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.

371 lines
8.4 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1998
  5. //
  6. // File: workitem.h
  7. //
  8. // Contents: backupsource Table
  9. //
  10. // History:
  11. //
  12. //---------------------------------------------------------------------------
  13. #ifndef __WORKITEM_H__
  14. #define __WORKITEM_H__
  15. #include "tlsdb.h"
  16. //
  17. //
  18. #define WORKITEM_PROCESS_JOBTIME 0x00000001
  19. #define WORKITEM_PROCESS_JOBRESTARTTIME (WORKITEM_PROCESS_JOBTIME << 1)
  20. #define WORKITEM_PROCESS_JOBTYPE (WORKITEM_PROCESS_JOBTIME << 2)
  21. #define WORKITEM_PROCESS_DATA (WORKITEM_PROCESS_JOBTIME << 3)
  22. //
  23. // Table structure
  24. //
  25. #define WORKITEM_TABLE_NAME _TEXT("WorkStorage")
  26. #define WORKITEM_COLUMN_JOBTIME _TEXT("ScheduledTime")
  27. #define WORKITEM_COLUMN_JOBRESTARTTIME _TEXT("RestartTime")
  28. #define WORKITEM_COLUMN_JOBTYPE _TEXT("JobType")
  29. #define WORKITEM_COLUMN_DATA _TEXT("Data")
  30. #define WORKITEM_MAX_DATA_SIZE 16 * 1024 // max of 32 K
  31. typedef struct __WorkItemRecord : public TLSReplWorkItem
  32. {
  33. __WorkItemRecord&
  34. operator=(const __WorkItemRecord& v)
  35. {
  36. DWORD bSuccess;
  37. PBYTE pbOldData=pbData;
  38. DWORD cbOldData=cbData;
  39. if(this == &v)
  40. return *this;
  41. *(TLSReplWorkItem *)this = *(TLSReplWorkItem *)&v;
  42. pbData = pbOldData;
  43. cbData = cbOldData;
  44. bSuccess = TLSDBCopyBinaryData(
  45. v.pbData,
  46. v.cbData,
  47. &pbData,
  48. &cbData
  49. );
  50. JB_ASSERT(bSuccess == TRUE);
  51. return *this;
  52. }
  53. __WorkItemRecord&
  54. operator=(const TLSReplWorkItem& v)
  55. {
  56. DWORD bSuccess;
  57. PBYTE pbOldData=pbData;
  58. DWORD cbOldData=cbData;
  59. *(TLSReplWorkItem *)this = *(TLSReplWorkItem *)&v;
  60. pbData = pbOldData;
  61. cbData = cbOldData;
  62. bSuccess = TLSDBCopyBinaryData(
  63. v.pbData,
  64. v.cbData,
  65. &pbData,
  66. &cbData
  67. );
  68. JB_ASSERT(bSuccess == TRUE);
  69. return *this;
  70. }
  71. __WorkItemRecord()
  72. {
  73. pbData = NULL;
  74. cbData = 0;
  75. }
  76. ~__WorkItemRecord()
  77. {
  78. if(pbData)
  79. {
  80. FreeMemory(pbData);
  81. }
  82. }
  83. } WORKITEMRECORD;
  84. typedef WORKITEMRECORD* LPWORKITEMRECORD;
  85. typedef WORKITEMRECORD* PWORKITEMRECORD;
  86. /////////////////////////////////////////////////////////
  87. //
  88. // Index structure
  89. //
  90. /////////////////////////////////////////////////////////
  91. //
  92. //
  93. #define WORKITEM_INDEX_JOBTIME_INDEXNAME \
  94. WORKITEM_TABLE_NAME SEPERATOR WORKITEM_COLUMN_JOBTIME SEPERATOR INDEXNAME
  95. //
  96. // Primary Index on KeyPack ID "+KeyPackId\0"
  97. //
  98. #define WORKITEM_INDEX_JOBTIME_INDEXKEY \
  99. INDEX_SORT_ASCENDING WORKITEM_COLUMN_JOBTIME INDEX_END_COLNAME
  100. typedef struct __WorkItemIdxOnJobTime : public JBKeyBase {
  101. DWORD dwScheduledTime;
  102. //--------------------------------------------------------
  103. __WorkItemIdxOnJobTime(
  104. const WORKITEMRECORD& v
  105. ) :
  106. JBKeyBase()
  107. /*++
  108. ++*/
  109. {
  110. *this = v;
  111. }
  112. //--------------------------------------------------------
  113. __WorkItemIdxOnJobTime(
  114. const WORKITEMRECORD* v=NULL
  115. ) :
  116. JBKeyBase()
  117. /*++
  118. ++*/
  119. {
  120. if(v)
  121. {
  122. *this = *v;
  123. }
  124. }
  125. //--------------------------------------------------------
  126. __WorkItemIdxOnJobTime&
  127. operator=(const WORKITEMRECORD& v)
  128. {
  129. dwScheduledTime = v.dwScheduledTime;
  130. SetEmptyValue(FALSE);
  131. return *this;
  132. }
  133. //--------------------------------------------------------
  134. LPCTSTR
  135. GetIndexName()
  136. {
  137. static LPTSTR pszIndexName=WORKITEM_INDEX_JOBTIME_INDEXNAME;
  138. return pszIndexName;
  139. }
  140. //--------------------------------------------------------
  141. LPCTSTR
  142. GetIndexKey()
  143. {
  144. static LPTSTR pszIndexKey=WORKITEM_INDEX_JOBTIME_INDEXKEY;
  145. return pszIndexKey;
  146. }
  147. //--------------------------------------------------------
  148. DWORD
  149. GetNumKeyComponents()
  150. {
  151. return 1;
  152. }
  153. //--------------------------------------------------------
  154. BOOL
  155. GetSearchKey(
  156. DWORD dwComponentIndex,
  157. PVOID* pbData,
  158. unsigned long* cbData,
  159. JET_GRBIT* grbit,
  160. DWORD dwSearchParm
  161. )
  162. /*++
  163. ++*/
  164. {
  165. if(dwComponentIndex >= GetNumKeyComponents())
  166. {
  167. JB_ASSERT(FALSE);
  168. return FALSE;
  169. }
  170. *pbData = &dwScheduledTime;
  171. *cbData = sizeof(dwScheduledTime);
  172. *grbit = JET_bitNewKey;
  173. return TRUE;
  174. }
  175. } TLSWorkItemIdxModifyTime;
  176. // -----------------------------------------------------------
  177. //
  178. // LicensedPackStatus Table
  179. //
  180. // -----------------------------------------------------------
  181. class WorkItemTable : public TLSTable<WORKITEMRECORD> {
  182. private:
  183. BOOL
  184. ProcessSingleColumn(
  185. BOOL bFetch,
  186. TLSColumnBase& column,
  187. DWORD offset,
  188. PVOID pbData,
  189. DWORD cbData,
  190. PDWORD pcbDataReturn,
  191. LPCTSTR szColumnName
  192. );
  193. BOOL
  194. ProcessRecord(
  195. WORKITEMRECORD* v,
  196. BOOL bFetch, // TRUE - fetch, FALSE insert
  197. DWORD dwParam,
  198. BOOL bUpdate
  199. );
  200. public:
  201. TLSColumnDword dwScheduledTime;
  202. TLSColumnDword dwRestartTime;
  203. TLSColumnDword dwJobType;
  204. TLSColumnBinary pbData;
  205. //-----------------------------------------------------
  206. virtual LPCTSTR
  207. GetTableName()
  208. {
  209. static LPTSTR pszTableName=WORKITEM_TABLE_NAME;
  210. return pszTableName;
  211. }
  212. //-----------------------------------------------------
  213. WorkItemTable(
  214. JBDatabase& database
  215. ) :
  216. TLSTable<WORKITEMRECORD>(database)
  217. /*
  218. */
  219. {
  220. }
  221. //-----------------------------------------------------
  222. virtual BOOL
  223. ResolveToTableColumn();
  224. //-----------------------------------------------------
  225. virtual BOOL
  226. FetchRecord(
  227. WORKITEMRECORD& v,
  228. DWORD dwParam=PROCESS_ALL_COLUMNS
  229. )
  230. /*
  231. */
  232. {
  233. if(IsValid() == FALSE)
  234. {
  235. DebugOutput(
  236. _TEXT("Table %s is not valid...\n"),
  237. GetTableName()
  238. );
  239. JB_ASSERT(FALSE);
  240. SetLastJetError(JET_errInvalidParameter);
  241. return FALSE;
  242. }
  243. //CCriticalSectionLocker Lock(GetTableLock());
  244. return ProcessRecord(&v, TRUE, dwParam, FALSE);
  245. }
  246. //-----------------------------------------------------
  247. virtual BOOL
  248. InsertRecord(
  249. WORKITEMRECORD& v,
  250. DWORD dwParam=PROCESS_ALL_COLUMNS
  251. )
  252. /*
  253. */
  254. {
  255. if(IsValid() == FALSE)
  256. {
  257. DebugOutput(
  258. _TEXT("Table %s is not valid...\n"),
  259. GetTableName()
  260. );
  261. JB_ASSERT(FALSE);
  262. SetLastJetError(JET_errInvalidParameter);
  263. return FALSE;
  264. }
  265. //CCriticalSectionLocker Lock(GetTableLock());
  266. return ProcessRecord(&v, FALSE, dwParam, FALSE);
  267. }
  268. //-----------------------------------------------------
  269. virtual BOOL
  270. UpdateRecord(
  271. WORKITEMRECORD& v,
  272. DWORD dwParam=PROCESS_ALL_COLUMNS
  273. )
  274. /*
  275. */
  276. {
  277. if(IsValid() == FALSE)
  278. {
  279. DebugOutput(
  280. _TEXT("Table %s is not valid...\n"),
  281. GetTableName()
  282. );
  283. JB_ASSERT(FALSE);
  284. SetLastJetError(JET_errInvalidParameter);
  285. return FALSE;
  286. }
  287. //CCriticalSectionLocker Lock(GetTableLock());
  288. return ProcessRecord(&v, FALSE, dwParam, TRUE);
  289. }
  290. //-------------------------------------------------------
  291. virtual BOOL
  292. Initialize()
  293. {
  294. return TRUE;
  295. }
  296. //-------------------------------------------------------
  297. virtual JBKeyBase*
  298. EnumerationIndex(
  299. IN BOOL bMatchAll,
  300. IN DWORD dwParam,
  301. IN WORKITEMRECORD* kp,
  302. IN OUT BOOL* bCompareKey
  303. );
  304. virtual BOOL
  305. EqualValue(
  306. WORKITEMRECORD& s1,
  307. WORKITEMRECORD& s2,
  308. BOOL bMatchAll,
  309. DWORD dwParam
  310. );
  311. };
  312. #endif