Leaked source code of windows server 2003
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.

736 lines
14 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. hsmworki.cpp
  5. Abstract:
  6. This class represents an HSM work item - a unit of work
  7. that is performed by the HSM engine
  8. Author:
  9. Cat Brant [cbrant] 5-May-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #define WSB_TRACE_IS WSB_TRACE_BIT_HSMTSKMGR
  14. #include "wsb.h"
  15. #include "fsa.h"
  16. #include "task.h"
  17. #include "hsmworki.h"
  18. static USHORT iCount = 0;
  19. HRESULT
  20. CHsmWorkItem::CompareTo(
  21. IN IUnknown* pUnknown,
  22. OUT SHORT* pResult
  23. )
  24. /*++
  25. Implements:
  26. IWsbCollectable::CompareTo().
  27. --*/
  28. {
  29. HRESULT hr = S_OK;
  30. CComPtr<IHsmWorkItem> pWorkItem;
  31. WsbTraceIn(OLESTR("CHsmWorkItem::CompareTo"), OLESTR(""));
  32. try {
  33. // Did they give us a valid item to compare to?
  34. WsbAssert(0 != pUnknown, E_POINTER);
  35. // We need the IHsmWorkItem interface to get the value of the object.
  36. WsbAffirmHr(pUnknown->QueryInterface(IID_IHsmWorkItem, (void**) &pWorkItem));
  37. // Compare the items
  38. hr = CompareToIHsmWorkItem(pWorkItem, pResult);
  39. } WsbCatch(hr);
  40. WsbTraceOut(OLESTR("CHsmWorkItem::CompareTo"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  41. return(hr);
  42. }
  43. HRESULT
  44. CHsmWorkItem::CompareToIHsmWorkItem(
  45. IN IHsmWorkItem* pWorkItem,
  46. OUT SHORT* pResult
  47. )
  48. /*++
  49. Implements:
  50. IHsmWorkItem::CompareToIHsmWorkItem().
  51. --*/
  52. {
  53. HRESULT hr = S_OK;
  54. GUID l_Id; // Type of work to do
  55. WsbTraceIn(OLESTR("CHsmWorkItem::CompareToIHsmWorkItem"), OLESTR(""));
  56. try {
  57. //
  58. // Did they give us a valid item to compare to?
  59. //
  60. WsbAssert(0 != pWorkItem, E_POINTER);
  61. //
  62. // Get the ID
  63. //
  64. WsbAffirmHr(pWorkItem->GetId(&l_Id));
  65. if (l_Id != m_MyId){
  66. hr = S_FALSE;
  67. }
  68. // If they asked for the relative value back, then return it to them.
  69. if (pResult != NULL) {
  70. if (S_OK == hr) {
  71. *pResult = 0;
  72. } else {
  73. *pResult = 1;
  74. }
  75. }
  76. } WsbCatch(hr);
  77. WsbTraceOut(OLESTR("CHsmWorkItem::CompareToIHsmWorkItem"), OLESTR("hr = <%ls>, result = <%ls>"), WsbHrAsString(hr), WsbPtrToShortAsString(pResult));
  78. return(hr);
  79. }
  80. HRESULT
  81. CHsmWorkItem::FinalConstruct(
  82. void
  83. )
  84. /*++
  85. Implements:
  86. CComObjectRoot::FinalConstruct().
  87. --*/
  88. {
  89. HRESULT hr = S_OK;
  90. WsbTraceIn(OLESTR("CHsmWorkItem::FinalConstruct"), OLESTR(""));
  91. try {
  92. WsbAffirmHr(CWsbObject::FinalConstruct());
  93. //
  94. // The comparison for database searches is based on the
  95. // ID of this object (m_MyId).
  96. //
  97. WsbAffirmHr(CoCreateGuid(&m_MyId));
  98. m_WorkType = HSM_WORK_ITEM_NONE;
  99. m_MediaId = GUID_NULL;
  100. m_MediaLastUpdate = WsbLLtoFT(0);
  101. m_MediaLastError = S_OK;
  102. m_MediaRecallOnly = FALSE;
  103. m_MediaFreeBytes = 0;
  104. } WsbCatch(hr);
  105. iCount++;
  106. WsbTraceOut(OLESTR("CHsmWorkItem::FinalConstruct"), OLESTR("hr = <%ls>, Count is <%d>"),
  107. WsbHrAsString(hr), iCount);
  108. return(hr);
  109. }
  110. void
  111. CHsmWorkItem::FinalRelease(
  112. void
  113. )
  114. /*++
  115. Implements:
  116. CComObjectRoot::FinalRelease().
  117. --*/
  118. {
  119. WsbTraceIn(OLESTR("CHsmWorkItem::FinalRelease"), OLESTR(""));
  120. // Let the parent class do his thing.
  121. CWsbObject::FinalRelease();
  122. iCount--;
  123. WsbTraceOut(OLESTR("CHsmWorkItem::FinalRelease"), OLESTR("Count is <%d>"), iCount);
  124. }
  125. HRESULT
  126. CHsmWorkItem::GetFsaPostIt (
  127. OUT IFsaPostIt **ppFsaPostIt
  128. )
  129. /*++
  130. Implements:
  131. IHsmWorkItem::GetFsaPostIt
  132. --*/
  133. {
  134. HRESULT hr = S_OK;
  135. WsbTraceIn(OLESTR("CHsmWorkItem::GetFsaPostIt"), OLESTR(""));
  136. try {
  137. // Did they give us a valid pointer?
  138. WsbAssert(0 != ppFsaPostIt, E_POINTER);
  139. *ppFsaPostIt = m_pFsaPostIt;
  140. if (0 != *ppFsaPostIt) {
  141. (*ppFsaPostIt)->AddRef();
  142. }
  143. } WsbCatch(hr);
  144. WsbTraceOut(OLESTR("CHsmWorkItem::GetFsaPostIt"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  145. return(hr);
  146. }
  147. HRESULT
  148. CHsmWorkItem::GetFsaResource (
  149. OUT IFsaResource **ppFsaResource
  150. )
  151. /*++
  152. Implements:
  153. IHsmWorkItem::GetFsaResource
  154. --*/
  155. {
  156. HRESULT hr = S_OK;
  157. WsbTraceIn(OLESTR("CHsmWorkItem::GetFsaResource"), OLESTR(""));
  158. try {
  159. // Did they give us a valid pointer?
  160. WsbAssert(0 != ppFsaResource, E_POINTER);
  161. *ppFsaResource = m_pFsaResource;
  162. if (0 != *ppFsaResource) {
  163. (*ppFsaResource)->AddRef();
  164. }
  165. } WsbCatch(hr);
  166. WsbTraceOut(OLESTR("CHsmWorkItem::GetFsaResource"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  167. return(hr);
  168. }
  169. HRESULT
  170. CHsmWorkItem::GetId(
  171. OUT GUID *pId
  172. )
  173. /*++
  174. Implements:
  175. IHsmWorkItem::GetId().
  176. --*/
  177. {
  178. HRESULT hr = S_OK;
  179. WsbTraceIn(OLESTR("CHsmWorkItem::GetId"), OLESTR(""));
  180. try {
  181. // Did they give us a valid pointer?
  182. WsbAssert(0 != pId, E_POINTER);
  183. *pId = m_MyId;
  184. } WsbCatch(hr);
  185. WsbTraceOut(OLESTR("CHsmWorkItem::GetId"), OLESTR("hr = <%ls>, Id = <%ls>"),
  186. WsbHrAsString(hr), WsbPtrToGuidAsString(pId));
  187. return(hr);
  188. }
  189. HRESULT
  190. CHsmWorkItem::GetMediaInfo (
  191. OUT GUID *pMediaId,
  192. OUT FILETIME *pMediaLastUpdate,
  193. OUT HRESULT *pMediaLastError,
  194. OUT BOOL *pMediaRecallOnly,
  195. OUT LONGLONG *pMediaFreeBytes,
  196. OUT short *pMediaRemoteDataSet
  197. )
  198. /*++
  199. Implements:
  200. IHsmWorkItem::GetMediaInfo
  201. --*/
  202. {
  203. HRESULT hr = S_OK;
  204. WsbTraceIn(OLESTR("CHsmWorkItem::GetMediaInfo"), OLESTR(""));
  205. try {
  206. // Did they give us valid pointers?
  207. WsbAssert(0 != pMediaId, E_POINTER);
  208. WsbAssert(0 != pMediaLastUpdate, E_POINTER);
  209. WsbAssert(0 != pMediaLastError, E_POINTER);
  210. WsbAssert(0 != pMediaRecallOnly, E_POINTER);
  211. WsbAssert(0 != pMediaFreeBytes, E_POINTER);
  212. WsbAssert(0 != pMediaRemoteDataSet, E_POINTER);
  213. *pMediaId = m_MediaId;
  214. *pMediaLastUpdate = m_MediaLastUpdate;
  215. *pMediaLastError = m_MediaLastError;
  216. *pMediaRecallOnly = m_MediaRecallOnly;
  217. *pMediaFreeBytes = m_MediaFreeBytes;
  218. *pMediaRemoteDataSet = m_MediaRemoteDataSet;
  219. } WsbCatch(hr);
  220. WsbTraceOut(OLESTR("CHsmWorkItem::GetMediaInfo"),
  221. OLESTR("hr = <%ls>, Id = <%ls>, LastUpdate = <%ls>, LastError = <%ls>, Recall Only = <%ls>, Free Bytes = <%ls>, RemoteDataSet = <%ls>"),
  222. WsbHrAsString(hr), WsbPtrToGuidAsString(pMediaId), WsbPtrToFiletimeAsString(FALSE, pMediaLastUpdate),
  223. WsbPtrToHrAsString(pMediaLastError), WsbPtrToBoolAsString(pMediaRecallOnly),
  224. WsbPtrToLonglongAsString(pMediaFreeBytes), WsbPtrToShortAsString(pMediaRemoteDataSet));
  225. return(hr);
  226. }
  227. HRESULT
  228. CHsmWorkItem::GetResult(
  229. OUT HRESULT *pHr
  230. )
  231. /*++
  232. Implements:
  233. IHsmWorkItem::GetResult().
  234. --*/
  235. {
  236. HRESULT hr = S_OK;
  237. WsbTraceIn(OLESTR("CHsmWorkItem::GetResult"), OLESTR(""));
  238. try {
  239. // Did they give us a valid pointer?
  240. WsbAssert(0 != pHr, E_POINTER);
  241. *pHr = m_WorkResult;
  242. } WsbCatch(hr);
  243. WsbTraceOut(OLESTR("CHsmWorkItem::GetResult"), OLESTR("hr = <%ls>, Result = <%ls>"),
  244. WsbHrAsString(hr), WsbPtrToHrAsString(pHr));
  245. return(hr);
  246. }
  247. HRESULT
  248. CHsmWorkItem::GetWorkType(
  249. OUT HSM_WORK_ITEM_TYPE *pWorkType
  250. )
  251. /*++
  252. Implements:
  253. IHsmWorkItem::GetWorkType().
  254. --*/
  255. {
  256. HRESULT hr = S_OK;
  257. WsbTraceIn(OLESTR("CHsmWorkItem::GetWorkType"), OLESTR(""));
  258. try {
  259. // Did they give us a valid pointer?
  260. WsbAssert(0 != pWorkType, E_POINTER);
  261. *pWorkType = m_WorkType;
  262. } WsbCatch(hr);
  263. WsbTraceOut(OLESTR("CHsmWorkItem::GetWorkType"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  264. return(hr);
  265. }
  266. HRESULT
  267. CHsmWorkItem::SetFsaPostIt (
  268. IN IFsaPostIt *pFsaPostIt
  269. )
  270. /*++
  271. Implements:
  272. IHsmWorkItem::SetFsaPostIt
  273. --*/
  274. {
  275. HRESULT hr = S_OK;
  276. WsbTraceIn(OLESTR("CHsmWorkItem::SetFsaPostIt"), OLESTR(""));
  277. try {
  278. // Did they give us a valid pointer?
  279. WsbAssert(0 != pFsaPostIt, E_POINTER);
  280. m_pFsaPostIt = pFsaPostIt;
  281. } WsbCatch(hr);
  282. WsbTraceOut(OLESTR("CHsmWorkItem::SetFsaPostIt"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  283. return(hr);
  284. }
  285. HRESULT
  286. CHsmWorkItem::SetFsaResource (
  287. IN IFsaResource *pFsaResource
  288. )
  289. /*++
  290. Implements:
  291. IHsmWorkItem::SetFsaResource
  292. --*/
  293. {
  294. HRESULT hr = S_OK;
  295. WsbTraceIn(OLESTR("CHsmWorkItem::SetFsaResource"), OLESTR(""));
  296. try {
  297. // Did they give us a valid pointer?
  298. WsbAssert(0 != pFsaResource, E_POINTER);
  299. m_pFsaResource = pFsaResource;
  300. } WsbCatch(hr);
  301. WsbTraceOut(OLESTR("CHsmWorkItem::SetFsaResource"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  302. return(hr);
  303. }
  304. HRESULT
  305. CHsmWorkItem::SetMediaInfo (
  306. IN GUID mediaId,
  307. IN FILETIME mediaLastUpdate,
  308. IN HRESULT mediaLastError,
  309. IN BOOL mediaRecallOnly,
  310. IN LONGLONG mediaFreeBytes,
  311. IN short mediaRemoteDataSet
  312. )
  313. /*++
  314. Implements:
  315. IHsmWorkItem::SetMediaInfo
  316. --*/
  317. {
  318. HRESULT hr = S_OK;
  319. WsbTraceIn(OLESTR("CHsmWorkItem::SetMediaInfo"),
  320. OLESTR("Id = <%ls>, LastUpdate = <%ls>, LastError = <%ls>, Recall Only = <%ls>, Free Bytes = <%ls>, RemoteDataSet = <%d>"),
  321. WsbGuidAsString(mediaId), WsbFiletimeAsString(FALSE, mediaLastUpdate),
  322. WsbHrAsString(mediaLastError), WsbBoolAsString(mediaRecallOnly),
  323. WsbLonglongAsString(mediaFreeBytes), mediaRemoteDataSet);
  324. try {
  325. m_MediaId = mediaId;
  326. m_MediaLastUpdate = mediaLastUpdate;
  327. m_MediaLastError = mediaLastError;
  328. m_MediaRecallOnly = mediaRecallOnly;
  329. m_MediaFreeBytes = mediaFreeBytes;
  330. m_MediaRemoteDataSet = mediaRemoteDataSet;
  331. } WsbCatch(hr);
  332. WsbTraceOut(OLESTR("CHsmWorkItem::GetMediaInfo"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  333. return(hr);
  334. }
  335. HRESULT
  336. CHsmWorkItem::SetResult(
  337. IN HRESULT workResult
  338. )
  339. /*++
  340. Implements:
  341. IHsmWorkItem::GetResult().
  342. --*/
  343. {
  344. HRESULT hr = S_OK;
  345. WsbTraceIn(OLESTR("CHsmWorkItem::SetResult"), OLESTR("Result is <%ls>"), WsbHrAsString(workResult));
  346. try {
  347. m_WorkResult = workResult;
  348. } WsbCatch(hr);
  349. WsbTraceOut(OLESTR("CHsmWorkItem::GetResult"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  350. return(hr);
  351. }
  352. HRESULT
  353. CHsmWorkItem::SetWorkType(
  354. IN HSM_WORK_ITEM_TYPE workType
  355. )
  356. /*++
  357. Implements:
  358. IHsmWorkItem::SetWorkType().
  359. --*/
  360. {
  361. HRESULT hr = S_OK;
  362. WsbTraceIn(OLESTR("CHsmWorkItem::SetWorkType"), OLESTR(""));
  363. m_WorkType = workType;
  364. WsbTraceOut(OLESTR("CHsmWorkItem::SetWorkType"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  365. return(hr);
  366. }
  367. HRESULT CHsmWorkItem::GetClassID
  368. (
  369. OUT LPCLSID pclsid
  370. )
  371. /*++
  372. Routine Description:
  373. See IPerist::GetClassID()
  374. Arguments:
  375. See IPerist::GetClassID()
  376. Return Value:
  377. See IPerist::GetClassID()
  378. --*/
  379. {
  380. HRESULT hr = S_OK;
  381. WsbTraceIn(OLESTR("CHsmWorkItem::GetClassID"), OLESTR(""));
  382. try {
  383. WsbAssert(0 != pclsid, E_POINTER);
  384. *pclsid = CLSID_CHsmWorkItem;
  385. } WsbCatch(hr);
  386. WsbTraceOut(OLESTR("CHsmWorkItem::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pclsid));
  387. return(hr);
  388. }
  389. HRESULT CHsmWorkItem::GetSizeMax
  390. (
  391. OUT ULARGE_INTEGER* pcbSize
  392. )
  393. /*++
  394. Routine Description:
  395. See IPersistStream::GetSizeMax().
  396. Arguments:
  397. See IPersistStream::GetSizeMax().
  398. Return Value:
  399. See IPersistStream::GetSizeMax().
  400. --*/
  401. {
  402. HRESULT hr = S_OK;
  403. WsbTraceIn(OLESTR("CHsmWorkItem::GetSizeMax"), OLESTR(""));
  404. try {
  405. WsbAssert(0 != pcbSize, E_POINTER);
  406. pcbSize->QuadPart = 0;
  407. hr = E_NOTIMPL;
  408. } WsbCatch(hr);
  409. WsbTraceOut(OLESTR("CHsmWorkItem::GetSizeMax"),
  410. OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr),
  411. WsbPtrToUliAsString(pcbSize));
  412. return(hr);
  413. }
  414. HRESULT CHsmWorkItem::Load
  415. (
  416. IN IStream* /*pStream*/
  417. )
  418. /*++
  419. Routine Description:
  420. See IPersistStream::Load().
  421. Arguments:
  422. See IPersistStream::Load().
  423. Return Value:
  424. See IPersistStream::Load().
  425. --*/
  426. {
  427. HRESULT hr = S_OK;
  428. WsbTraceIn(OLESTR("CHsmWorkItem::Load"), OLESTR(""));
  429. try {
  430. hr = E_NOTIMPL;
  431. } WsbCatch(hr);
  432. WsbTraceOut(OLESTR("CHsmWorkItem::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  433. return(hr);
  434. }
  435. HRESULT CHsmWorkItem::Save
  436. (
  437. IN IStream* pStream,
  438. IN BOOL clearDirty
  439. )
  440. /*++
  441. Routine Description:
  442. See IPersistStream::Save().
  443. Arguments:
  444. See IPersistStream::Save().
  445. Return Value:
  446. See IPersistStream::Save().
  447. --*/
  448. {
  449. HRESULT hr = S_OK;
  450. WsbTraceIn(OLESTR("CHsmWorkItem::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  451. try {
  452. WsbAssert(0 != pStream, E_POINTER);
  453. hr = E_NOTIMPL;
  454. // If we got it saved and we were asked to clear the dirty bit, then
  455. // do so now.
  456. if (clearDirty) {
  457. m_isDirty = FALSE;
  458. }
  459. } WsbCatch(hr);
  460. WsbTraceOut(OLESTR("CHsmWorkItem::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  461. return(hr);
  462. }
  463. HRESULT
  464. CHsmWorkItem::Test
  465. (
  466. OUT USHORT *pTestsPassed,
  467. OUT USHORT *pTestsFailed
  468. )
  469. /*++
  470. Routine Description:
  471. See IWsbTestable::Test().
  472. Arguments:
  473. See IWsbTestable::Test().
  474. Return Value:
  475. See IWsbTestable::Test().
  476. --*/
  477. {
  478. HRESULT hr = S_OK;
  479. WsbTraceIn(OLESTR("CHsmWorkItem::Test"), OLESTR(""));
  480. *pTestsPassed = *pTestsFailed = 0;
  481. try {
  482. hr = E_NOTIMPL;
  483. } WsbCatch(hr);
  484. WsbTraceOut(OLESTR("CHsmWorkItem::Test"), OLESTR("hr = <%ls>"),WsbHrAsString(hr));
  485. return( hr );
  486. }