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.

546 lines
14 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // refresher.h
  6. //
  7. // alanbos 02-Feb-00 Created.
  8. //
  9. // Refresher helper implementation.
  10. //
  11. //***************************************************************************
  12. #ifndef _REFRESHER_H_
  13. #define _REFRESHER_H_
  14. //***************************************************************************
  15. //
  16. // CLASS NAME:
  17. //
  18. // CSWbemRefreshableItem
  19. //
  20. // DESCRIPTION:
  21. //
  22. // Implements the ISWbemRefreshableItem interface.
  23. //
  24. //***************************************************************************
  25. class CSWbemRefreshableItem : public ISWbemRefreshableItem,
  26. public ISupportErrorInfo,
  27. public IProvideClassInfo
  28. {
  29. private:
  30. CDispatchHelp m_Dispatch;
  31. ISWbemRefresher *m_pISWbemRefresher;
  32. long m_iIndex;
  33. VARIANT_BOOL m_bIsSet;
  34. ISWbemObjectEx *m_pISWbemObjectEx;
  35. ISWbemObjectSet *m_pISWbemObjectSet;
  36. protected:
  37. long m_cRef; //Object reference count
  38. public:
  39. CSWbemRefreshableItem(ISWbemRefresher *pRefresher, long iIndex,
  40. IDispatch *pServices,
  41. IWbemClassObject *pObject,
  42. IWbemHiPerfEnum *pObjectSet);
  43. virtual ~CSWbemRefreshableItem(void);
  44. //Non-delegating object IUnknown
  45. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  46. STDMETHODIMP_(ULONG) AddRef(void);
  47. STDMETHODIMP_(ULONG) Release(void);
  48. // IDispatch
  49. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
  50. {return m_Dispatch.GetTypeInfoCount(pctinfo);}
  51. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  52. {return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  53. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  54. UINT cNames, LCID lcid, DISPID* rgdispid)
  55. {return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  56. lcid,
  57. rgdispid);}
  58. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  59. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  60. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  61. {return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  62. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  63. // ISWbemRefreshableItem methods
  64. HRESULT STDMETHODCALLTYPE get_Index (
  65. /*[out, retval]*/ long *iIndex
  66. )
  67. {
  68. ResetLastErrors ();
  69. *iIndex = m_iIndex;
  70. return WBEM_S_NO_ERROR;
  71. }
  72. HRESULT STDMETHODCALLTYPE get_Refresher (
  73. /*[out, retval]*/ ISWbemRefresher **objWbemRefresher
  74. )
  75. {
  76. ResetLastErrors ();
  77. *objWbemRefresher = m_pISWbemRefresher;
  78. if (m_pISWbemRefresher)
  79. m_pISWbemRefresher->AddRef();
  80. return WBEM_S_NO_ERROR;
  81. }
  82. HRESULT STDMETHODCALLTYPE get_IsSet (
  83. /*[out, retval]*/ VARIANT_BOOL *bIsSet
  84. )
  85. {
  86. ResetLastErrors ();
  87. *bIsSet = m_bIsSet;
  88. return WBEM_S_NO_ERROR;
  89. }
  90. HRESULT STDMETHODCALLTYPE get_Object (
  91. /*[out, retval]*/ ISWbemObjectEx **objWbemObject
  92. )
  93. {
  94. ResetLastErrors ();
  95. *objWbemObject = m_pISWbemObjectEx;
  96. if (*objWbemObject)
  97. (*objWbemObject)->AddRef ();
  98. return WBEM_S_NO_ERROR;
  99. }
  100. HRESULT STDMETHODCALLTYPE get_ObjectSet (
  101. /*[out, retval]*/ ISWbemObjectSet **objWbemObjectSet
  102. )
  103. {
  104. ResetLastErrors ();
  105. *objWbemObjectSet = m_pISWbemObjectSet;
  106. if (*objWbemObjectSet)
  107. (*objWbemObjectSet)->AddRef ();
  108. return WBEM_S_NO_ERROR;
  109. }
  110. HRESULT STDMETHODCALLTYPE Remove (
  111. /*[in, optional, defaultvalue(0)]*/ long iFlags
  112. )
  113. {
  114. HRESULT hr = WBEM_E_FAILED;
  115. ResetLastErrors ();
  116. if (m_pISWbemRefresher)
  117. hr = m_pISWbemRefresher->Remove (m_iIndex, 0);
  118. if (FAILED(hr))
  119. m_Dispatch.RaiseException (hr);
  120. return hr;
  121. }
  122. // ISupportErrorInfo methods
  123. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  124. (
  125. /* [in] */ REFIID riid
  126. )
  127. {
  128. return (IID_ISWbemRefreshableItem == riid) ? S_OK : S_FALSE;
  129. }
  130. // IProvideClassInfo methods
  131. HRESULT STDMETHODCALLTYPE GetClassInfo
  132. (
  133. /* [in] */ ITypeInfo **ppTI
  134. )
  135. {
  136. return m_Dispatch.GetClassInfo (ppTI);
  137. }
  138. // Other methods
  139. void UnhookRefresher ()
  140. {
  141. if (m_pISWbemRefresher)
  142. m_pISWbemRefresher = NULL;
  143. }
  144. };
  145. typedef map<long, CSWbemRefreshableItem*, less<long>, CWbemAllocator<CSWbemRefreshableItem*> > RefreshableItemMap;
  146. //***************************************************************************
  147. //
  148. // CLASS NAME:
  149. //
  150. // CSWbemRefresher
  151. //
  152. // DESCRIPTION:
  153. //
  154. // Implements the ISWbemRefresher interface.
  155. //
  156. //***************************************************************************
  157. class CEnumRefresher;
  158. class CSWbemRefresher : public ISWbemRefresher,
  159. public IObjectSafety,
  160. public ISupportErrorInfo,
  161. public IProvideClassInfo
  162. {
  163. friend CEnumRefresher;
  164. private:
  165. CDispatchHelp m_Dispatch;
  166. long m_iCount;
  167. VARIANT_BOOL m_bAutoReconnect;
  168. IWbemConfigureRefresher *m_pIWbemConfigureRefresher;
  169. IWbemRefresher *m_pIWbemRefresher;
  170. RefreshableItemMap m_ObjectMap;
  171. void CreateRefresher ();
  172. void EraseItem (RefreshableItemMap::iterator iterator);
  173. protected:
  174. long m_cRef; //Object reference count
  175. public:
  176. CSWbemRefresher(void);
  177. virtual ~CSWbemRefresher(void);
  178. //Non-delegating object IUnknown
  179. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  180. STDMETHODIMP_(ULONG) AddRef(void);
  181. STDMETHODIMP_(ULONG) Release(void);
  182. // IDispatch
  183. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
  184. {return m_Dispatch.GetTypeInfoCount(pctinfo);}
  185. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  186. {return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  187. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  188. UINT cNames, LCID lcid, DISPID* rgdispid)
  189. {return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  190. lcid,
  191. rgdispid);}
  192. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  193. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  194. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  195. {return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  196. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  197. // ISWbemRefresher methods
  198. HRESULT STDMETHODCALLTYPE get__NewEnum (
  199. /*[out, retval]*/ IUnknown **pUnk
  200. );
  201. HRESULT STDMETHODCALLTYPE Item (
  202. /*[in]*/ long iIndex,
  203. /*[out, retval]*/ ISWbemRefreshableItem **objWbemRefreshableItem
  204. );
  205. HRESULT STDMETHODCALLTYPE get_Count (
  206. /*[out, retval]*/ long *iCount
  207. );
  208. HRESULT STDMETHODCALLTYPE Add (
  209. /*[in]*/ ISWbemServicesEx *objWbemServices,
  210. /*[in]*/ BSTR bsInstancePath,
  211. /*[in, optional, defaultvalue(0)]*/ long iFlags,
  212. /*[in, optional, defaultvalue(0)]*/ /*ISWbemNamedValueSet*/ IDispatch *objWbemNamedValueSet,
  213. /*[out, retval]*/ ISWbemRefreshableItem **objWbemRefreshableItem
  214. );
  215. HRESULT STDMETHODCALLTYPE AddEnum (
  216. /*[in]*/ ISWbemServicesEx *objWbemServices,
  217. /*[in]*/ BSTR bsClassName,
  218. /*[in, optional, defaultvalue(0)]*/ long iFlags,
  219. /*[in, optional, defaultvalue(0)]*/ /*ISWbemNamedValueSet*/ IDispatch *objWbemNamedValueSet,
  220. /*[out, retval]*/ ISWbemRefreshableItem **objWbemRefreshableItem
  221. );
  222. HRESULT STDMETHODCALLTYPE Remove (
  223. /*[in]*/ long iIndex,
  224. /*[in, optional, defaultvalue(0)]*/ long iFlags
  225. );
  226. HRESULT STDMETHODCALLTYPE Refresh (
  227. /*[in, optional, defaultvalue(0)]*/ long iFlags
  228. );
  229. HRESULT STDMETHODCALLTYPE get_AutoReconnect (
  230. /*[out, retval]*/ VARIANT_BOOL *bAutoReconnect
  231. )
  232. {
  233. ResetLastErrors ();
  234. *bAutoReconnect = m_bAutoReconnect;
  235. return WBEM_S_NO_ERROR;
  236. }
  237. HRESULT STDMETHODCALLTYPE put_AutoReconnect (
  238. /*[in]*/ VARIANT_BOOL bAutoReconnect
  239. )
  240. {
  241. ResetLastErrors ();
  242. m_bAutoReconnect = bAutoReconnect;
  243. return WBEM_S_NO_ERROR;
  244. }
  245. HRESULT STDMETHODCALLTYPE DeleteAll (
  246. );
  247. // IObjectSafety methods
  248. HRESULT STDMETHODCALLTYPE SetInterfaceSafetyOptions
  249. (
  250. /* [in] */ REFIID riid,
  251. /* [in] */ DWORD dwOptionSetMask,
  252. /* [in] */ DWORD dwEnabledOptions
  253. )
  254. {
  255. return (dwOptionSetMask & dwEnabledOptions) ? E_FAIL : S_OK;
  256. }
  257. HRESULT STDMETHODCALLTYPE GetInterfaceSafetyOptions(
  258. /* [in] */ REFIID riid,
  259. /* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
  260. /* [out] */ DWORD __RPC_FAR *pdwEnabledOptions
  261. )
  262. {
  263. if (pdwSupportedOptions) *pdwSupportedOptions = 0;
  264. if (pdwEnabledOptions) *pdwEnabledOptions = 0;
  265. return S_OK;
  266. }
  267. // ISupportErrorInfo methods
  268. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  269. (
  270. /* [in] */ REFIID riid
  271. )
  272. {
  273. return (IID_ISWbemRefresher == riid) ? S_OK : S_FALSE;
  274. }
  275. // IProvideClassInfo methods
  276. HRESULT STDMETHODCALLTYPE GetClassInfo
  277. (
  278. /* [in] */ ITypeInfo **ppTI
  279. )
  280. {
  281. return m_Dispatch.GetClassInfo (ppTI);
  282. }
  283. };
  284. //***************************************************************************
  285. //
  286. // CLASS NAME:
  287. //
  288. // CEnumRefresher
  289. //
  290. // DESCRIPTION:
  291. //
  292. // Implements the IEnumVARIANT interface for ISWbemRefresher
  293. //
  294. //***************************************************************************
  295. class CEnumRefresher : public IEnumVARIANT
  296. {
  297. private:
  298. long m_cRef;
  299. CSWbemRefresher *m_pCSWbemRefresher;
  300. RefreshableItemMap::iterator m_Iterator;
  301. public:
  302. CEnumRefresher (CSWbemRefresher *pCSWbemRefresher);
  303. CEnumRefresher (CSWbemRefresher *pCSWbemRefresher,
  304. RefreshableItemMap::iterator iterator);
  305. virtual ~CEnumRefresher (void);
  306. // Non-delegating object IUnknown
  307. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  308. STDMETHODIMP_(ULONG) AddRef(void);
  309. STDMETHODIMP_(ULONG) Release(void);
  310. // IEnumVARIANT
  311. STDMETHODIMP Next(
  312. unsigned long celt,
  313. VARIANT FAR* rgvar,
  314. unsigned long FAR* pceltFetched
  315. );
  316. STDMETHODIMP Skip(
  317. unsigned long celt
  318. );
  319. STDMETHODIMP Reset();
  320. STDMETHODIMP Clone(
  321. IEnumVARIANT **ppenum
  322. );
  323. };
  324. //***************************************************************************
  325. //
  326. // CLASS NAME:
  327. //
  328. // CSWbemHiPerfObjectSet
  329. //
  330. // DESCRIPTION:
  331. //
  332. // Implements the ISWbemObjectSet interface for IWbemHiPerfEnum
  333. //
  334. //***************************************************************************
  335. class CSWbemHiPerfObjectSet : public ISWbemObjectSet,
  336. public ISupportErrorInfo,
  337. public IProvideClassInfo
  338. {
  339. private:
  340. CSWbemServices *m_pSWbemServices;
  341. CDispatchHelp m_Dispatch;
  342. CSWbemSecurity *m_SecurityInfo;
  343. IWbemHiPerfEnum *m_pIWbemHiPerfEnum;
  344. protected:
  345. long m_cRef; //Object reference count
  346. public:
  347. CSWbemHiPerfObjectSet(CSWbemServices *pService, IWbemHiPerfEnum *pIWbemHiPerfEnum);
  348. ~CSWbemHiPerfObjectSet(void);
  349. //Non-delegating object IUnknown
  350. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  351. STDMETHODIMP_(ULONG) AddRef(void);
  352. STDMETHODIMP_(ULONG) Release(void);
  353. // IDispatch
  354. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
  355. {return m_Dispatch.GetTypeInfoCount(pctinfo);}
  356. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  357. {return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  358. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  359. UINT cNames, LCID lcid, DISPID* rgdispid)
  360. {return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  361. lcid,
  362. rgdispid);}
  363. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  364. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  365. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  366. {return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  367. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  368. // Collection methods
  369. HRESULT STDMETHODCALLTYPE get__NewEnum
  370. (
  371. /*[out]*/ IUnknown **ppUnk
  372. );
  373. HRESULT STDMETHODCALLTYPE get_Count
  374. (
  375. /*[out]*/ long *plCount
  376. );
  377. HRESULT STDMETHODCALLTYPE Item
  378. (
  379. /*[in]*/ BSTR objectPath,
  380. /*[in]*/ long lFlags,
  381. /*[out]*/ ISWbemObject **ppObject
  382. );
  383. HRESULT STDMETHODCALLTYPE get_Security_
  384. (
  385. /* [in] */ ISWbemSecurity **ppSecurity
  386. );
  387. // ISupportErrorInfo methods
  388. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  389. (
  390. /* [in] */ REFIID riid
  391. )
  392. {
  393. return (IID_ISWbemObjectSet == riid) ? S_OK : S_FALSE;
  394. }
  395. // IProvideClassInfo methods
  396. HRESULT STDMETHODCALLTYPE GetClassInfo
  397. (
  398. /* [in] */ ITypeInfo **ppTI
  399. )
  400. {
  401. return m_Dispatch.GetClassInfo (ppTI);
  402. }
  403. // Other methods
  404. HRESULT ReadObjects (unsigned long & iCount , IWbemObjectAccess ***ppIWbemObjectAccess); // Bug Id 566345
  405. // Other methods
  406. CSWbemServices *GetSWbemServices ()
  407. {
  408. return m_pSWbemServices;
  409. }
  410. };
  411. //***************************************************************************
  412. //
  413. // CLASS NAME:
  414. //
  415. // CEnumVarHiPerf
  416. //
  417. // DESCRIPTION:
  418. //
  419. // Implements the IEnumVARIANT interface for IWbemHiPerfEnum
  420. //
  421. //***************************************************************************
  422. class CEnumVarHiPerf : public IEnumVARIANT
  423. {
  424. private:
  425. long m_cRef;
  426. unsigned long m_iCount;
  427. unsigned long m_iPos;
  428. IWbemObjectAccess **m_ppIWbemObjectAccess;
  429. CSWbemHiPerfObjectSet *m_pCSWbemHiPerfObjectSet;
  430. public:
  431. CEnumVarHiPerf (CSWbemHiPerfObjectSet *pCSWbemHiPerfObjectSet);
  432. virtual ~CEnumVarHiPerf (void);
  433. // Non-delegating object IUnknown
  434. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  435. STDMETHODIMP_(ULONG) AddRef(void);
  436. STDMETHODIMP_(ULONG) Release(void);
  437. // IEnumVARIANT
  438. STDMETHODIMP Next(
  439. unsigned long celt,
  440. VARIANT FAR* rgvar,
  441. unsigned long FAR* pceltFetched
  442. );
  443. STDMETHODIMP Skip(
  444. unsigned long celt
  445. );
  446. STDMETHODIMP Reset()
  447. {
  448. m_iPos = 0;
  449. SetWbemError (m_pCSWbemHiPerfObjectSet->GetSWbemServices ());
  450. return WBEM_S_NO_ERROR;
  451. }
  452. STDMETHODIMP Clone(
  453. IEnumVARIANT **ppenum
  454. );
  455. };
  456. #endif // _REFRESHER_H