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.

406 lines
8.4 KiB

  1. // Factory.cpp: implementation of the CFactory class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "hmagent.h"
  5. #include "consumer.h"
  6. #include "system.h"
  7. #include "evtprov.h"
  8. #include "instprov.h"
  9. #include "methprov.h"
  10. #include "factory.h"
  11. #include "Provider.h"
  12. extern long g_cComponents;
  13. extern long g_cServerLocks;
  14. //extern CSystem* g_pSystem;
  15. //extern HANDLE g_hEvtReady;
  16. //////////////////////////////////////////////////////////////////////
  17. // CHealthMonFactory - Base Class Factory
  18. //////////////////////////////////////////////////////////////////////
  19. //////////////////////////////////////////////////////////////////////
  20. // Construction/Destruction
  21. //////////////////////////////////////////////////////////////////////
  22. CBaseFactory::CBaseFactory()
  23. {
  24. m_cRef = 0L;
  25. }
  26. CBaseFactory::~CBaseFactory()
  27. {
  28. }
  29. //////////////////////////////////////////////////////////////////////
  30. // Query Interface
  31. //////////////////////////////////////////////////////////////////////
  32. STDMETHODIMP CBaseFactory::QueryInterface(REFIID riid, LPVOID* ppv)
  33. {
  34. *ppv=NULL;
  35. if (IID_IUnknown==riid || IID_IClassFactory==riid)
  36. {
  37. *ppv=this;
  38. AddRef();
  39. return S_OK;
  40. }
  41. return E_NOINTERFACE;
  42. }
  43. //////////////////////////////////////////////////////////////////////
  44. // AddRef/Release()
  45. //////////////////////////////////////////////////////////////////////
  46. STDMETHODIMP_(ULONG) CBaseFactory::AddRef(void)
  47. {
  48. return InterlockedIncrement((long*)&m_cRef);
  49. }
  50. STDMETHODIMP_(ULONG) CBaseFactory::Release(void)
  51. {
  52. ULONG ulNewCount = InterlockedDecrement((long *)&m_cRef);
  53. if (0L == ulNewCount)
  54. {
  55. delete this;
  56. }
  57. return ulNewCount;
  58. }
  59. //////////////////////////////////////////////////////////////////////
  60. // Create Instance
  61. //////////////////////////////////////////////////////////////////////
  62. STDMETHODIMP CBaseFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  63. {
  64. *ppObj = NULL;
  65. if (NULL != pUnkOuter)
  66. {
  67. return CLASS_E_NOAGGREGATION;
  68. }
  69. return S_OK;
  70. }
  71. //////////////////////////////////////////////////////////////////////
  72. // Lock Server
  73. //////////////////////////////////////////////////////////////////////
  74. STDMETHODIMP CBaseFactory::LockServer(BOOL fLock)
  75. {
  76. if (fLock)
  77. {
  78. InterlockedIncrement((LONG *) &g_cServerLocks);
  79. }
  80. else
  81. {
  82. InterlockedDecrement((LONG *) &g_cServerLocks);
  83. }
  84. return S_OK;
  85. }
  86. //////////////////////////////////////////////////////////////////////
  87. // Class Factory for Consumer (original agent)
  88. // Create instance of CConsumer
  89. //////////////////////////////////////////////////////////////////////
  90. STDMETHODIMP CConsFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
  91. {
  92. HRESULT hr;
  93. CProvider *pProvider = NULL;
  94. if (pUnkOuter)
  95. {
  96. return E_FAIL;
  97. }
  98. pProvider = new CProvider();
  99. if (pProvider == NULL)
  100. {
  101. *ppv = NULL;
  102. return E_OUTOFMEMORY;
  103. }
  104. if (pProvider)
  105. {
  106. hr = pProvider->QueryInterface(riid, ppv);
  107. MY_HRESASSERT(hr);
  108. }
  109. return NOERROR;
  110. }
  111. //////////////////////////////////////////////////////////////////////
  112. // Class Factory for Event Providers
  113. // Create instance of CBaseEventprovider
  114. //////////////////////////////////////////////////////////////////////
  115. STDMETHODIMP CSystemEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  116. {
  117. *ppObj = NULL;
  118. if (NULL != pUnkOuter)
  119. {
  120. return CLASS_E_NOAGGREGATION;
  121. }
  122. CSystemEventProvider* pProvider = new CSystemEventProvider();
  123. if (!pProvider)
  124. {
  125. return E_OUTOFMEMORY;
  126. }
  127. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  128. MY_HRESASSERT(hr);
  129. return hr;
  130. }
  131. STDMETHODIMP CDataGroupEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  132. {
  133. *ppObj = NULL;
  134. if (NULL != pUnkOuter)
  135. {
  136. return CLASS_E_NOAGGREGATION;
  137. }
  138. CDataGroupEventProvider* pProvider = new CDataGroupEventProvider;
  139. if (!pProvider)
  140. {
  141. return E_OUTOFMEMORY;
  142. }
  143. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  144. MY_HRESASSERT(hr);
  145. return hr;
  146. }
  147. STDMETHODIMP CDataCollectorEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  148. {
  149. *ppObj = NULL;
  150. if (NULL != pUnkOuter)
  151. {
  152. return CLASS_E_NOAGGREGATION;
  153. }
  154. CDataCollectorEventProvider* pProvider = new CDataCollectorEventProvider;
  155. if (!pProvider)
  156. {
  157. return E_OUTOFMEMORY;
  158. }
  159. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  160. MY_HRESASSERT(hr);
  161. return hr;
  162. }
  163. STDMETHODIMP CDataCollectorPerInstanceEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  164. {
  165. *ppObj = NULL;
  166. if (NULL != pUnkOuter)
  167. {
  168. return CLASS_E_NOAGGREGATION;
  169. }
  170. CDataCollectorPerInstanceEventProvider* pProvider = new CDataCollectorPerInstanceEventProvider;
  171. if (!pProvider)
  172. {
  173. return E_OUTOFMEMORY;
  174. }
  175. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  176. MY_HRESASSERT(hr);
  177. return hr;
  178. }
  179. STDMETHODIMP CThresholdEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  180. {
  181. *ppObj = NULL;
  182. if (NULL != pUnkOuter)
  183. {
  184. return CLASS_E_NOAGGREGATION;
  185. }
  186. CThresholdEventProvider* pProvider = new CThresholdEventProvider;
  187. if (!pProvider)
  188. {
  189. return E_OUTOFMEMORY;
  190. }
  191. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  192. MY_HRESASSERT(hr);
  193. return hr;
  194. }
  195. STDMETHODIMP CActionEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  196. {
  197. *ppObj = NULL;
  198. if (NULL != pUnkOuter)
  199. {
  200. return CLASS_E_NOAGGREGATION;
  201. }
  202. CActionEventProvider* pProvider = new CActionEventProvider;
  203. if (!pProvider)
  204. {
  205. return E_OUTOFMEMORY;
  206. }
  207. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  208. MY_HRESASSERT(hr);
  209. return hr;
  210. }
  211. STDMETHODIMP CActionTriggerEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  212. {
  213. *ppObj = NULL;
  214. if (NULL != pUnkOuter)
  215. {
  216. return CLASS_E_NOAGGREGATION;
  217. }
  218. CActionTriggerEventProvider* pProvider = new CActionTriggerEventProvider;
  219. if (!pProvider)
  220. {
  221. return E_OUTOFMEMORY;
  222. }
  223. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  224. MY_HRESASSERT(hr);
  225. return hr;
  226. }
  227. //////////////////////////////////////////////////////////////////////
  228. // Class Factory for Instance Provider.
  229. // Create instance of CBaseInstanceProvider
  230. //////////////////////////////////////////////////////////////////////
  231. STDMETHODIMP CInstProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  232. {
  233. *ppObj = NULL;
  234. if (NULL != pUnkOuter)
  235. {
  236. return CLASS_E_NOAGGREGATION;
  237. }
  238. CBaseInstanceProvider* pProvider = new CBaseInstanceProvider;
  239. if (!pProvider)
  240. {
  241. return E_OUTOFMEMORY;
  242. }
  243. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  244. MY_HRESASSERT(hr);
  245. return hr;
  246. }
  247. //////////////////////////////////////////////////////////////////////
  248. // Class Factory for Method Provider.
  249. // Create instance of CCMethProvFactory
  250. //////////////////////////////////////////////////////////////////////
  251. STDMETHODIMP CMethProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  252. {
  253. *ppObj = NULL;
  254. if (NULL != pUnkOuter)
  255. return CLASS_E_NOAGGREGATION;
  256. CBaseMethodProvider* pProvider = new CBaseMethodProvider;
  257. if (!pProvider)
  258. {
  259. return E_OUTOFMEMORY;
  260. }
  261. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  262. MY_HRESASSERT(hr);
  263. return hr;
  264. }
  265. #ifdef SAVE
  266. STDMETHODIMP CDataCollectorStatisticsEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  267. {
  268. *ppObj = NULL;
  269. if (NULL != pUnkOuter)
  270. {
  271. return CLASS_E_NOAGGREGATION;
  272. }
  273. CDataCollectorStatisticsEventProvider* pProvider = new CDataCollectorStatisticsEventProvider;
  274. if (!pProvider)
  275. {
  276. return E_OUTOFMEMORY;
  277. }
  278. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  279. MY_HRESASSERT(hr);
  280. return hr;
  281. }
  282. #endif
  283. #ifdef SAVE
  284. STDMETHODIMP CThresholdInstanceEvtProvFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppObj)
  285. {
  286. *ppObj = NULL;
  287. if (NULL != pUnkOuter)
  288. return CLASS_E_NOAGGREGATION;
  289. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEvtProvFactory::CreateInstance BLOCK - g_hEvtReady BLOCK WAIT", 1);
  290. //ZZZ if (WaitForSingleObject(g_hEvtReady, 0) != WAIT_OBJECT_0 || g_pSystem == NULL)
  291. //ZZZ {
  292. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEvtProvFactory::CreateInstance BLOCK - g_hEvtReady BLOCK NOT READY", 1);
  293. //ZZZ return E_FAIL;
  294. //ZZZ }
  295. //ZZZMY_OUTPUT(L"BLOCK - BLOCK CThresholdInstanceEvtProvFactory::CreateInstance BLOCK - g_hEvtReady BLOCK READY", 1);
  296. // MY_ASSERT(g_pSystem);
  297. CThresholdInstanceEventProvider* pProvider = new CThresholdInstanceEventProvider;
  298. if (!pProvider)
  299. return E_OUTOFMEMORY;
  300. HRESULT hr = pProvider->QueryInterface(riid, ppObj);
  301. MY_HRESASSERT(hr);
  302. return hr;
  303. }
  304. #endif