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.

480 lines
12 KiB

  1. // EVTPROV.CPP: implementation of the CBaseEventProvider class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "HMAgent.h"
  5. //#include "system.h"
  6. #include "evtprov.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // global data
  9. //extern CSystem* g_pSystem;
  10. extern HANDLE g_hConfigLock;
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. CBaseEventProvider::CBaseEventProvider()
  15. {
  16. OutputDebugString(L"CBaseEventProvider::CBaseEventProvider()\n");
  17. // m_pSystem = g_pSystem;
  18. m_cRef = 0L;
  19. m_pIWbemServices = NULL;
  20. }
  21. CBaseEventProvider::~CBaseEventProvider()
  22. {
  23. OutputDebugString(L"CBaseEventProvider::~CBaseEventProvider()\n");
  24. if (m_pIWbemServices)
  25. {
  26. m_pIWbemServices->Release();
  27. }
  28. m_pIWbemServices = NULL;
  29. }
  30. //////////////////////////////////////////////////////////////////////
  31. // IUnknown Implementation
  32. //////////////////////////////////////////////////////////////////////
  33. STDMETHODIMP CBaseEventProvider::QueryInterface(REFIID riid, LPVOID* ppv)
  34. {
  35. *ppv = NULL;
  36. if (IID_IUnknown==riid || IID_IWbemEventProvider==riid)
  37. {
  38. *ppv = (IWbemEventProvider *) this;
  39. AddRef();
  40. return S_OK;
  41. }
  42. if (IID_IWbemProviderInit==riid)
  43. {
  44. *ppv = (IWbemProviderInit *) this;
  45. AddRef();
  46. return S_OK;
  47. }
  48. return E_NOINTERFACE;
  49. }
  50. STDMETHODIMP_(ULONG) CBaseEventProvider::AddRef(void)
  51. {
  52. return InterlockedIncrement((long*)&m_cRef);
  53. }
  54. //////////////////////////////////////////////////////////////////////
  55. // IWbemProviderInit Implementation
  56. //////////////////////////////////////////////////////////////////////
  57. HRESULT CBaseEventProvider::Initialize( LPWSTR pszUser,
  58. LONG lFlags,
  59. LPWSTR pszNamespace,
  60. LPWSTR pszLocale,
  61. IWbemServices __RPC_FAR *pNamespace,
  62. IWbemContext __RPC_FAR *pCtx,
  63. IWbemProviderInitSink __RPC_FAR *pInitSink)
  64. {
  65. OutputDebugString(L"CBaseEventProvider::Initialize()\n");
  66. if (NULL == pNamespace)
  67. {
  68. return WBEM_E_INVALID_PARAMETER;
  69. }
  70. // save the IWbemServices namespace
  71. // we may need it later
  72. m_pIWbemServices = pNamespace;
  73. m_pIWbemServices->AddRef();
  74. // Tell CIMOM that we're up and running.
  75. MY_ASSERT(pInitSink);
  76. pInitSink->SetStatus(WBEM_S_INITIALIZED, 0);
  77. return WBEM_NO_ERROR;
  78. }
  79. //////////////////////////////////////////////////////////////////////
  80. // IWbemProvider Implementation
  81. //////////////////////////////////////////////////////////////////////
  82. HRESULT CBaseEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  83. {
  84. if (NULL == pSink)
  85. {
  86. return WBEM_E_INVALID_PARAMETER;
  87. }
  88. return WBEM_E_NOT_SUPPORTED;
  89. }
  90. STDMETHODIMP_(ULONG) CBaseEventProvider::Release(void)
  91. {
  92. LONG lCount;
  93. lCount = InterlockedDecrement((long*)&m_cRef);
  94. if (0 != lCount)
  95. {
  96. return lCount;
  97. }
  98. delete this;
  99. return 0L;
  100. }
  101. //////////////////////////////////////////////////////////////////////
  102. // Derived Implementation
  103. //////////////////////////////////////////////////////////////////////
  104. HRESULT CSystemEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  105. {
  106. OutputDebugString(L"CSystemEventProvider::ProvideEvents\n");
  107. // Set CSystem to deliver events
  108. pSink->AddRef();
  109. g_pSystemEventSink = pSink;
  110. return WBEM_NO_ERROR;
  111. }
  112. STDMETHODIMP_(ULONG) CSystemEventProvider::Release(void)
  113. {
  114. OutputDebugString(L"CSystemEventProvider::Release()\n");
  115. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  116. if (0 != lCount)
  117. {
  118. return lCount;
  119. }
  120. OutputDebugString(L"CSystemEventProvider::Release - Terminating Evt Delivery\n");
  121. if (g_pSystemEventSink)
  122. {
  123. g_pSystemEventSink->Release();
  124. }
  125. g_pSystemEventSink = NULL;
  126. delete this;
  127. return 0L;
  128. }
  129. HRESULT CDataGroupEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  130. {
  131. OutputDebugString(L"CDataGroupEventProvider::ProvideEvents\n");
  132. // Set CSystem to deliver events
  133. pSink->AddRef();
  134. g_pDataGroupEventSink = pSink;
  135. return WBEM_NO_ERROR;
  136. }
  137. STDMETHODIMP_(ULONG) CDataGroupEventProvider::Release(void)
  138. {
  139. OutputDebugString(L"CDataGroupEventProvider::Release()\n");
  140. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  141. if (0 != lCount)
  142. {
  143. return lCount;
  144. }
  145. OutputDebugString(L"CDataGroupEventProvider::Release - Terminating Evt Delivery\n");
  146. if (g_pDataGroupEventSink)
  147. {
  148. g_pDataGroupEventSink->Release();
  149. }
  150. g_pDataGroupEventSink = NULL;
  151. delete this;
  152. return 0L;
  153. }
  154. HRESULT CDataCollectorEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  155. {
  156. OutputDebugString(L"CDataCollectorEventProvider::ProvideEvents\n");
  157. // Set CSystem to deliver events
  158. pSink->AddRef();
  159. g_pDataCollectorEventSink = pSink;
  160. return WBEM_NO_ERROR;
  161. }
  162. STDMETHODIMP_(ULONG) CDataCollectorEventProvider::Release(void)
  163. {
  164. OutputDebugString(L"CDataCollectorEventProvider::Release()\n");
  165. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  166. if (0 != lCount)
  167. {
  168. return lCount;
  169. }
  170. OutputDebugString(L"CDataCollectorEventProvider::Release - Terminating Evt Delivery\n");
  171. if (g_pDataCollectorEventSink)
  172. {
  173. g_pDataCollectorEventSink->Release();
  174. }
  175. g_pDataCollectorEventSink = NULL;
  176. delete this;
  177. return 0L;
  178. }
  179. HRESULT CDataCollectorPerInstanceEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  180. {
  181. OutputDebugString(L"CDataCollectorPerInstanceEventProvider::ProvideEvents\n");
  182. // Set CSystem to deliver events
  183. pSink->AddRef();
  184. g_pDataCollectorPerInstanceEventSink = pSink;
  185. return WBEM_NO_ERROR;
  186. }
  187. STDMETHODIMP_(ULONG) CDataCollectorPerInstanceEventProvider::Release(void)
  188. {
  189. OutputDebugString(L"CDataCollectorPerInstanceEventProvider::Release()\n");
  190. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  191. if (0 != lCount)
  192. {
  193. return lCount;
  194. }
  195. OutputDebugString(L"CDataCollectorPerInstanceEventProvider::Release - Terminating Evt Delivery\n");
  196. if (g_pDataCollectorPerInstanceEventSink)
  197. {
  198. g_pDataCollectorPerInstanceEventSink->Release();
  199. }
  200. g_pDataCollectorPerInstanceEventSink = NULL;
  201. delete this;
  202. return 0L;
  203. }
  204. HRESULT CThresholdEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  205. {
  206. OutputDebugString(L"CThresholdEventProvider::ProvideEvents\n");
  207. // Set CSystem to deliver events
  208. pSink->AddRef();
  209. g_pThresholdEventSink = pSink;
  210. return WBEM_NO_ERROR;
  211. }
  212. STDMETHODIMP_(ULONG) CThresholdEventProvider::Release(void)
  213. {
  214. OutputDebugString(L"CThresholdEventProvider::Release()\n");
  215. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  216. if (0 != lCount)
  217. {
  218. return lCount;
  219. }
  220. OutputDebugString(L"CThresholdEventProvider::Release - Terminating Evt Delivery\n");
  221. if (g_pThresholdEventSink)
  222. {
  223. g_pThresholdEventSink->Release();
  224. }
  225. g_pThresholdEventSink = NULL;
  226. delete this;
  227. return 0L;
  228. }
  229. HRESULT CActionEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  230. {
  231. OutputDebugString(L"CActionEventProvider::ProvideEvents\n");
  232. // Set CSystem to deliver events
  233. pSink->AddRef();
  234. g_pActionEventSink = pSink;
  235. return WBEM_NO_ERROR;
  236. }
  237. STDMETHODIMP_(ULONG) CActionEventProvider::Release(void)
  238. {
  239. OutputDebugString(L"CActionEventProvider::Release()\n");
  240. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  241. if (0 != lCount)
  242. {
  243. return lCount;
  244. }
  245. OutputDebugString(L"CActionEventProvider::Release - Terminating Evt Delivery\n");
  246. if (g_pActionEventSink)
  247. {
  248. g_pActionEventSink->Release();
  249. }
  250. g_pActionEventSink = NULL;
  251. delete this;
  252. return 0L;
  253. }
  254. HRESULT CActionTriggerEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  255. {
  256. OutputDebugString(L"CActionTriggerEventProvider::ProvideEvents\n");
  257. // Set CSystem to deliver events
  258. pSink->AddRef();
  259. g_pActionTriggerEventSink = pSink;
  260. return WBEM_NO_ERROR;
  261. }
  262. STDMETHODIMP_(ULONG) CActionTriggerEventProvider::Release(void)
  263. {
  264. OutputDebugString(L"CActionTriggerEventProvider::Release()\n");
  265. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  266. if (0 != lCount)
  267. {
  268. return lCount;
  269. }
  270. OutputDebugString(L"CActionTriggerEventProvider::Release - Terminating Evt Delivery\n");
  271. if (g_pActionTriggerEventSink)
  272. {
  273. g_pActionTriggerEventSink->Release();
  274. }
  275. g_pActionTriggerEventSink = NULL;
  276. delete this;
  277. return 0L;
  278. }
  279. ///////////////////////////////////////////////////////////////////////////////////////
  280. #ifdef SAVE
  281. HRESULT CDataCollectorStatisticsEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  282. {
  283. OutputDebugString(L"CDataCollectorStatisticsEventProvider::ProvideEvents\n");
  284. // Set CSystem to deliver events
  285. pSink->AddRef();
  286. g_pDataCollectorStatisticsEventSink = pSink;
  287. return WBEM_NO_ERROR;
  288. }
  289. STDMETHODIMP_(ULONG) CDataCollectorStatisticsEventProvider::Release(void)
  290. {
  291. OutputDebugString(L"CDataCollectorStatisticsEventProvider::Release()\n");
  292. //XXXPut all these back in, or create a different mutex, so can differentiate
  293. //between blocking the three things - config edit, come here beacuse of WMI request
  294. //and AgentInterval. We were having a problem with action association and creation of the
  295. //__FilterToConsumerBinding instance, that it would then call back in on a separate thread
  296. //And we would block here. The reason is that the Action code also registers an event sink for
  297. //Status events, so that it can do the Throttling, that beings us back into here on a separate thread
  298. //and we block each other! Becuse the call in Action.cpp never returns...
  299. //I don't remember why it was comming into the release code however.
  300. //The reason for the Mutex in the first place is to avoid a timming issue where the DE code or other
  301. //similar event code that calls Indicate doesn;t have the sink pointer taken away, because just
  302. //before it goes to use it it is pre-empted and this code NULLs it out!. This would happen when the
  303. //console goes away.
  304. //The Instprov.cpp code and calls to indicate in DE.cpp are OK as they are still protected by
  305. //the EditMutex. There we want to prevent two threads colliding, like a delete happening
  306. //At the same time someone is enumerating the SystemStatus class.
  307. //XXXMY_OUTPUT(L"BLOCK - BLOCK CDataCollectorStatisticsEventProvider::Release BLOCK - g_hConfigLock BLOCK WAIT", 1);
  308. //XXX WaitForSingleObject(g_hConfigLock, INFINITE);
  309. //XXXMY_OUTPUT(L"BLOCK - BLOCK CDataCollectorStatisticsEventProvider::Release BLOCK - g_hConfigLock BLOCK GOT IT", 1);
  310. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  311. if (0 != lCount)
  312. {
  313. //XXXMY_OUTPUT(L"BLOCK - BLOCK CDataCollectorStatisticsEventProvider::Release g_hConfigLock BLOCK - RELEASE IT", 1);
  314. //XXX ReleaseMutex(g_hConfigLock);
  315. //XXXMY_OUTPUT(L"BLOCK - BLOCK CDataCollectorStatisticsEventProvider::Release g_hConfigLock BLOCK - RELEASED", 1);
  316. return lCount;
  317. }
  318. OutputDebugString(L"CDataCollectorEventStatisticsProvider::Release - Terminating Evt Delivery\n");
  319. if (g_pDataCollectorStatisticsEventSink)
  320. g_pDataCollectorStatisticsEventSink->Release();
  321. g_pDataCollectorStatisticsEventSink = NULL;
  322. delete this;
  323. //XXXMY_OUTPUT(L"BLOCK - BLOCK CDataCollectorStatisticsEventProvider::Release g_hConfigLock BLOCK - RELEASE IT", 1);
  324. //XXX ReleaseMutex(g_hConfigLock);
  325. //XXXMY_OUTPUT(L"BLOCK - BLOCK CDataCollectorStatisticsEventProvider::Release g_hConfigLock BLOCK - RELEASED", 1);
  326. return 0L;
  327. }
  328. #endif
  329. #ifdef SAVE
  330. HRESULT CThresholdInstanceEventProvider::ProvideEvents(IWbemObjectSink __RPC_FAR *pSink, long lFlags)
  331. {
  332. OutputDebugString(L"CThresholdInstanceEventProvider::ProvideEvents\n");
  333. // Set CSystem to deliver events
  334. pSink->AddRef();
  335. g_pThresholdInstanceEventSink = pSink;
  336. return WBEM_NO_ERROR;
  337. }
  338. STDMETHODIMP_(ULONG) CThresholdInstanceEventProvider::Release(void)
  339. {
  340. OutputDebugString(L"CThresholdInstanceEventProvider::Release()\n");
  341. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEventProvider::Release g_hConfigLock BLOCK - BLOCK WAIT", 1);
  342. //ZZZ WaitForSingleObject(g_hConfigLock, INFINITE);
  343. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEventProvider::Release BLOCK - g_hConfigLock BLOCK GOT IT", 1);
  344. LONG lCount = InterlockedDecrement((long*)&m_cRef);
  345. if (0 != lCount)
  346. {
  347. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEventProvider::Release g_hConfigLock BLOCK - RELEASE IT", 1);
  348. //ZZZ ReleaseMutex(g_hConfigLock);
  349. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEventProvider::Release g_hConfigLock BLOCK - RELEASED", 1);
  350. return lCount;
  351. }
  352. OutputDebugString(L"CThresholdInstanceEventProvider::Release - Terminating Evt Delivery\n");
  353. if (g_pThresholdInstanceEventSink)
  354. g_pThresholdInstanceEventSink->Release();
  355. g_pThresholdInstanceEventSink = NULL;
  356. delete this;
  357. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEventProvider::Release g_hConfigLock BLOCK - RELEASE IT", 1);
  358. //ZZZ ReleaseMutex(g_hConfigLock);
  359. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEventProvider::Release g_hConfigLock BLOCK - RELEASED", 1);
  360. return 0L;
  361. }
  362. #endif