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.

961 lines
24 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmjobcx.cpp
  5. Abstract:
  6. This class contains properties that define the job, mainly the policies
  7. to be enacted by the job.
  8. Author:
  9. Chuck Bardeen [cbardeen] 29-Oct-1996
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include "wsb.h"
  14. #include "job.h"
  15. #include "hsmjobdf.h"
  16. #define WSB_TRACE_IS WSB_TRACE_BIT_JOB
  17. HRESULT
  18. CHsmJobDef::EnumPolicies(
  19. IWsbEnum** ppEnum
  20. )
  21. /*++
  22. Implements:
  23. IHsmJobDef::EnumPolicies().
  24. --*/
  25. {
  26. HRESULT hr = S_OK;
  27. try {
  28. WsbAssert(0 != ppEnum, E_POINTER);
  29. WsbAffirmHr(m_pPolicies->Enum(ppEnum));
  30. } WsbCatch(hr);
  31. return(hr);
  32. }
  33. HRESULT
  34. CHsmJobDef::FinalConstruct(
  35. void
  36. )
  37. /*++
  38. Implements:
  39. CComObjectRoot::FinalConstruct().
  40. --*/
  41. {
  42. HRESULT hr = S_OK;
  43. try {
  44. WsbAffirmHr(CWsbObject::FinalConstruct());
  45. m_skipHiddenItems = TRUE;
  46. m_skipSystemItems = TRUE;
  47. m_useRPIndex = FALSE;
  48. m_useDbIndex = FALSE;
  49. // Each instance should have its own unique identifier.
  50. WsbAffirmHr(CoCreateGuid(&m_id));
  51. //Create the Policies collection (with no items).
  52. WsbAffirmHr(CoCreateInstance(CLSID_CWsbOrderedCollection, NULL, CLSCTX_ALL, IID_IWsbCollection, (void**) &m_pPolicies));
  53. } WsbCatch(hr);
  54. return(hr);
  55. }
  56. HRESULT
  57. CHsmJobDef::GetClassID(
  58. OUT CLSID* pClsid
  59. )
  60. /*++
  61. Implements:
  62. IPersist::GetClassID().
  63. --*/
  64. {
  65. HRESULT hr = S_OK;
  66. WsbTraceIn(OLESTR("CHsmJobDef::GetClassID"), OLESTR(""));
  67. try {
  68. WsbAssert(0 != pClsid, E_POINTER);
  69. *pClsid = CLSID_CHsmJobDef;
  70. } WsbCatch(hr);
  71. WsbTraceOut(OLESTR("CHsmJobDef::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  72. return(hr);
  73. }
  74. HRESULT
  75. CHsmJobDef::GetIdentifier(
  76. GUID* pId
  77. )
  78. /*++
  79. Implements:
  80. IHsmJobDef::GetIdentifier().
  81. --*/
  82. {
  83. HRESULT hr = S_OK;
  84. try {
  85. WsbAssert(0 != pId, E_POINTER);
  86. *pId = m_id;
  87. } WsbCatch(hr);
  88. return(hr);
  89. }
  90. HRESULT
  91. CHsmJobDef::GetName(
  92. OLECHAR** pName,
  93. ULONG bufferSize
  94. )
  95. /*++
  96. Implements:
  97. IHsmJobDef::GetName().
  98. --*/
  99. {
  100. HRESULT hr = S_OK;
  101. try {
  102. WsbAssert(0 != pName, E_POINTER);
  103. WsbAffirmHr(m_name.CopyTo(pName, bufferSize));
  104. } WsbCatch(hr);
  105. return(hr);
  106. }
  107. HRESULT
  108. CHsmJobDef::GetPostActionOnResource(
  109. OUT IHsmActionOnResourcePost** ppAction
  110. )
  111. /*++
  112. Implements:
  113. IHsmJobDef::GetPostActionOnResource().
  114. --*/
  115. {
  116. HRESULT hr = S_OK;
  117. try {
  118. WsbAssertPointer(ppAction);
  119. *ppAction = m_pActionResourcePost;
  120. if (m_pActionResourcePost) {
  121. m_pActionResourcePost->AddRef();
  122. }
  123. } WsbCatch(hr);
  124. return(hr);
  125. }
  126. HRESULT
  127. CHsmJobDef::GetPreActionOnResource(
  128. OUT IHsmActionOnResourcePre** ppAction
  129. )
  130. /*++
  131. Implements:
  132. IHsmJobDef::GetPreActionOnResource().
  133. --*/
  134. {
  135. HRESULT hr = S_OK;
  136. try {
  137. WsbAssertPointer(ppAction);
  138. *ppAction = m_pActionResourcePre;
  139. if (m_pActionResourcePre) {
  140. m_pActionResourcePre->AddRef();
  141. }
  142. } WsbCatch(hr);
  143. return(hr);
  144. }
  145. HRESULT
  146. CHsmJobDef::GetPreScanActionOnResource(
  147. OUT IHsmActionOnResourcePreScan** ppAction
  148. )
  149. /*++
  150. Implements:
  151. IHsmJobDef::GetPreScanActionOnResource().
  152. --*/
  153. {
  154. HRESULT hr = S_OK;
  155. try {
  156. WsbAssertPointer(ppAction);
  157. *ppAction = m_pActionResourcePreScan;
  158. if (m_pActionResourcePreScan) {
  159. m_pActionResourcePreScan->AddRef();
  160. }
  161. } WsbCatch(hr);
  162. return(hr);
  163. }
  164. HRESULT
  165. CHsmJobDef::GetSizeMax(
  166. OUT ULARGE_INTEGER* pSize
  167. )
  168. /*++
  169. Implements:
  170. IPersistStream::GetSizeMax().
  171. --*/
  172. {
  173. HRESULT hr = S_OK;
  174. CComPtr<IPersistStream> pPersistStream;
  175. ULARGE_INTEGER entrySize;
  176. WsbTraceIn(OLESTR("CHsmJobDef::GetSizeMax"), OLESTR(""));
  177. try {
  178. pSize->QuadPart = WsbPersistSizeOf(GUID) + 2 * WsbPersistSizeOf(BOOL) + WsbPersistSizeOf(ULONG) + WsbPersistSize((wcslen(m_name) + 1) * sizeof(OLECHAR));
  179. WsbAffirmHr(m_pPolicies->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  180. WsbAffirmHr(pPersistStream->GetSizeMax(&entrySize));
  181. pPersistStream = 0;
  182. pSize->QuadPart += entrySize.QuadPart;
  183. WsbAffirmHr(m_pPolicies->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  184. WsbAffirmHr(pPersistStream->GetSizeMax(&entrySize));
  185. pPersistStream = 0;
  186. pSize->QuadPart += entrySize.QuadPart;
  187. } WsbCatch(hr);
  188. WsbTraceOut(OLESTR("CHsmJobDef::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pSize));
  189. return(hr);
  190. }
  191. HRESULT
  192. CHsmJobDef::InitAs(
  193. IN OLECHAR* name,
  194. IN HSM_JOB_DEF_TYPE type,
  195. IN GUID storagePool,
  196. IN IHsmServer* pServer,
  197. IN BOOL isUserDefined
  198. )
  199. /*++
  200. Implements:
  201. IHsmJobDef::InitAs().
  202. --*/
  203. {
  204. HRESULT hr = S_OK;
  205. CComPtr<IHsmJobContext> pContext;
  206. CComPtr<IHsmPolicy> pPolicy;
  207. CComPtr<IHsmRule> pRule;
  208. CComPtr<IHsmCriteria> pCriteria;
  209. CComPtr<IHsmAction> pAction;
  210. CComPtr<IHsmDirectedAction> pDirectedAction;
  211. CComPtr<IWsbGuid> pGuid;
  212. CComPtr<IWsbCollection> pRulesCollection;
  213. CComPtr<IWsbCollection> pCriteriaCollection;
  214. CComPtr<IWsbCreateLocalObject> pCreateObj;
  215. WsbTraceIn(OLESTR("CHsmJobDef::InitAs"), OLESTR("name = <%ls>, type = %ld"),
  216. name, static_cast<LONG>(type));
  217. try {
  218. WsbAssert(0 != name, E_POINTER);
  219. // All objects created need to be owned by the engine.
  220. WsbAffirmHr(pServer->QueryInterface(IID_IWsbCreateLocalObject, (void**) &pCreateObj));
  221. // All types will need a policy and at least one rule.
  222. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmPolicy, IID_IHsmPolicy, (void**) &pPolicy));
  223. WsbAffirmHr(pPolicy->SetName(name));
  224. WsbAffirmHr(pPolicy->Rules(&pRulesCollection));
  225. WsbAffirmHr(m_pPolicies->Add(pPolicy));
  226. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmRule, IID_IHsmRule, (void**) &pRule));
  227. WsbAffirmHr(pRule->SetIsInclude(TRUE));
  228. WsbAffirmHr(pRule->SetIsUserDefined(isUserDefined));
  229. WsbAffirmHr(pRule->SetIsUsedInSubDirs(TRUE));
  230. WsbAffirmHr(pRule->SetName(OLESTR("*")));
  231. WsbAffirmHr(pRule->SetPath(OLESTR("\\")));
  232. WsbAffirmHr(pRule->Criteria(&pCriteriaCollection));
  233. WsbAffirmHr(pRulesCollection->Add(pRule));
  234. // The criteria and the action vary upon the job type.
  235. switch(type) {
  236. case HSM_JOB_DEF_TYPE_MANAGE:
  237. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionManage, IID_IHsmAction, (void**) &pAction));
  238. WsbAffirmHr(pAction->QueryInterface(IID_IHsmDirectedAction, (void**) &pDirectedAction));
  239. WsbAffirmHr(pDirectedAction->SetStoragePoolId(storagePool));
  240. WsbAffirmHr(pPolicy->SetAction(pAction));
  241. WsbAffirmHr(pPolicy->SetUsesDefaultRules(TRUE));
  242. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritManageable, IID_IHsmCriteria, (void**) &pCriteria));
  243. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  244. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  245. break;
  246. case HSM_JOB_DEF_TYPE_RECALL:
  247. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionRecall, IID_IHsmAction, (void**) &pAction));
  248. WsbAffirmHr(pPolicy->SetAction(pAction));
  249. WsbAffirmHr(pPolicy->SetUsesDefaultRules(FALSE));
  250. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritMigrated, IID_IHsmCriteria, (void**) &pCriteria));
  251. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  252. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  253. break;
  254. case HSM_JOB_DEF_TYPE_TRUNCATE:
  255. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionTruncate, IID_IHsmAction, (void**) &pAction));
  256. WsbAffirmHr(pPolicy->SetAction(pAction));
  257. WsbAffirmHr(pPolicy->SetUsesDefaultRules(FALSE));
  258. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritPremigrated, IID_IHsmCriteria, (void**) &pCriteria));
  259. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  260. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  261. break;
  262. case HSM_JOB_DEF_TYPE_UNMANAGE:
  263. m_useRPIndex = TRUE;
  264. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionUnmanage, IID_IHsmAction, (void**) &pAction));
  265. WsbAffirmHr(pPolicy->SetAction(pAction));
  266. WsbAffirmHr(pPolicy->SetUsesDefaultRules(FALSE));
  267. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritPremigrated, IID_IHsmCriteria, (void**) &pCriteria));
  268. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  269. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  270. pCriteria = 0;
  271. pCriteriaCollection = 0;
  272. pRule = 0;
  273. // Add an addition rule
  274. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmRule, IID_IHsmRule, (void**) &pRule));
  275. WsbAffirmHr(pRule->SetIsInclude(TRUE));
  276. WsbAffirmHr(pRule->SetIsUserDefined(isUserDefined));
  277. WsbAffirmHr(pRule->SetIsUsedInSubDirs(TRUE));
  278. WsbAffirmHr(pRule->SetName(OLESTR("*")));
  279. WsbAffirmHr(pRule->SetPath(OLESTR("\\")));
  280. WsbAffirmHr(pRule->Criteria(&pCriteriaCollection));
  281. WsbAffirmHr(pRulesCollection->Add(pRule));
  282. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritMigrated, IID_IHsmCriteria, (void**) &pCriteria));
  283. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  284. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  285. break;
  286. case HSM_JOB_DEF_TYPE_FULL_UNMANAGE:
  287. m_useRPIndex = TRUE;
  288. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionUnmanage, IID_IHsmAction, (void**) &pAction));
  289. WsbAffirmHr(pPolicy->SetAction(pAction));
  290. WsbAffirmHr(pPolicy->SetUsesDefaultRules(FALSE));
  291. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritPremigrated, IID_IHsmCriteria, (void**) &pCriteria));
  292. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  293. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  294. pCriteria = 0;
  295. pCriteriaCollection = 0;
  296. pRule = 0;
  297. // Add an addition rule
  298. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmRule, IID_IHsmRule, (void**) &pRule));
  299. WsbAffirmHr(pRule->SetIsInclude(TRUE));
  300. WsbAffirmHr(pRule->SetIsUserDefined(isUserDefined));
  301. WsbAffirmHr(pRule->SetIsUsedInSubDirs(TRUE));
  302. WsbAffirmHr(pRule->SetName(OLESTR("*")));
  303. WsbAffirmHr(pRule->SetPath(OLESTR("\\")));
  304. WsbAffirmHr(pRule->Criteria(&pCriteriaCollection));
  305. WsbAffirmHr(pRulesCollection->Add(pRule));
  306. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritMigrated, IID_IHsmCriteria, (void**) &pCriteria));
  307. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  308. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  309. // When done, remove the volume from management
  310. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionOnResourcePostUnmanage,
  311. IID_IHsmActionOnResourcePost, (void**) &m_pActionResourcePost));
  312. // When starting, mark the resource as DeletePending
  313. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionOnResourcePreUnmanage,
  314. IID_IHsmActionOnResourcePre, (void**) &m_pActionResourcePre));
  315. break;
  316. case HSM_JOB_DEF_TYPE_QUICK_UNMANAGE:
  317. m_useRPIndex = TRUE;
  318. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionUnmanage, IID_IHsmAction, (void**) &pAction));
  319. WsbAffirmHr(pPolicy->SetAction(pAction));
  320. WsbAffirmHr(pPolicy->SetUsesDefaultRules(FALSE));
  321. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritPremigrated, IID_IHsmCriteria, (void**) &pCriteria));
  322. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  323. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  324. // Clean out pointers so we can create more stuff
  325. pPolicy.Release();
  326. pAction.Release();
  327. pRulesCollection.Release();
  328. pCriteria.Release();
  329. pCriteriaCollection.Release();
  330. pRule.Release();
  331. // Create a new policy for job to do the delete
  332. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmPolicy, IID_IHsmPolicy, (void**) &pPolicy));
  333. WsbAffirmHr(pPolicy->SetName(name));
  334. WsbAffirmHr(pPolicy->Rules(&pRulesCollection));
  335. WsbAffirmHr(m_pPolicies->Add(pPolicy));
  336. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionDelete, IID_IHsmAction, (void**) &pAction));
  337. WsbAffirmHr(pPolicy->SetAction(pAction));
  338. WsbAffirmHr(pPolicy->SetUsesDefaultRules(FALSE));
  339. // Add an addition rule
  340. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmRule, IID_IHsmRule, (void**) &pRule));
  341. WsbAffirmHr(pRule->SetIsInclude(TRUE));
  342. WsbAffirmHr(pRule->SetIsUserDefined(isUserDefined));
  343. WsbAffirmHr(pRule->SetIsUsedInSubDirs(TRUE));
  344. WsbAffirmHr(pRule->SetName(OLESTR("*")));
  345. WsbAffirmHr(pRule->SetPath(OLESTR("\\")));
  346. WsbAffirmHr(pRule->Criteria(&pCriteriaCollection));
  347. WsbAffirmHr(pRulesCollection->Add(pRule));
  348. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritMigrated, IID_IHsmCriteria, (void**) &pCriteria));
  349. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  350. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  351. // When done, remove the volume from management
  352. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionOnResourcePostUnmanage,
  353. IID_IHsmActionOnResourcePost, (void**) &m_pActionResourcePost));
  354. // When starting, mark the resource as DeletePending
  355. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionOnResourcePreUnmanage,
  356. IID_IHsmActionOnResourcePre, (void**) &m_pActionResourcePre));
  357. break;
  358. case HSM_JOB_DEF_TYPE_VALIDATE:
  359. m_useRPIndex = TRUE;
  360. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionValidate, IID_IHsmAction, (void**) &pAction));
  361. WsbAffirmHr(pPolicy->SetAction(pAction));
  362. WsbAffirmHr(pPolicy->SetUsesDefaultRules(FALSE));
  363. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritPremigrated, IID_IHsmCriteria, (void**) &pCriteria));
  364. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  365. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  366. pCriteria = 0;
  367. pCriteriaCollection = 0;
  368. pRule = 0;
  369. // Add an addition rule
  370. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmRule, IID_IHsmRule, (void**) &pRule));
  371. WsbAffirmHr(pRule->SetIsInclude(TRUE));
  372. WsbAffirmHr(pRule->SetIsUserDefined(isUserDefined));
  373. WsbAffirmHr(pRule->SetIsUsedInSubDirs(TRUE));
  374. WsbAffirmHr(pRule->SetName(OLESTR("*")));
  375. WsbAffirmHr(pRule->SetPath(OLESTR("\\")));
  376. WsbAffirmHr(pRule->Criteria(&pCriteriaCollection));
  377. WsbAffirmHr(pRulesCollection->Add(pRule));
  378. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmCritMigrated, IID_IHsmCriteria, (void**) &pCriteria));
  379. WsbAffirmHr(pCriteria->SetIsNegated(FALSE));
  380. WsbAffirmHr(pCriteriaCollection->Add(pCriteria));
  381. // Add pre & post actions on resources
  382. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionOnResourcePreValidate,
  383. IID_IHsmActionOnResourcePre, (void**) &m_pActionResourcePre));
  384. WsbAffirmHr(pCreateObj->CreateInstance(CLSID_CHsmActionOnResourcePostValidate,
  385. IID_IHsmActionOnResourcePost, (void**) &m_pActionResourcePost));
  386. WsbTrace(OLESTR("CHsmJobDef::InitAs(Validate): m_pActionResourcePre = %lx, m_pActionResourcePost = %lx\n"),
  387. static_cast<void*>(m_pActionResourcePre), static_cast<void*>(m_pActionResourcePost));
  388. break;
  389. }
  390. // There are a couple of other fields to fill out in the job definition
  391. m_name = name;
  392. } WsbCatch(hr);
  393. WsbTraceOut(OLESTR("CHsmJobDef::InitAs"), OLESTR("hr = <%ls>"),
  394. WsbHrAsString(hr));
  395. return(hr);
  396. }
  397. HRESULT
  398. CHsmJobDef::Load(
  399. IN IStream* pStream
  400. )
  401. /*++
  402. Implements:
  403. IPersistStream::Load().
  404. --*/
  405. {
  406. BOOL hasA;
  407. HRESULT hr = S_OK;
  408. CComPtr<IPersistStream> pPersistStream;
  409. WsbTraceIn(OLESTR("CHsmJobDef::Load"), OLESTR(""));
  410. try {
  411. WsbAssert(0 != pStream, E_POINTER);
  412. WsbLoadFromStream(pStream, &m_id);
  413. WsbLoadFromStream(pStream, &m_name, 0);
  414. WsbLoadFromStream(pStream, &m_skipHiddenItems);
  415. WsbLoadFromStream(pStream, &m_skipSystemItems);
  416. WsbLoadFromStream(pStream, &m_useRPIndex);
  417. WsbAffirmHr(m_pPolicies->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  418. WsbAffirmHr(pPersistStream->Load(pStream));
  419. // Is there a pre-scan resource action?
  420. WsbAffirmHr(WsbLoadFromStream(pStream, &hasA));
  421. if (hasA) {
  422. WsbAffirmHr(OleLoadFromStream(pStream, IID_IHsmActionOnResourcePre,
  423. (void**) &m_pActionResourcePre));
  424. }
  425. // Is there a post-scan resource action?
  426. WsbAffirmHr(WsbLoadFromStream(pStream, &hasA));
  427. if (hasA) {
  428. WsbAffirmHr(OleLoadFromStream(pStream, IID_IHsmActionOnResourcePost,
  429. (void**) &m_pActionResourcePost));
  430. }
  431. } WsbCatch(hr);
  432. WsbTraceOut(OLESTR("CHsmJobDef::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  433. return(hr);
  434. }
  435. HRESULT
  436. CHsmJobDef::Policies(
  437. IWsbCollection** ppPolicies
  438. )
  439. /*++
  440. Implements:
  441. IHsmJobDef::Policies().
  442. --*/
  443. {
  444. HRESULT hr = S_OK;
  445. try {
  446. WsbAssert(0 != ppPolicies, E_POINTER);
  447. *ppPolicies = m_pPolicies;
  448. m_pPolicies->AddRef();
  449. } WsbCatch(hr);
  450. return(hr);
  451. }
  452. HRESULT
  453. CHsmJobDef::Save(
  454. IN IStream* pStream,
  455. IN BOOL clearDirty
  456. )
  457. /*++
  458. Implements:
  459. IPersistStream::Save().
  460. --*/
  461. {
  462. BOOL hasA;
  463. HRESULT hr = S_OK;
  464. CComPtr<IPersistStream> pPersistStream;
  465. WsbTraceIn(OLESTR("CHsmJobDef::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  466. try {
  467. WsbAssert(0 != pStream, E_POINTER);
  468. WsbSaveToStream(pStream, m_id);
  469. WsbSaveToStream(pStream, m_name);
  470. WsbSaveToStream(pStream, m_skipHiddenItems);
  471. WsbSaveToStream(pStream, m_skipSystemItems);
  472. WsbSaveToStream(pStream, m_useRPIndex);
  473. WsbAffirmHr(m_pPolicies->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  474. WsbAffirmHr(pPersistStream->Save(pStream, clearDirty));
  475. pPersistStream = 0;
  476. // Save pre-scan resource action if present
  477. WsbTrace(OLESTR("CHsmJobDef::Save: m_pActionResourcePre = %lx, m_pActionResourcePost = %lx\n"),
  478. static_cast<void*>(m_pActionResourcePre), static_cast<void*>(m_pActionResourcePost));
  479. if (m_pActionResourcePre) {
  480. hasA = TRUE;
  481. WsbSaveToStream(pStream, hasA);
  482. WsbAffirmHr(m_pActionResourcePre->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  483. WsbAffirmHr(OleSaveToStream(pPersistStream, pStream));
  484. pPersistStream = 0;
  485. } else {
  486. hasA = FALSE;
  487. WsbSaveToStream(pStream, hasA);
  488. }
  489. // Save post-scan resource action if present
  490. if (m_pActionResourcePost) {
  491. hasA = TRUE;
  492. WsbSaveToStream(pStream, hasA);
  493. WsbAffirmHr(m_pActionResourcePost->QueryInterface(IID_IPersistStream, (void**) &pPersistStream));
  494. WsbAffirmHr(OleSaveToStream(pPersistStream, pStream));
  495. pPersistStream = 0;
  496. } else {
  497. hasA = FALSE;
  498. WsbSaveToStream(pStream, hasA);
  499. }
  500. // If we got it saved and we were asked to clear the dirty bit, then
  501. // do so now.
  502. if (clearDirty) {
  503. m_isDirty = FALSE;
  504. }
  505. } WsbCatch(hr);
  506. WsbTraceOut(OLESTR("CHsmJobDef::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  507. return(hr);
  508. }
  509. HRESULT
  510. CHsmJobDef::SetName(
  511. OLECHAR* name
  512. )
  513. /*++
  514. Implements:
  515. IHsmJobDef::SetName().
  516. --*/
  517. {
  518. HRESULT hr = S_OK;
  519. try {
  520. m_name = name;
  521. } WsbCatch(hr);
  522. return(hr);
  523. }
  524. HRESULT
  525. CHsmJobDef::SetPostActionOnResource(
  526. IN IHsmActionOnResourcePost* pAction
  527. )
  528. /*++
  529. Implements:
  530. IHsmJobDef::SetPostActionOnResource
  531. --*/
  532. {
  533. m_pActionResourcePost = pAction;
  534. return(S_OK);
  535. }
  536. HRESULT
  537. CHsmJobDef::SetPreActionOnResource(
  538. IN IHsmActionOnResourcePre* pAction
  539. )
  540. /*++
  541. Implements:
  542. IHsmJobDef::SetPreActionOnResource
  543. --*/
  544. {
  545. m_pActionResourcePre = pAction;
  546. return(S_OK);
  547. }
  548. HRESULT
  549. CHsmJobDef::SetPreScanActionOnResource(
  550. IN IHsmActionOnResourcePreScan* pAction
  551. )
  552. /*++
  553. Implements:
  554. IHsmJobDef::SetPreScanActionOnResource
  555. --*/
  556. {
  557. m_pActionResourcePreScan = pAction;
  558. return(S_OK);
  559. }
  560. HRESULT
  561. CHsmJobDef::SkipHiddenItems(
  562. void
  563. )
  564. /*++
  565. Implements:
  566. IHsmJobDef::SkipHiddenItems().
  567. --*/
  568. {
  569. return(m_skipHiddenItems ? S_OK : S_FALSE);
  570. }
  571. HRESULT
  572. CHsmJobDef::SkipSystemItems(
  573. void
  574. )
  575. /*++
  576. Implements:
  577. IHsmJobDef::SkipSystemItems().
  578. --*/
  579. {
  580. return(m_skipSystemItems ? S_OK : S_FALSE);
  581. }
  582. HRESULT
  583. CHsmJobDef::SetSkipHiddenItems(
  584. IN BOOL shouldSkip
  585. )
  586. /*++
  587. Implements:
  588. IHsmJobDef::SetSkipHiddenItems().
  589. --*/
  590. {
  591. m_skipHiddenItems = shouldSkip;
  592. return(S_OK);
  593. }
  594. HRESULT
  595. CHsmJobDef::SetSkipSystemItems(
  596. IN BOOL shouldSkip
  597. )
  598. /*++
  599. Implements:
  600. IHsmJobDef::SetSkipSytemItems().
  601. --*/
  602. {
  603. m_skipSystemItems = shouldSkip;
  604. return(S_OK);
  605. }
  606. HRESULT
  607. CHsmJobDef::SetUseRPIndex(
  608. IN BOOL useRPIndex
  609. )
  610. /*++
  611. Implements:
  612. IHsmJobDef::SetUseRPIndex().
  613. --*/
  614. {
  615. m_useRPIndex = useRPIndex;
  616. return(S_OK);
  617. }
  618. HRESULT
  619. CHsmJobDef::SetUseDbIndex(
  620. IN BOOL useIndex
  621. )
  622. /*++
  623. Implements:
  624. IHsmJobDef::SetUseRPIndex().
  625. --*/
  626. {
  627. m_useDbIndex = useIndex;
  628. return(S_OK);
  629. }
  630. HRESULT
  631. CHsmJobDef::Test(
  632. USHORT* passed,
  633. USHORT* failed
  634. )
  635. /*++
  636. Implements:
  637. IWsbTestable::Test().
  638. --*/
  639. {
  640. HRESULT hr = S_OK;
  641. try {
  642. WsbAssert(0 != passed, E_POINTER);
  643. WsbAssert(0 != failed, E_POINTER);
  644. *passed = 0;
  645. *failed = 0;
  646. } WsbCatch(hr);
  647. return(hr);
  648. }
  649. HRESULT
  650. CHsmJobDef::UseRPIndex(
  651. void
  652. )
  653. /*++
  654. Implements:
  655. IHsmJobDef::UseRPIndex().
  656. --*/
  657. {
  658. return(m_useRPIndex ? S_OK : S_FALSE);
  659. }
  660. HRESULT
  661. CHsmJobDef::UseDbIndex(
  662. void
  663. )
  664. /*++
  665. Implements:
  666. IHsmJobDef::UseDbIndex().
  667. --*/
  668. {
  669. return(m_useDbIndex ? S_OK : S_FALSE);
  670. }