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.

266 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxJobsCollection.h
  5. Abstract:
  6. Implementation of Copy Policy Classes and Job Collection Class.
  7. Author:
  8. Iv Garber (IvG) May, 2000
  9. Revision History:
  10. --*/
  11. #ifndef __FAXJOBSCOLLECTION_H_
  12. #define __FAXJOBSCOLLECTION_H_
  13. #include "VCUE_Copy.h"
  14. //
  15. //================= FAX JOB COLLECTION TEMPLATE ================================
  16. //
  17. template <class CollectionIfc, class ContainerType, class CollectionExposedType, class CollectionCopyType,
  18. class EnumType, class JobClass, const IID* piid, const CLSID* pcid>
  19. class JobCollection : public ICollectionOnSTLImpl<CollectionIfc, ContainerType, CollectionExposedType*,
  20. CollectionCopyType, EnumType>
  21. {
  22. public :
  23. JobCollection()
  24. {
  25. DBG_ENTER(_T("JOB COLLECTION :: CREATE"));
  26. }
  27. ~JobCollection()
  28. {
  29. DBG_ENTER(_T("JOB COLLECTION :: DESTROY"));
  30. CCollectionKiller<ContainerType> CKiller;
  31. CKiller.EmptyObjectCollection(&m_coll);
  32. }
  33. // Interfaces
  34. STDMETHOD(get_Item)(/*[in]*/ VARIANT vIndex, /*[out, retval]*/ CollectionExposedType **pFaxJob);
  35. // Internal Use
  36. HRESULT Init(FAX_JOB_ENTRY_EX* pJobs, DWORD dwJobCount, IFaxServerInner *pFaxServerInner);
  37. };
  38. //
  39. //============================= GET ITEM =========================================
  40. //
  41. template <class CollectionIfc, class ContainerType, class CollectionExposedType,
  42. class CollectionCopyType, class EnumType, class JobClass, const IID* piid,
  43. const CLSID* pcid>
  44. STDMETHODIMP
  45. JobCollection<CollectionIfc, ContainerType, CollectionExposedType, CollectionCopyType, EnumType, JobClass,
  46. piid, pcid>::get_Item(
  47. /*[in]*/ VARIANT vIndex,
  48. /*[out, retval]*/ CollectionExposedType **pFaxJob
  49. )
  50. /*++
  51. Routine name : JobCollection::get_Item
  52. Routine description:
  53. Return Item Job from the Collection.
  54. Author:
  55. Iv Garber (IvG), May, 2000
  56. Arguments:
  57. vIndex [in] - Index of the Job to find
  58. pFaxJob [out] - the resulting Job Object
  59. Return Value:
  60. Standard HRESULT code
  61. --*/
  62. {
  63. HRESULT hr = S_OK;
  64. DBG_ENTER(_T("JobCollection::get_Item"), hr);
  65. if (::IsBadWritePtr(pFaxJob, sizeof(CollectionExposedType *)))
  66. {
  67. //
  68. // Invalid Argument
  69. //
  70. hr = E_POINTER;
  71. AtlReportError(*pcid, IDS_ERROR_INVALID_ARGUMENT, *piid, hr);
  72. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr(pFaxJob)"), hr);
  73. return hr;
  74. }
  75. CComVariant var;
  76. if (vIndex.vt != VT_BSTR)
  77. {
  78. //
  79. // vIndex is not BSTR ==> convert to VT_I4
  80. //
  81. hr = var.ChangeType(VT_I4, &vIndex);
  82. if (SUCCEEDED(hr))
  83. {
  84. VERBOSE(DBG_MSG, _T("Parameter is Number : %d"), var.lVal);
  85. //
  86. // call default ATL's implementation
  87. //
  88. hr = ICollectionOnSTLImpl<CollectionIfc, ContainerType, CollectionExposedType*,
  89. CollectionCopyType, EnumType>::get_Item(var.lVal, pFaxJob);
  90. return hr;
  91. }
  92. }
  93. //
  94. // convert to BSTR
  95. //
  96. hr = var.ChangeType(VT_BSTR, &vIndex);
  97. if (FAILED(hr))
  98. {
  99. //
  100. // Got wrong vIndex
  101. //
  102. hr = E_INVALIDARG;
  103. AtlReportError(*pcid, IDS_ERROR_INVALIDINDEX, *piid, hr);
  104. CALL_FAIL(GENERAL_ERR, _T("var.ChangeType(VT_BSTR, &vIndex)"), hr);
  105. return hr;
  106. }
  107. VERBOSE(DBG_MSG, _T("Parameter is String : %s"), var.bstrVal);
  108. ContainerType::iterator it = m_coll.begin();
  109. while (it != m_coll.end())
  110. {
  111. CComBSTR bstrMsgId;
  112. hr = (*it)->get_Id(&bstrMsgId);
  113. if (FAILED(hr))
  114. {
  115. CALL_FAIL(GENERAL_ERR, _T("it->get_Id(&dwlMsgid)"), hr);
  116. AtlReportError(*pcid, GetErrorMsgId(hr), *piid, hr);
  117. return hr;
  118. }
  119. if (_tcsicmp(bstrMsgId, var.bstrVal) == 0)
  120. {
  121. //
  122. // found the desired Job
  123. //
  124. (*it)->AddRef();
  125. *pFaxJob = *it;
  126. return hr;
  127. }
  128. it++;
  129. }
  130. //
  131. // Job not found
  132. //
  133. hr = E_INVALIDARG;
  134. CALL_FAIL(GENERAL_ERR, _T("Job Not Found"), hr);
  135. AtlReportError(*pcid, IDS_ERROR_INVALIDMSGID, *piid, hr);
  136. return hr;
  137. }
  138. //
  139. //============================= INIT =========================================
  140. //
  141. template <class CollectionIfc, class ContainerType, class CollectionExposedType, class CollectionCopyType,
  142. class EnumType, class JobType, const IID* piid, const CLSID* pcid>
  143. HRESULT
  144. JobCollection<CollectionIfc, ContainerType, CollectionExposedType, CollectionCopyType, EnumType,
  145. JobType, piid, pcid>::Init(
  146. /*[in]*/ FAX_JOB_ENTRY_EX *pJobs,
  147. /*[in]*/ DWORD dwJobCount,
  148. /*[in]*/ IFaxServerInner *pFaxServerInner
  149. )
  150. /*++
  151. Routine name : JobCollection::Init
  152. Routine description:
  153. Fill the collection with pointers to structures
  154. Author:
  155. Iv Garber (IvG), May, 2000
  156. Arguments:
  157. pJobs [in] - ptr to array of structs
  158. dwJobCount [in] - num of structs in the array
  159. pFaxServerInner [in] - ptr to Fax Server object
  160. Return Value:
  161. Standard HRESULT code
  162. --*/
  163. {
  164. HRESULT hr = S_OK;
  165. DBG_ENTER(_T("JobCollection::Init"), hr);
  166. //
  167. // Fill collection with data :
  168. // create object for each element in structure
  169. //
  170. for ( long i = 0 ; i < dwJobCount ; i++ )
  171. {
  172. //
  173. // Create Job Object
  174. //
  175. CComPtr<CollectionExposedType> pNewJobObject;
  176. hr = JobType::Create(&pNewJobObject);
  177. if (FAILED(hr))
  178. {
  179. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  180. CALL_FAIL(GENERAL_ERR, _T("JobType::Create(&pNewJobObject)"), hr);
  181. return hr;
  182. }
  183. //
  184. // Initialize the Job Object
  185. //
  186. hr = ((JobType *)((CollectionExposedType *)pNewJobObject))->Init(&pJobs[i], pFaxServerInner);
  187. if (FAILED(hr))
  188. {
  189. AtlReportError(*pcid, IDS_ERROR_OPERATION_FAILED, *piid, hr);
  190. CALL_FAIL(GENERAL_ERR, _T("pNewJobObject->Init()"), hr);
  191. return hr;
  192. }
  193. //
  194. // Put the Object in the collection
  195. //
  196. try
  197. {
  198. m_coll.push_back(pNewJobObject);
  199. }
  200. catch (exception &)
  201. {
  202. //
  203. // Failed to put ptr to the new Job Object in the vector
  204. //
  205. hr = E_OUTOFMEMORY;
  206. AtlReportError(*pcid, IDS_ERROR_OUTOFMEMORY, *piid, hr);
  207. CALL_FAIL(MEM_ERR, _T("m_coll.push_back(pNewJobObject.Detach())"), hr);
  208. return hr;
  209. }
  210. pNewJobObject.Detach();
  211. }
  212. return hr;
  213. }
  214. #endif // __FAXJOBSCOLLECTION_H_