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.

632 lines
12 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmcln.cpp
  5. Abstract:
  6. This component is an provides helper functions to access to the
  7. collections maintained by the HSM engine.
  8. Author:
  9. Cat Brant [cbrant] 09-Jan-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "wsb.h"
  14. #include "HsmEng.h"
  15. #include "HsmServ.h"
  16. #include "HsmConn.h"
  17. #include "job.h"
  18. #include "metalib.h"
  19. #define WSB_TRACE_IS WSB_TRACE_BIT_HSMENG
  20. // Local functions
  21. static HRESULT LoadCollection(IStream* pStream, IWsbIndexedCollection* pIWC);
  22. static HRESULT StoreCollection(IStream* pStream, IWsbIndexedCollection* pIWC);
  23. HRESULT
  24. CHsmServer::LoadJobs(
  25. IStream* pStream
  26. )
  27. /*++
  28. Routine Description:
  29. Loads the persistent data for Jobs
  30. Arguments:
  31. pStream - Data stream.
  32. Return Value:
  33. S_OK: The collection was loaded OK.
  34. --*/
  35. {
  36. HRESULT hr = S_OK;
  37. WsbTraceIn(OLESTR("CHsmServer::LoadJobs"),OLESTR(""));
  38. try {
  39. WsbAffirmHr(LoadCollection(pStream, m_pJobs));
  40. } WsbCatch(hr);
  41. WsbTraceOut(OLESTR("CHsmServer::LoadJobs"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  42. return(hr);
  43. }
  44. HRESULT
  45. CHsmServer::StoreJobs(
  46. IStream* pStream
  47. )
  48. /*++
  49. Routine Description:
  50. Saves the persistent data for Jobs.
  51. Arguments:
  52. pStream - Data stream.
  53. Return Value:
  54. S_OK: The collection was loaded OK.
  55. --*/
  56. {
  57. HRESULT hr = S_OK;
  58. WsbTraceIn(OLESTR("CHsmServer::StoreJobs"),OLESTR(""));
  59. //
  60. // Make sure we have a valid collection pointer
  61. //
  62. try {
  63. WsbAffirmHr(StoreCollection(pStream, m_pJobs));
  64. } WsbCatch(hr);
  65. WsbTraceOut(OLESTR("CHsmServer::StoreJobs"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  66. return(hr);
  67. }
  68. HRESULT
  69. CHsmServer::LoadJobDefs(
  70. IStream* pStream
  71. )
  72. /*++
  73. Routine Description:
  74. Loads the persistent data for Job Definitions
  75. Arguments:
  76. pStream - Data stream.
  77. Return Value:
  78. S_OK: The collection was loaded OK.
  79. --*/
  80. {
  81. HRESULT hr = S_OK;
  82. WsbTraceIn(OLESTR("CHsmServer::LoadJobDefs"),OLESTR(""));
  83. try {
  84. WsbAffirmHr(LoadCollection(pStream, m_pJobDefs));
  85. } WsbCatch(hr);
  86. WsbTraceOut(OLESTR("CHsmServer::LoadJobDefs"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  87. return(hr);
  88. }
  89. HRESULT
  90. CHsmServer::StoreJobDefs(
  91. IStream* pStream
  92. )
  93. /*++
  94. Routine Description:
  95. Saves the persistent data for Job Definitons
  96. Arguments:
  97. pStream - Data stream.
  98. Return Value:
  99. S_OK: The collection was loaded OK.
  100. --*/
  101. {
  102. HRESULT hr = S_OK;
  103. WsbTraceIn(OLESTR("CHsmServer::StoreJobDefs"),OLESTR(""));
  104. //
  105. try {
  106. WsbAffirmHr(StoreCollection(pStream, m_pJobDefs));
  107. } WsbCatch(hr);
  108. WsbTraceOut(OLESTR("CHsmServer::StoreJobDefs"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  109. return(hr);
  110. }
  111. HRESULT
  112. CHsmServer::LoadPolicies(
  113. IStream* pStream
  114. )
  115. /*++
  116. Routine Description:
  117. Loads the persistent data for policies
  118. Arguments:
  119. pStream - Data stream.
  120. Return Value:
  121. S_OK: The collection was loaded OK.
  122. --*/
  123. {
  124. HRESULT hr = S_OK;
  125. WsbTraceIn(OLESTR("CHsmServer::LoadPolicies"),OLESTR(""));
  126. try {
  127. WsbAffirmHr(LoadCollection(pStream, m_pPolicies));
  128. } WsbCatch(hr);
  129. WsbTraceOut(OLESTR("CHsmServer::LoadPolicies"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  130. return(hr);
  131. }
  132. HRESULT
  133. CHsmServer::StorePolicies(
  134. IStream* pStream
  135. )
  136. /*++
  137. Routine Description:
  138. Saves the persistent data for policies.
  139. Arguments:
  140. pStream - Data stream.
  141. Return Value:
  142. S_OK: The collection was loaded OK.
  143. --*/
  144. {
  145. HRESULT hr = S_OK;
  146. WsbTraceIn(OLESTR("CHsmServer::StorePolicies"),OLESTR(""));
  147. //
  148. // Make sure we have a valid collection pointer
  149. //
  150. try {
  151. WsbAffirmHr(StoreCollection(pStream, m_pPolicies));
  152. } WsbCatch(hr);
  153. WsbTraceOut(OLESTR("CHsmServer::StorePolicies"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  154. return(hr);
  155. }
  156. HRESULT
  157. CHsmServer::LoadManagedResources(
  158. IStream* pStream
  159. )
  160. /*++
  161. Routine Description:
  162. Loads the persistent data for managed resources
  163. Arguments:
  164. pStream - Data stream.
  165. Return Value:
  166. S_OK: The collection was loaded OK.
  167. --*/
  168. {
  169. HRESULT hr = S_OK;
  170. WsbTraceIn(OLESTR("CHsmServer::LoadManagedResources"),OLESTR(""));
  171. try {
  172. WsbAffirmHr(LoadCollection(pStream, m_pManagedResources));
  173. } WsbCatch(hr);
  174. WsbTraceOut(OLESTR("CHsmServer::LoadManagedResources"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  175. return(hr);
  176. }
  177. HRESULT
  178. CHsmServer::StoreManagedResources(
  179. IStream* pStream
  180. )
  181. /*++
  182. Routine Description:
  183. Saves the persistent data for managed resources.
  184. Arguments:
  185. pStream - Data stream.
  186. Return Value:
  187. S_OK: The collection was loaded OK.
  188. --*/
  189. {
  190. HRESULT hr = S_OK;
  191. WsbTraceIn(OLESTR("CHsmServer::StoreManagedResources"),OLESTR(""));
  192. //
  193. // Make sure we have a valid collection pointer
  194. //
  195. try {
  196. WsbAffirmHr(StoreCollection(pStream, m_pManagedResources));
  197. } WsbCatch(hr);
  198. WsbTraceOut(OLESTR("CHsmServer::StoreManagedResources"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  199. return(hr);
  200. }
  201. HRESULT
  202. CHsmServer::LoadStoragePools(
  203. IStream* pStream
  204. )
  205. /*++
  206. Routine Description:
  207. Loads the persistent data for storage pools
  208. Arguments:
  209. pStream - Data stream.
  210. Return Value:
  211. S_OK: The collection was loaded OK.
  212. --*/
  213. {
  214. HRESULT hr = S_OK;
  215. WsbTraceIn(OLESTR("CHsmServer::LoadStoragePools"),OLESTR(""));
  216. try {
  217. WsbAffirmHr(LoadCollection(pStream, m_pStoragePools));
  218. } WsbCatch(hr);
  219. WsbTraceOut(OLESTR("CHsmServer::LoadStoragePools"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  220. return(hr);
  221. }
  222. HRESULT
  223. CHsmServer::StoreStoragePools(
  224. IStream* pStream
  225. )
  226. /*++
  227. Routine Description:
  228. Saves the persistent data for managed resources.
  229. Arguments:
  230. pStream - Data stream.
  231. Return Value:
  232. S_OK: The collection was loaded OK.
  233. --*/
  234. {
  235. HRESULT hr = S_OK;
  236. WsbTraceIn(OLESTR("CHsmServer::StoreStoragePools"),OLESTR(""));
  237. //
  238. // Make sure we have a valid collection pointer
  239. //
  240. try {
  241. WsbAffirmHr(StoreCollection(pStream, m_pStoragePools));
  242. } WsbCatch(hr);
  243. WsbTraceOut(OLESTR("CHsmServer::StoreStoragePools"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  244. return(hr);
  245. }
  246. HRESULT
  247. CHsmServer::LoadSegmentInformation(
  248. void
  249. )
  250. /*++
  251. Routine Description:
  252. Loads the persistent data for the segment information
  253. Arguments:
  254. None
  255. Return Value:
  256. S_OK: The collection was loaded OK.
  257. --*/
  258. {
  259. HRESULT hr = S_OK;
  260. CWsbStringPtr tmpString;
  261. WsbTraceIn(OLESTR("CHsmServer::LoadSegmentInformation"),OLESTR(""));
  262. try {
  263. BOOL CreateFlag = FALSE;
  264. CComPtr<ISegDb> l_pSegmentDatabase;
  265. // Determine if we should try to create the DB or just open it.
  266. // If the persistence file was just created we're probably starting
  267. // for the first time so creating the DB is correct. Also, if
  268. // the media count is still zero, then even if there was an old
  269. // DB that got deleted, it probably didn't have any useful information
  270. // in it anyway so creating a new one is OK.
  271. if (m_persistWasCreated || 0 == m_mediaCount) {
  272. CreateFlag = TRUE;
  273. }
  274. // Initialize the Engine database
  275. //
  276. WsbAffirmHr(CoCreateInstance( CLSID_CSegDb, 0, CLSCTX_SERVER, IID_ISegDb, (void **)&l_pSegmentDatabase ));
  277. WsbAffirmHr(GetIDbPath(&tmpString, 0));
  278. WsbAffirmHr(l_pSegmentDatabase->Initialize(tmpString, m_pDbSys, &CreateFlag));
  279. WsbAffirmHr(l_pSegmentDatabase->QueryInterface(IID_IWsbDb, (void**) &m_pSegmentDatabase));
  280. } WsbCatch(hr);
  281. WsbTraceOut(OLESTR("CHsmServer::LoadSegmentInformation"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  282. return(hr);
  283. }
  284. HRESULT
  285. CHsmServer::StoreSegmentInformation(
  286. void
  287. )
  288. /*++
  289. Routine Description:
  290. Saves the persistent data for the segment information.
  291. Arguments:
  292. None
  293. Return Value:
  294. S_OK: The collection was loaded OK.
  295. --*/
  296. {
  297. HRESULT hr = S_OK;
  298. // CWsbStringPtr tmpString;
  299. WsbTraceIn(OLESTR("CHsmServer::StoreSegmentInformation"),OLESTR(""));
  300. //
  301. // Make sure we have a valid collection pointer
  302. //
  303. try {
  304. WsbAssert(m_pSegmentDatabase != 0, E_POINTER);
  305. // This should not be necessary for a real DB
  306. // WsbAffirmHr(m_pSegmentDatabase->Close());
  307. // WsbAffirmHr(m_pSegmentDatabase->Open());
  308. } WsbCatch(hr);
  309. WsbTraceOut(OLESTR("CHsmServer::StoreSegmentInformation"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  310. return(hr);
  311. }
  312. HRESULT
  313. CHsmServer::StoreSegmentInformationFinal(
  314. void
  315. )
  316. /*++
  317. Routine Description:
  318. Saves the segment information
  319. Arguments:
  320. None
  321. Return Value:
  322. S_OK: The collection was loaded OK.
  323. --*/
  324. {
  325. HRESULT hr = S_OK;
  326. CWsbStringPtr tmpString;
  327. WsbTraceIn(OLESTR("CHsmServer::StoreSegmentInformationFinal"),OLESTR(""));
  328. try {
  329. WsbAssert(m_pSegmentDatabase.p != 0, E_POINTER);
  330. // This should not be necessary for a real DB
  331. // WsbAffirmHr(m_pSegmentDatabase->Close());
  332. m_pSegmentDatabase = 0;
  333. } WsbCatch(hr);
  334. WsbTraceOut(OLESTR("CHsmServer::StoreSegmentInformationFinal"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  335. return(hr);
  336. }
  337. HRESULT
  338. CHsmServer::LoadMessages(
  339. IStream* pStream
  340. )
  341. /*++
  342. Routine Description:
  343. Loads the persistent data for messages
  344. Arguments:
  345. pStream - Data stream.
  346. Return Value:
  347. S_OK: The collection was loaded OK.
  348. --*/
  349. {
  350. HRESULT hr = S_OK;
  351. WsbTraceIn(OLESTR("CHsmServer::LoadMessages"),OLESTR(""));
  352. try {
  353. WsbAffirmHr(LoadCollection(pStream, m_pMessages));
  354. } WsbCatch(hr);
  355. WsbTraceOut(OLESTR("CHsmServer::LoadMessages"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  356. return(hr);
  357. }
  358. HRESULT
  359. CHsmServer::StoreMessages(
  360. IStream* pStream
  361. )
  362. /*++
  363. Routine Description:
  364. Saves the persistent data for messages.
  365. Arguments:
  366. pStream - Data stream.
  367. Return Value:
  368. S_OK: The collection was saved OK.
  369. --*/
  370. {
  371. HRESULT hr = S_OK;
  372. WsbTraceIn(OLESTR("CHsmServer::StoreMessages"),OLESTR(""));
  373. //
  374. // Make sure we have a valid collection pointer
  375. //
  376. try {
  377. WsbAffirmHr(StoreCollection(pStream, m_pMessages));
  378. } WsbCatch(hr);
  379. WsbTraceOut(OLESTR("CHsmServer::StoreMessages"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  380. return(hr);
  381. }
  382. // LoadCollection - load a collection from the given stream
  383. static HRESULT LoadCollection(IStream* pStream, IWsbIndexedCollection* pIWC)
  384. {
  385. HRESULT hr = S_OK;
  386. try {
  387. CComPtr<IPersistStream> pIStream;
  388. WsbAffirm(0 != pStream, E_POINTER);
  389. WsbAffirm(0 != pIWC, E_POINTER);
  390. // Load the ordered collection from the persistent file
  391. WsbAffirmHr(pIWC->QueryInterface(IID_IPersistStream, (void**)&pIStream));
  392. WsbAffirmHr(pIStream->Load(pStream));
  393. } WsbCatch(hr);
  394. return(hr);
  395. }
  396. // StoreCollection - store a collection to the given stream
  397. static HRESULT StoreCollection(IStream* pStream, IWsbIndexedCollection* pIWC)
  398. {
  399. HRESULT hr = S_OK;
  400. try {
  401. CComPtr<IPersistStream> pIStream;
  402. // Get the IPersistStream interface for the collection
  403. WsbAffirm(0 != pStream, E_POINTER);
  404. WsbAffirm(0 != pIWC, E_POINTER);
  405. WsbAffirmHr(pIWC->QueryInterface(IID_IPersistStream, (void**)&pIStream));
  406. // Store the ordered collection to the persistent file
  407. WsbAffirmHr(pIStream->Save(pStream, TRUE));
  408. } WsbCatch(hr);
  409. return(hr);
  410. }