home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / text_cla / wfl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-12  |  6.3 KB  |  221 lines

  1. /***********************************************************************
  2. **+
  3. **  Module Name:  workflow.h
  4. **
  5. **  Description:  Workflow specific defines
  6. **
  7. **  Include Modules Referenced:  None.
  8. **
  9. **  Written by:  John Tal
  10. **
  11. **
  12. **  Modification history:
  13. **
  14. **  Date         Engineer     Mod #          Modification Description
  15. **
  16. **  07-Jul-1991  Tal          v 1.0-001      Initial release
  17. **-
  18. ***********************************************************************/
  19.  
  20. #ifdef WFL_H
  21. #else
  22. #define WFL_H
  23.  
  24. #define WFL_KEY_LEN 16             /* standard key length */
  25. #define WFL_MAX_TRN_STATES 10      /* limit of transition states per profile */
  26.  
  27. #define WFL_NO_JOB  -1             /* no jobs for a process */
  28.  
  29.  
  30. /*
  31. **   A workflow management system is a way to coordinate several processes
  32. **   which are all processing the same set of data.   The environment
  33. **   in which the concept was developed at I2MS was for distributed Unix
  34. **   processing.   Concept was defined by Mike Peregoy and implemented by
  35. **   the I2MS Blue Shield Imaging team lead by John Tal (Spring 1991).
  36. **
  37. **   Basically, a workflow management system (WMS) is a way to 'send' jobs
  38. **   around a network through various states or queues.   A particular
  39. **   process is looking for jobs with a particular state.  Jobs it finds
  40. **   with a matching state are taken and locked for processing.  When that 
  41. **   process is finished processing a job, it resets the state to another 
  42. **   value.  This value is likely a selection value for another process.
  43. **
  44. **   Network
  45. **
  46. **     Process 1  Loads jobs into database
  47. **                Sets Jobs to state 200
  48. **
  49. **     Process 2  Looking for Jobs with state 200
  50. **                Sets completed Jobs to state 300
  51. **
  52. **     Process 3  Looking for Jobs with state 300
  53. **                Sets completed Jobs to state 400
  54. **
  55. **     Process 4  Looking for Jobs with state 300
  56. **                Deletes jobs from database
  57. **
  58. **
  59. **
  60. **    A major advantage to a WMS is the ability for the system manager to
  61. **    'customize' the operation of the system.   (Process 3 could execute
  62. **    before Process 2.)
  63. **
  64. **    A review of WMS for the right-side of the brain.....
  65. **
  66. **          All of these processes are plugged into this network
  67. **          and grab any jobs they can.  After processing, they
  68. **          set the job state so that another process can have some
  69. **          fun.
  70. **
  71. **    The program below is an example of how to use the C algorithms in
  72. **    constructing a WMS based on an in-memory database.
  73. **
  74. **    A WMS would typically be created in a library layer above the
  75. **    disk-based data-base.
  76. **
  77. **    FURTHER DEVELOPMENT
  78. **
  79. **    An evolution to the EMS (especially meaningful in a multi-tasking
  80. **    environment) would be to have each process block until a job is
  81. **    available for processing.   This would eliminate the constant
  82. **    polling to the database.   
  83. **
  84. **    To implement a priority-based scheme, you could add a priority to
  85. **    each job and change the link-list off each state node in the 
  86. **    binary tree to a heap.   The only limitation is that because most
  87. **    heaps are implemented in arrays, you would have to allocate for a
  88. **    maximum size if only one job existed at a given state.
  89. **
  90. */
  91.  
  92.  
  93.  
  94. /*
  95. **  The following item is at each node of the workflow binary tree
  96. **
  97. **  The workflow binary tree has one node for each state.   All jobs
  98. **  for the same state are connected in a link-list off of the binary
  99. **  tree node for that state.
  100. */
  101.  
  102. struct WORK_TREE_S
  103. {
  104.     SHORT  sState;       /* the state */
  105.     LLIST_P  pstList;    /* ptr to the list of jobs at that state */
  106. };
  107.  
  108. typedef struct WORK_TREE_S WORK_TREE_T;
  109. typedef WORK_TREE_T * WORK_TNODE_P;
  110.  
  111.  
  112. /*
  113. **  The workflow data (WORK_ITEM_S) is stored in a linked-list hung off
  114. **  of a binary tree.
  115. **
  116. **  The WORK_ITEM is data about each job.
  117. */
  118.  
  119. struct WORK_ITEM_S
  120. {
  121.     SHORT  sState;   /* the state, or queue job is currently at */
  122.     CHAR   szId[WFL_KEY_LEN + 1];  /* unique identifier for job */
  123.     CHAR   szKey[WFL_KEY_LEN + 1];  /* current or last owners Id */
  124.     BOOL   fLocked;  /* is currently in use */
  125.     PVOID  pvData;   /* common data type all processes/owners are using */
  126. };
  127.  
  128. typedef struct WORK_ITEM_S WORK_ITEM_T;
  129. typedef WORK_ITEM_T * WORK_ITEM_P;
  130. typedef WORK_ITEM_T ** WORK_ITEM_PP;
  131.  
  132.  
  133. /*
  134. **  This is the workflow profile data
  135. **
  136. **  It is contained in a linked list which is belongs to a process.
  137. **
  138. **  This is a profile to describe how each 'process' is to access the data.
  139. **  A process initializes for this data once and then does queries against
  140. **  the master set of WORK_ITEM data to get a job for processing.
  141. **
  142. **  The profile data contains the selection, activation, and transition
  143. **  state values.  A process may have multiple WORK_FLOW entries as
  144. **  part of its profile.
  145. **
  146. **  The profile data would normally be stored in a file on disk.
  147. */
  148.  
  149.  
  150. /*
  151. **  The following are the array [] offsets for each type of state in the
  152. **  WORK_FLOW . sTrnState[]
  153. */
  154.  
  155. #define WFL_SEL_STATE 0
  156. #define WFL_ACT_STATE 1
  157. #define WFL_TRN_STATE 2
  158.  
  159. /* 
  160. **  each process would typically have it's own meaning for the 
  161. **  transition values.  Here are some generic ones
  162. **/
  163.  
  164. #define WFL_TRN_OK    0
  165. #define WFL_TRN_ERR_1 1    
  166. #define WFL_TRN_ERR_2 2
  167.  
  168. struct WORK_FLOW_S
  169. {
  170.     CHAR   szKey[WFL_KEY_LEN + 1];   /* Key = ID of process */
  171.     SHORT  sTrnState[10];            /* States themselves */
  172.     SHORT  sTrnStates;               /* How many states are there */
  173. };
  174.  
  175. typedef struct WORK_FLOW_S  WORK_FLOW_T;
  176. typedef WORK_FLOW_T * WORK_FLOW_P;
  177. typedef WORK_FLOW_T ** WORK_FLOW_PP;
  178.  
  179.  
  180.  
  181. #ifdef C_ANSI
  182.  
  183. SHORT APIENTRY
  184. WflProAdd(LLIST_PP, WORK_FLOW_P);
  185.  
  186. SHORT APIENTRY
  187. WflJobAdd(TNODE_PP,WORK_ITEM_P);
  188.  
  189. SHORT APIENTRY
  190. WflJobSelect(TNODE_P,
  191.              LLIST_P,
  192.              WORK_FLOW_PP,
  193.              WORK_ITEM_PP,
  194.              PVOID *);
  195.  
  196. SHORT APIENTRY
  197. WflJobTrans(TNODE_PP,
  198.             WORK_ITEM_P,
  199.             WORK_FLOW_P,
  200.             SHORT,
  201.             BOOL);
  202.  
  203. SHORT CompareState(PVOID,PVOID);
  204.  
  205. SHORT CompareNodeState(PVOID,PVOID);
  206.  
  207. #else
  208.  
  209. SHORT APIENTRY WflProAdd();
  210. SHORT APIENTRY WflJobAdd();
  211. SHORT APIENTRY WflJobSelect();
  212. SHORT APIENTRY WflJobTrans();
  213. SHORT CompareState();
  214. SHORT CompareNodeState();
  215.  
  216. #endif
  217.  
  218.  
  219.  
  220. #endif
  221.