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.

257 lines
5.7 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CFactory.cpp
  7. //
  8. // Description:
  9. // description-for-module
  10. //
  11. // [Header File:]
  12. // CFactory.h
  13. //
  14. // History:
  15. // Xing Jin (i-xingj) 06-Dec-2000
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "stdafx.h"
  19. #include "CFactory.h"
  20. #include "CAlertEmailConsumerProvider.h"
  21. #include "AlertEmailProviderGuid.h"
  22. extern LONG g_cObj;
  23. extern LONG g_cLock;
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // CFactory::CFactory
  27. //
  28. // Description:
  29. // Class constructor.
  30. //
  31. // Arguments:
  32. // [in] ClsIdIn
  33. //
  34. // History:
  35. // Xing Jin (i-xingj) 06-Dec-2000
  36. //
  37. //////////////////////////////////////////////////////////////////////////////
  38. CFactory::CFactory(
  39. const CLSID & ClsIdIn
  40. )
  41. {
  42. m_cRef = 0;
  43. m_ClsId = ClsIdIn;
  44. InterlockedIncrement( &g_cObj );
  45. }
  46. //////////////////////////////////////////////////////////////////////////////
  47. //
  48. // CFactory::CFactory
  49. //
  50. // Description:
  51. // Class deconstructor.
  52. //
  53. // History:
  54. // Xing Jin (i-xingj) 06-Dec-2000
  55. //
  56. //////////////////////////////////////////////////////////////////////////////
  57. CFactory::~CFactory()
  58. {
  59. // nothing
  60. InterlockedDecrement( &g_cObj );
  61. }
  62. //////////////////////////////////////////////////////////////////////////////
  63. //
  64. // CFactory::QueryInterface
  65. //
  66. // Description:
  67. // An method implement of IUnkown interface.
  68. //
  69. // Arguments:
  70. // [in] riidIn Identifier of the requested interface
  71. // [out] ppvOut Address of output variable that receives the
  72. // interface pointer requested in iid
  73. //
  74. // Returns:
  75. // NOERROR if the interface is supported
  76. // E_NOINTERFACE if not
  77. //
  78. // History:
  79. // Xing Jin (i-xingj) 06-Dec-2000
  80. //
  81. //////////////////////////////////////////////////////////////////////////////
  82. STDMETHODIMP
  83. CFactory::QueryInterface(
  84. REFIID riidIn,
  85. LPVOID * ppvOut
  86. )
  87. {
  88. *ppvOut = NULL;
  89. if ( ( IID_IUnknown == riidIn )
  90. || ( IID_IClassFactory==riidIn ) )
  91. {
  92. *ppvOut = this;
  93. AddRef();
  94. return NOERROR;
  95. }
  96. return E_NOINTERFACE;
  97. }
  98. //////////////////////////////////////////////////////////////////////////////
  99. //
  100. // CFactory::AddRef
  101. //
  102. // Description:
  103. // increments the reference count for an interface on an object
  104. //
  105. // Returns:
  106. // The new reference count.
  107. //
  108. // History:
  109. // Xing Jin (i-xingj) 06-Dec-2000
  110. //
  111. //////////////////////////////////////////////////////////////////////////////
  112. ULONG
  113. CFactory::AddRef()
  114. {
  115. InterlockedIncrement( &m_cRef );
  116. return m_cRef;
  117. }
  118. //////////////////////////////////////////////////////////////////////////////
  119. //
  120. // CFactory::Release
  121. //
  122. // Description:
  123. // decrements the reference count for an interface on an object.
  124. //
  125. // Returns:
  126. // The new reference count.
  127. //
  128. // History:
  129. // Xing Jin (i-xingj) 06-Dec-2000
  130. //
  131. //////////////////////////////////////////////////////////////////////////////
  132. ULONG
  133. CFactory::Release()
  134. {
  135. InterlockedDecrement( &m_cRef );
  136. if (0 != m_cRef)
  137. {
  138. return m_cRef;
  139. }
  140. delete this;
  141. return 0;
  142. }
  143. //////////////////////////////////////////////////////////////////////////////
  144. //
  145. // CFactory::CreateInstance
  146. //
  147. // Description:
  148. // Instance creation.
  149. //
  150. // Arguments:
  151. // [in] riidIn Reference to the identifier of the interface
  152. // [out] pUnkOuter Pointer to whether object is or isn't part of
  153. // an aggregate
  154. // ppvObjOut Address of output variable that receives the
  155. // interface pointer requested in riid
  156. //
  157. // History:
  158. // Xing Jin (i-xingj) 06-Dec-2000
  159. //
  160. //////////////////////////////////////////////////////////////////////////////
  161. STDMETHODIMP
  162. CFactory::CreateInstance(
  163. LPUNKNOWN pUnkOuter,
  164. REFIID riidIn,
  165. LPVOID * ppvObjOut
  166. )
  167. {
  168. IUnknown* pObj = NULL;
  169. HRESULT hr;
  170. //
  171. // Defaults
  172. //
  173. *ppvObjOut = NULL;
  174. hr = E_OUTOFMEMORY;
  175. //
  176. // We aren't supporting aggregation.
  177. //
  178. if ( pUnkOuter )
  179. {
  180. return CLASS_E_NOAGGREGATION;
  181. }
  182. if (m_ClsId == CLSID_AlertEmailConsumerProvider)
  183. {
  184. pObj = (IWbemEventConsumerProvider *) new CAlertEmailConsumerProvider;
  185. }
  186. if ( pObj == NULL )
  187. {
  188. return hr;
  189. }
  190. //
  191. // Initialize the object and verify that it can return the
  192. // interface in question.
  193. //
  194. hr = pObj->QueryInterface( riidIn, ppvObjOut );
  195. //
  196. // Kill the object if initial creation or Init failed.
  197. //
  198. if ( FAILED( hr ) )
  199. {
  200. delete pObj;
  201. }
  202. return hr;
  203. }
  204. //////////////////////////////////////////////////////////////////////////////
  205. //
  206. // CFactory::LockServer
  207. //
  208. // Description:
  209. // Call by client to keep server in memory.
  210. //
  211. // Arguments:
  212. // [in] fLockIn //Increments or decrements the lock count
  213. //
  214. // History:
  215. // Xing Jin (i-xingj) 06-Dec-2000
  216. //
  217. //////////////////////////////////////////////////////////////////////////////
  218. STDMETHODIMP
  219. CFactory::LockServer(
  220. BOOL fLockIn
  221. )
  222. {
  223. if ( fLockIn )
  224. {
  225. InterlockedIncrement( &g_cLock );
  226. }
  227. else
  228. {
  229. InterlockedDecrement( &g_cLock );
  230. }
  231. return NOERROR;
  232. }