⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wfl.cpp

📁 语法分析器 完成从c/c++向C++转变
💻 CPP
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////
//
// Module Name:   wfl.cpp
// 
// Description:   Demonstration of workflow management system.
//                Built on top of the link-list and binary tree algorithms.
//
// Written by:  John Tal
//
//
// Modification History:
//
// Date          Programmer      Mod#     Modification
// ---------------------------------------------------------------------------
// 03-JUL-1991   J. Tal          V1.0-000 New
//
//
//

#include <iostream.h>
#include <string.h>


#include "cmemlib.h"

#include "wfl.h"



//
//  CompareState       used for SHORT to node comparison of short ids
//                     by search routines
//

SHORT CompareState(PVOID pvData1,PVOID pvData2)
{

   PSHORT psState1;
   PSHORT psState2;
   WORK_ITEM_P  pstWorkItem;     
   LLIST_CP  pclList;


   psState1 = (PSHORT) pvData1;    // get direct state in short

   pclList = (LLIST_CP) pvData2;   // ptr to list class

   pclList -> FindFirst((PPVOID) &pstWorkItem);  // get first object/item in list class

   psState2 = &(pstWorkItem -> sState);  // get state

   if(*psState1 == *psState2)
      return(0);
   else if(*psState1 > *psState2)
      return(-1);
   else
      return(1);

}

//
//   May want to make function more sophisticated in future, now just
//   takes first one
//


SHORT PROFILE_C::Get(PROFILE_PP ppclProfile)
{
   C_DEF_MODULE("PROFILE_C::Get")


   C_STATUS = clProfiles.FindFirst((PPVOID) ppclProfile);

   C_RETURN
}
                              


//
//  CompareNodeState   used for node to node comparison of short ids
//                     by delete routines
//

SHORT CompareNodeState(PVOID pvData1,PVOID pvData2)
{
   PSHORT psState1;
   PSHORT psState2;
  
   LLIST_CP  pclList1;
   LLIST_CP  pclList2;

   WORK_ITEM_P pstWorkItem1;
   WORK_ITEM_P pstWorkItem2;


   pclList1 = (LLIST_CP) pvData1;     // class is at this ptr

   pclList1 -> FindFirst((PPVOID) &pstWorkItem1);  // get first object/item in list class
   
   psState1 = &(pstWorkItem1 -> sState);   // ptr to state



   pclList2 = (LLIST_CP) pvData2;     // class of link list at this ptr
   
   pclList2 -> FindFirst((PPVOID) &pstWorkItem2);  // get first object/item in list class
   
   psState1 = &(pstWorkItem2 -> sState);  // ptr to state



   if(*psState1 == *psState2)
      return(0);
   else if(*psState1 > *psState2)
      return(-1);
   else
      return(1);

}

//
//  CompareIdNode
//


SHORT CompareIdNode(PVOID pvData1,PVOID pvData2)
{
   PCHAR  pcId1;
   PCHAR  pcId2;

   pcId1 = (PCHAR) pvData1;
   pcId2 = (PCHAR) pvData2;

   return(strcmp(pcId1,pcId2));
}


//
//  WrkProAdd
//
//  Adds a profile for a process to the process' profile list
//

SHORT PROFILE_C::Add(PROFILE_P pstAProfile)
{
   C_DEF_MODULE("WrkProAdd")

   PROFILE_P  pstProfile;
   PVOID      pvData;


   pstProfile = new PROFILE_T;

   memcpy(pstProfile,pstAProfile,sizeof(PROFILE_T));


   C_STATUS = clProfiles.FindLast(&pvData);

   C_STATUS = clProfiles.AddAfterCur((PVOID) pstProfile);

   C_RETURN
}


//
//  Add another job.
//  Each workflow_T is in a linked-list off of a single binary tree node
//

SHORT
WORK_FLOW_C::Add(PCHAR szId, SHORT sState, PVOID pvData)
{
   C_DEF_MODULE("WORK_FLOW_C::Add")

   PVOID pvData1;
   PVOID pvData2;
   LLIST_CP  pclLlist;
   WORK_ITEM_P pstWorkItem;

   pstWorkItem = new WORK_ITEM_T;


   //
   //  Check if in Id Tree, if so, is error
   //

   C_STATUS = clIdTree.SetCompareFunc(CompareIdNode);

   C_STATUS = clIdTree.Find((PVOID) szId,&pvData1);   // fix 16-Feb-92 was pvData

   if(pvData1 != NULL)    // fix 16-Feb-92 was pvData
   {
      C_LEAVE(WRK_DUPLICATE_ID)
   }


   //
   //  Add to Id Tree
   //

   C_STATUS = clIdTree.Insert((PVOID) szId);

   //
   // Populate new item
   //

   pstWorkItem -> sState = sState;
   strcpy(pstWorkItem -> szId, szId);
   pstWorkItem -> fLocked = C_FALSE;
   pstWorkItem -> pvData = pvData;


   C_STATUS = clStateTree.SetCompareFunc(CompareNodeState);

   C_STATUS = clStateTree.Find((PVOID) &sState,(PPVOID) &pvData1);

   if(pvData1 == NULL)
   {

#if DEBUG
   cout << "WrkJobAdd:   Adding entry for state " << pstWorkItem -> sState << "\n";
#endif

      //
      //  Must add entry for this state
      //

      pclLlist = new (LLIST_C);

      //
      //  Put info on Work Item into link list
      //

      pclLlist -> Insert((PVOID) pstWorkItem);
              
      //
      //  Put info on Link List into Tree
      //

      C_STATUS = clStateTree.Insert((PVOID) pclLlist);

   }
   else
   {
#if DEBUG
   cout << "WrkJobAdd:   Appending entry for state " << pstWorkItem -> sState << "\n";
#endif

      //
      //  Find current llist 
      //

      pclLlist = (LLIST_CP) pvData1;

      //
      //  Find last one of current list
      //
 
      C_STATUS = pclLlist -> FindLast((PPVOID) pvData2);

      //
      //  Add new one after current last one
      //  Maintains FIFO ordering
      //

      C_STATUS = pclLlist -> AddAfterCur((PVOID) pstWorkItem); 
   }

C_MODULE_EXIT:

   C_RETURN
}




