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.

240 lines
5.1 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: wkspace.h
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #ifndef __TLSDBWORKSPACE_H__
  13. #define __TLSDBWORKSPACE_H__
  14. #include "SrvDef.h"
  15. //
  16. // from TLSDb
  17. //
  18. #include "JBDef.h"
  19. #include "JetBlue.h"
  20. #include "TLSDb.h"
  21. #include "backup.h"
  22. #include "KPDesc.h"
  23. #include "Licensed.h"
  24. #include "licpack.h"
  25. #include "version.h"
  26. #include "workitem.h"
  27. struct __TLSDbWorkSpace;
  28. //
  29. // Temporary define workspace to be 32
  30. //
  31. #define MAX_WORKSPACE 32
  32. typedef CHandlePool<
  33. struct __TlsDbWorkSpace *,
  34. MAX_WORKSPACE
  35. > TLSDbWorkSpacePool;
  36. //---------------------------------------------------------------------------
  37. typedef struct __TlsDbWorkSpace {
  38. // one instance for all session
  39. static JBInstance g_JbInstance;
  40. //------------------------------------------------
  41. //
  42. // JetBlue transaction is session based and no
  43. // two thread can use same session
  44. //
  45. JBSession m_JetSession;
  46. JBDatabase m_JetDatabase;
  47. //
  48. // These table should be kept open
  49. //
  50. LicPackTable m_LicPackTable;
  51. LicensedTable m_LicensedTable;
  52. //
  53. // LicPackDesc table is used by enumeration and
  54. // adding license pack open as necessary.
  55. //
  56. LicPackDescTable m_LicPackDescTable;
  57. //-----------------------------------------------
  58. BOOL
  59. BeginTransaction()
  60. {
  61. BOOL bSuccess;
  62. try {
  63. bSuccess = m_JetDatabase.BeginTransaction();
  64. } catch( SE_Exception e ) {
  65. bSuccess = FALSE;
  66. SetLastError(e.getSeNumber());
  67. }
  68. catch(...) {
  69. bSuccess = FALSE;
  70. SetLastError(TLS_E_INTERNAL);
  71. }
  72. return bSuccess;
  73. }
  74. //-----------------------------------------------
  75. BOOL
  76. CommitTransaction()
  77. {
  78. BOOL bSuccess;
  79. try {
  80. bSuccess = m_JetDatabase.CommitTransaction();
  81. } catch( SE_Exception e ) {
  82. bSuccess = FALSE;
  83. SetLastError(e.getSeNumber());
  84. }
  85. catch(...) {
  86. bSuccess = FALSE;
  87. SetLastError(TLS_E_INTERNAL);
  88. }
  89. return bSuccess;
  90. }
  91. //-----------------------------------------------
  92. BOOL
  93. RollbackTransaction()
  94. {
  95. BOOL bSuccess;
  96. try {
  97. bSuccess = m_JetDatabase.RollbackTransaction();
  98. } catch( SE_Exception e ) {
  99. bSuccess = FALSE;
  100. SetLastError(e.getSeNumber());
  101. }
  102. catch(...) {
  103. bSuccess = FALSE;
  104. SetLastError(TLS_E_INTERNAL);
  105. }
  106. return bSuccess;
  107. }
  108. //-----------------------------------------------
  109. void
  110. Cleanup()
  111. {
  112. m_LicPackTable.Cleanup();
  113. m_LicPackDescTable.Cleanup();
  114. m_LicensedTable.Cleanup();
  115. }
  116. //------------------------------------------------
  117. __TlsDbWorkSpace() :
  118. m_JetSession(g_JbInstance),
  119. m_JetDatabase(m_JetSession),
  120. m_LicPackTable(m_JetDatabase),
  121. m_LicPackDescTable(m_JetDatabase),
  122. m_LicensedTable(m_JetDatabase)
  123. /*
  124. */
  125. {
  126. //
  127. // Force apps to call InitWorkSpace...
  128. //
  129. }
  130. //------------------------------------------------
  131. ~__TlsDbWorkSpace()
  132. {
  133. m_LicPackTable.CloseTable();
  134. m_LicPackDescTable.CloseTable();
  135. m_LicensedTable.CloseTable();
  136. m_JetDatabase.CloseDatabase();
  137. m_JetSession.EndSession();
  138. }
  139. //------------------------------------------------
  140. BOOL
  141. InitWorkSpace(
  142. BOOL bCreateIfNotExist,
  143. LPCTSTR szDatabaseFile,
  144. LPCTSTR szUserName=NULL,
  145. LPCTSTR szPassword=NULL,
  146. IN LPCTSTR szChkPointDirPath=NULL,
  147. IN LPCTSTR szTempDirPath=NULL,
  148. IN BOOL bUpdatable = FALSE
  149. );
  150. } TLSDbWorkSpace, *LPTLSDbWorkSpace, *PTLSDbWorkSpace;
  151. #ifdef __cplusplus
  152. extern "C" {
  153. #endif
  154. BOOL
  155. TLSJbInstanceInit(
  156. IN OUT JBInstance& jbInstance,
  157. IN LPCTSTR pszChkPointDirPath,
  158. IN LPCTSTR pszTempDirPath,
  159. IN LPCTSTR pszLogDirPath
  160. );
  161. TLSDbWorkSpace*
  162. AllocateWorkSpace(
  163. DWORD dwWaitTime
  164. );
  165. void
  166. ReleaseWorkSpace(
  167. PTLSDbWorkSpace *p
  168. );
  169. //
  170. BOOL
  171. InitializeWorkSpacePool(
  172. int num_workspace,
  173. LPCTSTR szDatabaseFile,
  174. LPCTSTR szUserName,
  175. LPCTSTR szPassword,
  176. LPCTSTR szChkPointDirPath,
  177. LPCTSTR szTempDirPath,
  178. LPCTSTR szLogDirPath,
  179. BOOL bUpdatable
  180. );
  181. DWORD
  182. CloseWorkSpacePool();
  183. WorkItemTable*
  184. GetWorkItemStorageTable();
  185. DWORD
  186. GetNumberOfWorkSpaceHandle();
  187. BOOL
  188. TLSGetESEError(
  189. const JET_ERR jetErrCode,
  190. LPTSTR* pszString
  191. );
  192. BOOL
  193. IsValidAllocatedWorkspace(
  194. PTLSDbWorkSpace p
  195. );
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199. #endif