Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
5.2 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: wkstore.h
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #ifndef __WORKSTORAGE_H__
  13. #define __WORKSTORAGE_H__
  14. #include "tlsjob.h"
  15. //--------------------------------------------------------------
  16. //
  17. // Work Object initialization function, each work object
  18. // must supply its own initialization routine to work
  19. // manager.
  20. //
  21. typedef CWorkObject* (WINAPI *PWorkObjectInitFunc)(
  22. CWorkManager* pWkMgr,
  23. PBYTE pbInitData,
  24. DWORD cbInitData
  25. );
  26. typedef void (WINAPI *PWorkObjectDeleteFunc)(CWorkObject* ptr);
  27. //------------------------------------------------------
  28. //
  29. // Work object initialization routine
  30. //
  31. typedef struct _WorkObjectInitFunc {
  32. DWORD m_WorkType;
  33. PWorkObjectInitFunc m_WorkInitFunc;
  34. } WORKOBJECTINITFUNC;
  35. typedef enum {
  36. WORKITEM_ADD=1,
  37. WORKITEM_BEGINPROCESSING,
  38. WORKITEM_RESCHEDULE,
  39. WORKITEM_DELETE
  40. } WORKITEM_OPERATION;
  41. class CPersistentWorkStorage : public CWorkStorage {
  42. private:
  43. DWORD m_dwStartupTime;
  44. CSafeCounter m_dwNumJobs;
  45. CSafeCounter m_dwJobsInProcesssing;
  46. //
  47. // m_hNextJobLock guard ...
  48. //
  49. CCriticalSection m_hTableLock;
  50. CSafeCounter m_dwNextJobTime;
  51. CWorkObject* m_pNextWorkObject;
  52. //PBYTE m_pbCurrentBookmark;
  53. //DWORD m_cbCurrentBookmark;
  54. //
  55. // Table must be updatable,
  56. //
  57. WorkItemTable* m_pWkItemTable;
  58. void
  59. UpdateNextJobTime(DWORD dwTime) { m_dwNextJobTime=dwTime; }
  60. DWORD
  61. StartupUpdateExistingJobTime();
  62. //
  63. //
  64. //
  65. BOOL
  66. ReturnJobToQueue(
  67. IN DWORD dwTime,
  68. IN CWorkObject* ptr
  69. );
  70. //
  71. //
  72. //
  73. BOOL
  74. DeleteErrorJob(
  75. IN CWorkObject* ptr
  76. );
  77. BOOL
  78. UpdateJobEntry(
  79. IN WorkItemTable* pTable,
  80. IN PBYTE pbBookmark,
  81. IN DWORD cbBoolmark,
  82. IN WORKITEMRECORD& wkItem
  83. );
  84. BOOL
  85. AddJobEntry(
  86. IN WorkItemTable* pTable,
  87. IN WORKITEMRECORD& wkItem
  88. );
  89. BOOL
  90. DeleteJobEntry(
  91. IN WorkItemTable* pTable,
  92. IN PBYTE pbBookmark,
  93. IN DWORD cbBookmark,
  94. IN WORKITEMRECORD& wkItem
  95. );
  96. BOOL
  97. UpdateWorkItemEntry(
  98. IN WorkItemTable* pTable,
  99. IN WORKITEM_OPERATION opCode,
  100. IN PBYTE pbBookmark,
  101. IN DWORD cbBookmark,
  102. IN DWORD dwRestartTime,
  103. IN DWORD dwTime,
  104. IN DWORD dwJobType,
  105. IN PBYTE pbJobData,
  106. IN DWORD cbJobData
  107. );
  108. BOOL
  109. IsValidWorkObject(
  110. CWorkObject* ptr
  111. );
  112. DWORD
  113. GetCurrentBookmarkEx(
  114. IN WorkItemTable* pTable,
  115. IN OUT PBYTE* ppbData,
  116. IN OUT PDWORD pcbData
  117. );
  118. DWORD
  119. GetCurrentBookmark(
  120. IN WorkItemTable* pTable,
  121. IN PBYTE ppbData,
  122. IN OUT PDWORD pcbData
  123. );
  124. DWORD
  125. SetCurrentBookmark(
  126. IN WorkItemTable* pTable,
  127. IN PBYTE pbData,
  128. IN DWORD cbData
  129. );
  130. BOOL
  131. RescheduleJob(
  132. CWorkObject* ptr
  133. );
  134. CWorkObject*
  135. GetCurrentJob(
  136. PDWORD pdwTime
  137. );
  138. DWORD
  139. FindNextJob();
  140. CWorkObject*
  141. InitializeWorkObject(
  142. DWORD dwWorkType,
  143. PBYTE pbData,
  144. DWORD cbData
  145. );
  146. BOOL
  147. DeleteWorkObject(
  148. CWorkObject* ptr
  149. );
  150. public:
  151. CPersistentWorkStorage(
  152. WorkItemTable* pUpdateWkItemTable = NULL
  153. );
  154. ~CPersistentWorkStorage();
  155. //--------------------------------------------------------
  156. BOOL
  157. AttachTable(
  158. IN WorkItemTable* pWkTable
  159. )
  160. /*++
  161. --*/
  162. {
  163. if(pWkTable != NULL)
  164. {
  165. m_pWkItemTable = pWkTable;
  166. }
  167. else
  168. {
  169. SetLastError(ERROR_INVALID_PARAMETER);
  170. }
  171. return pWkTable != NULL;
  172. }
  173. //--------------------------------------------------------
  174. BOOL
  175. IsGood();
  176. //--------------------------------------------------------
  177. virtual BOOL
  178. Startup(
  179. IN CWorkManager* pWkMgr
  180. );
  181. //--------------------------------------------------------
  182. virtual BOOL
  183. Shutdown();
  184. //--------------------------------------------------------
  185. virtual BOOL
  186. AddJob(
  187. DWORD dwJobTime,
  188. CWorkObject* ptr
  189. );
  190. //--------------------------------------------------------
  191. virtual DWORD
  192. GetNextJobTime();
  193. //--------------------------------------------------------
  194. virtual CWorkObject*
  195. GetNextJob(
  196. PDWORD pdwTime
  197. );
  198. //--------------------------------------------------------
  199. virtual BOOL
  200. EndProcessingJob(
  201. IN ENDPROCESSINGJOB_CODE opCode,
  202. IN DWORD dwOriginalTime,
  203. IN CWorkObject* ptr
  204. );
  205. //--------------------------------------------------------
  206. virtual DWORD
  207. GetNumJobs()
  208. {
  209. return m_dwNumJobs;
  210. }
  211. //-------------------------------------------------------
  212. virtual BOOL
  213. BeginProcessingJob(
  214. CWorkObject* pJob
  215. );
  216. };
  217. #endif