//
//  WrkJobSelect, select a job to work on
//  Automatically locks a job when selected
//

SHORT WORK_FLOW_C::Select(PROFILE_CP pclProfile, PCHAR * ppcId, PVOID * ppvData)
{
   C_DEF_MODULE("WORK_FLOW::Select")

   WORK_ITEM_P pstWorkItem;
   PROFILE_P   pstProfile;
   BOOL        fFoundJob = C_FALSE;
   LLIST_CP    pclStateList;

   *ppvData = NULL;


   
   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_SEL_STATE]),
                                   (PPVOID) &pclStateList);

       if(pclStateList == NULL)
	  break;

       if(pclStateList != NULL && !fFoundJob)
       {
          //
          //  Found 1 or more jobs at this state
          //
          //  Check each member in linked list till no more or got one
          //

          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;

		strcpy(pstWorkItem -> szKey, pstProfile -> szKey);

		*ppcId = pstWorkItem -> szId;

		*ppvData = pstWorkItem -> pvData;

                fFoundJob = C_TRUE;

             }

             //
             //  If still looking, check next job
             //

	     if(!fFoundJob)
	     {
		C_STATUS = pclStateList -> GetNext((PPVOID) &pstWorkItem);
		if(C_STATUS)
		   break;
	     } 
	  }

       } 

       //  
       //  If still looking, check next profile
       //

       //if((pclStateList == NULL) && !fFoundJob)
       // C_STATUS = pclProfile -> Get(&pstProfile);
   }

   if(!fFoundJob)
      C_SET_STATUS(WRK_NO_JOB);

   C_RETURN

}


//
//  WrkJobTrans
//
//  Set the job to the appropriate transition state
//  and unlocks job if told to
//

SHORT WORK_FLOW_C::SetTrans(PCHAR szId, PROFILE_CP pclProfile, SHORT sTrnStateNdx)
{
   C_DEF_MODULE("WORK_FLOW_C::SetTrans")

   SHORT sSaveState;
   WORK_ITEM_P  pstWorkItem;
   PVOID pvData;
   PROFILE_P    pstProfile;
   BOOL   fFoundJob;
   LLIST_CP   pclStateList;

#if DEBUG
   cout << "WrkJobTrans: Setting " << szId << " to state ndx " << sTrnStateNdx << "\n";
#endif

#ifdef WHY

   //
   //  Get WORK_ITEM based on szId
   //

   C_STATUS = clIdTree.SetCompareFunc(CompareIdNode);

   C_STATUS = clIdTree.Find((PVOID) szId, (PPVOID)&pstWorkItem);


   //
   //  Must also unlink from link list in workflow tree
   //  and add to new link list
   //

#endif



   C_STATUS = pclProfile -> Get(&pstProfile);

   sSaveState = pstProfile -> sTrnState[sTrnStateNdx];



   C_STATUS = clStateTree.SetCompareFunc(CompareState);

   while(!C_STATUS && (pstProfile != NULL) && !fFoundJob)
   {
       C_STATUS = clStateTree.Find((PVOID)
                                    &(pstProfile -> sTrnState[WRK_SEL_STATE]),
                                   (PPVOID) &pclStateList);

       if(pclStateList != NULL && !fFoundJob)
       {
          //
          //  Found 1 or more jobs at this state
          //
          //  Check each member in linked list till no more or got one
          //

          C_STATUS = pclStateList -> FindFirst((PPVOID) &pstWorkItem);

          while(pstWorkItem != NULL && !fFoundJob)
          {
 
             //
             //  All same states, check if match on owner
             //

	     if(strcmp(pstWorkItem -> szKey,pstProfile -> szKey) == 0)
             {

                 //
                 //  Found it, delete from old list, add to new/current one
                 //

                 fFoundJob = C_TRUE;

		 C_STATUS = pclStateList -> DeleteCur();

		 C_STATUS = pclStateList -> FindFirst((PPVOID) & pvData);

                 if(pvData == NULL)
                 {

                    //
                    //  Delete tree entry because no more at this state
                    //

                    C_STATUS = clStateTree.Delete((PVOID) &sSaveState);
#if DEBUG
		    cout << "WORK_FLOW_C::Trans: Deleting state " << sSaveState << "\n";
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -