📄 wfl.cpp
字号:
}
else
{
#if DEBUG
cout << "WrkJobTrans: Resetting node for state " << sSaveState << "\n";
#endif
}
//
// Add to new/current list
//
C_STATUS = pclProfile -> Get(&pstProfile);
pstWorkItem -> sState = pstProfile -> sTrnState[sTrnStateNdx];
C_STATUS = Add(szId,pstWorkItem -> sState,(PVOID) pstWorkItem);
}
C_STATUS = pclStateList -> GetNext((PPVOID) &pstWorkItem);
}
}
}
C_RETURN
}
//
//
//
SHORT WORK_FLOW_C::UnLock(PCHAR pcId, PROFILE_CP pclProfile)
{
C_DEF_MODULE("WORK_FLOW_C::UnLock")
PVOID pvData;
BOOL fFoundJob = C_FALSE;
SHORT sCnt;
WORK_ITEM_P pstWorkItem;
PROFILE_P pstProfile;
LLIST_CP pclStateList;
#if 0
//
// Look in Id Tree
//
C_STATUS = clIdTree.SetCompareFunc(CompareIdNode);
C_STATUS = clIdTree.Find((PVOID) pcId,&pvData);
if(pvData == NULL)
{
C_LEAVE(WRK_NO_JOB)
}
pclProfile -> Get(&pst
pstWorkItem = (WORK_ITEM_P) pvData;
//
// See if profiles have access to pcId
//
// This is done by comparing pcId current state to selection or
// activation state of profile
//
pstProfile = NULL;
C_STATUS = pclProfile -> Get(&pstProfile);
while(!C_STATUS && (pstProfile != NULL) && !fFoundJob)
{
for(sCnt = 0; sCnt < pstProfile -> sTrnStates; sCnt++)
if(pstWorkItem -> sState == pstProfile -> sTrnState[sCnt])
{
fTrnOk = C_TRUE;
break;
}
if(
(fTrnOk)
&&
(pstWorkItem -> fLocked)
&&
(strcmp(pstWorkItem -> szKey,pstProfile -> szKey) == 0)
)
{
pstWorkItem -> fLocked = C_FALSE;
fFoundJob = C_TRUE;
}
}
C_MODULE_EXIT:
C_RETURN
#endif
C_STATUS = pclProfile -> Get(&pstProfile);
//
// Check all jobs based on jobs which this process can process
//
C_STATUS = clStateTree.SetCompareFunc(CompareState);
while(!C_STATUS && (pstProfile != NULL) && !fFoundJob)
{
C_STATUS = clStateTree.Find((PVOID)
&(pstProfile -> sTrnState[WRK_ACT_STATE]),
(PPVOID) &pclStateList);
if(pclStateList == NULL)
break;
if(pclStateList != NULL && !fFoundJob)
{
//
// Found 1 or more jobs at this state
//
C_STATUS = pclStateList -> FindFirst((PPVOID) &pstWorkItem);
while(pstWorkItem != NULL && !fFoundJob)
{
if(pstWorkItem -> fLocked)
{
//
// Mark job as locked, we are new owners
//
pstWorkItem -> fLocked = C_TRUE;
fFoundJob = C_TRUE;
}
//
// If still looking, check next job
//
if(!fFoundJob)
{
C_STATUS = pclStateList -> GetNext((PPVOID) &pstWorkItem);
if(C_STATUS)
break;
}
}
}
}
C_RETURN
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
#define TEST 1
#define DEBUG 1
#ifdef TEST
//
// Beginning of test program
//
struct JOB_S // a dummy 'job' to process //
{
SHORT sData1;
SHORT sData2;
};
typedef struct JOB_S JOB_T;
typedef JOB_T * JOB_P;
JOB_T stJob1; // some jobs //
JOB_T stJob2;
JOB_T stJob3;
JOB_T stJob4;
int Process1(); // processes to process the jobs //
int Process2();
int Process3();
int (*Procs[3])() = { Process1, Process2, Process3 }; // array of processes //
WORK_FLOW_C clWorkFlow;
PROFILE_C clProfile1;
PROFILE_C clProfile2;
PROFILE_C clProfile3;
int DoProcs();
main()
{
C_DEF_MODULE("main")
SHORT s1,s2,s3,s4,s5,s6;
PROFILE_T stProfile;
//
// Initialize 'Job' data
//
stJob1.sData1 = 0; // 'bad data' , will get sent 1, to 2, to 1, to 3 //
stJob1.sData2 = 0;
stJob2.sData1 = 1;
stJob2.sData2 = 1;
stJob3.sData1 = 1;
stJob3.sData2 = 1;
stJob4.sData1 = 1;
stJob4.sData2 = 1;
//
// Initialize data for each 'process'
//
strcpy(stProfile.szKey,"PRE_PROC");
stProfile.sTrnStates = 5;
stProfile.sTrnState[0] = 100; // Selection //
stProfile.sTrnState[1] = 101; // Activation //
stProfile.sTrnState[2] = 300; // successful completion //
stProfile.sTrnState[3] = 200; // error 1 //
stProfile.sTrnState[4] = 250; // error 2 //
clProfile1.Add(&stProfile);
strcpy(stProfile.szKey,"ERR_PROC");
stProfile.sTrnStates = 5;
stProfile.sTrnState[0] = 200; // Selection //
stProfile.sTrnState[1] = 201; // Activation //
stProfile.sTrnState[2] = 100; // successful completion //
stProfile.sTrnState[3] = 999; // error 1 //
stProfile.sTrnState[4] = 998; // error 2 //
clProfile2.Add(&stProfile);
strcpy(stProfile.szKey,"END_PROC");
stProfile.sTrnStates = 5;
stProfile.sTrnState[0] = 300; // Selection //
stProfile.sTrnState[1] = 301; // Activation //
stProfile.sTrnState[2] = 700; // successful completion //
stProfile.sTrnState[3] = 970; // error 1 //
stProfile.sTrnState[4] = 980; // error 2 //
clProfile3.Add(&stProfile);
//
// Initialize each job
//
clWorkFlow.Add("Job1",100,(PVOID) &stJob1);
clWorkFlow.Add("Job2",200,(PVOID) &stJob2);
clWorkFlow.Add("Job3",300,(PVOID) &stJob3);
clWorkFlow.Add("Job4",400,(PVOID) &stJob4);
C_SET_STATUS(0);
s1 = 1; // remember results of last 5 process executions //
s2 = 0;
s3 = 0;
s4 = 0;
s5 = 0;
s6 = 0;
do
{
s6 = s5;
s5 = s4;
s4 = s3;
s3 = s2;
s2 = s1;
C_STATUS = DoProcs(); // simple 'multi-tasker' //
if(!C_STATUS)
s1 = 1;
else
s1 = 0;
} while( (s1+s2+s3+s4+s5+s6) > 0);
}
//
// 'Multi-task' (round-robin) the different processes
//
int DoProcs()
{
C_DEF_MODULE("DoProcs")
static SHORT sLastProc = 0;
C_STATUS = Procs[sLastProc]();
sLastProc++;
if(sLastProc > 2)
sLastProc = 0;
C_RETURN
}
//
// Process 1
//
int Process1()
{
C_DEF_MODULE("Process 1")
PCHAR pcId;
JOB_P pstJob;
cout << "Process 1 - Executing\n";
C_STATUS = clWorkFlow.Select(&clProfile1,&pcId,(PPVOID) &pstJob);
if(pstJob == NULL)
{
cout << "Process 1 - Found nothing to work on\n";
C_STATUS = -1;
}
else
{
cout << "Process 1 - Working on job " << pcId << "\n";
clWorkFlow.SetTrans(pcId,&clProfile1,WRK_ACT_STATE);
if(pstJob -> sData1 == 0)
{
cout << "Process 1 - Incorrect Data on job " << pcId << "\n";
clWorkFlow.UnLock(pcId,&clProfile1);
clWorkFlow.SetTrans(pcId,&clProfile1,WRK_TRN_STATE+WRK_TRN_ERR_1);
}
else
{
cout << "Process 1 - Completing job " << pcId << "\n";
clWorkFlow.UnLock(pcId,&clProfile1);
clWorkFlow.SetTrans(pcId,&clProfile1,WRK_TRN_STATE+WRK_TRN_OK);
}
}
C_RETURN
}
//
// Process 2, is sent 'bad' data by process 1 for correction if possible
//
int Process2()
{
C_DEF_MODULE("Process 2")
JOB_P pstJob;
PCHAR pcId;
cout << "\nProcess 2 - Executing\n";
C_STATUS = clWorkFlow.Select(&clProfile2,&pcId,(PPVOID) &pstJob);
if(pstJob == NULL)
{
cout << "Process 2 - Found nothing to work on\n";
C_STATUS = -1;
}
else
{
cout << "Process 2 - Working on job " << pcId << "\n";
clWorkFlow.SetTrans(pcId,&clProfile2,WRK_ACT_STATE);
pstJob -> sData1 = 1; // Correct problem which sent it here //
cout << "Process 2 - Completing job " << pcId << "\n";
clWorkFlow.SetTrans(pcId,&clProfile2,WRK_TRN_STATE+WRK_TRN_OK);
}
C_RETURN
}
int Process3()
{
C_DEF_MODULE("Process 3")
JOB_P pstJob;
PCHAR pcId;
cout << "\nProcess 3 - Executing\n";
C_STATUS = clWorkFlow.Select(&clProfile3,&pcId,(PPVOID) &pstJob);
if(pstJob == NULL)
{
cout << "Process 3 - Found nothing to work on\n";
C_STATUS = -1;
}
else
{
cout << "Process 3 - Working on job " << pcId << "\n";
clWorkFlow.SetTrans(pcId,&clProfile3,WRK_ACT_STATE);
clWorkFlow.UnLock(pcId,&clProfile3);
clWorkFlow.SetTrans(pcId,&clProfile3,WRK_TRN_STATE+WRK_TRN_OK);
}
C_RETURN
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -