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.

289 lines
5.8 KiB

  1. //***************************************************************************
  2. //
  3. // VPCFAC.CPP
  4. //
  5. // Module: WBEM VIEW PROVIDER
  6. //
  7. // Purpose: Contains the class factory. This creates objects when
  8. // connections are requested.
  9. //
  10. // Copyright (c) 1998-2001 Microsoft Corporation, All Rights Reserved
  11. //
  12. //***************************************************************************
  13. #include "precomp.h"
  14. #include <provexpt.h>
  15. #include <provtempl.h>
  16. #include <provmt.h>
  17. #include <typeinfo.h>
  18. #include <process.h>
  19. #include <objbase.h>
  20. #include <stdio.h>
  21. #include <wbemidl.h>
  22. #include <provcont.h>
  23. #include <provevt.h>
  24. #include <provthrd.h>
  25. #include <provlog.h>
  26. #include <instpath.h>
  27. #include <genlex.h>
  28. #include <sql_1.h>
  29. #include <objpath.h>
  30. #include <vpserv.h>
  31. #include <vpcfac.h>
  32. extern CRITICAL_SECTION g_CriticalSection;
  33. LONG CViewProvClassFactory :: objectsInProgress = 0 ;
  34. LONG CViewProvClassFactory :: locksInProgress = 0 ;
  35. //***************************************************************************
  36. //
  37. // CViewProvClassFactory::CViewProvClassFactory
  38. // CViewProvClassFactory::~CViewProvClassFactory
  39. //
  40. // Constructor Parameters:
  41. // None
  42. //***************************************************************************
  43. CViewProvClassFactory::CViewProvClassFactory ()
  44. {
  45. EnterCriticalSection(&g_CriticalSection);
  46. objectsInProgress++;
  47. LeaveCriticalSection(&g_CriticalSection);
  48. m_referenceCount = 0 ;
  49. }
  50. CViewProvClassFactory::~CViewProvClassFactory ()
  51. {
  52. EnterCriticalSection(&g_CriticalSection);
  53. objectsInProgress--;
  54. LeaveCriticalSection(&g_CriticalSection);
  55. }
  56. //***************************************************************************
  57. //
  58. // CViewProvClassFactory::QueryInterface
  59. // CViewProvClassFactory::AddRef
  60. // CViewProvClassFactory::Release
  61. //
  62. // Purpose: Standard Ole routines needed for all interfaces
  63. //
  64. //***************************************************************************
  65. STDMETHODIMP CViewProvClassFactory::QueryInterface (
  66. REFIID iid ,
  67. LPVOID FAR *iplpv
  68. )
  69. {
  70. SetStructuredExceptionHandler seh;
  71. try
  72. {
  73. *iplpv = NULL ;
  74. if ( iid == IID_IUnknown )
  75. {
  76. *iplpv = ( LPVOID ) this ;
  77. }
  78. else if ( iid == IID_IClassFactory )
  79. {
  80. *iplpv = ( LPVOID ) this ;
  81. }
  82. if ( *iplpv )
  83. {
  84. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  85. return ResultFromScode ( S_OK ) ;
  86. }
  87. else
  88. {
  89. return ResultFromScode ( E_NOINTERFACE ) ;
  90. }
  91. }
  92. catch(Structured_Exception e_SE)
  93. {
  94. return E_UNEXPECTED;
  95. }
  96. catch(Heap_Exception e_HE)
  97. {
  98. return E_OUTOFMEMORY;
  99. }
  100. catch(...)
  101. {
  102. return E_UNEXPECTED;
  103. }
  104. }
  105. STDMETHODIMP_( ULONG ) CViewProvClassFactory :: AddRef ()
  106. {
  107. SetStructuredExceptionHandler seh;
  108. try
  109. {
  110. return InterlockedIncrement ( &m_referenceCount ) ;
  111. }
  112. catch(Structured_Exception e_SE)
  113. {
  114. return 0;
  115. }
  116. catch(Heap_Exception e_HE)
  117. {
  118. return 0;
  119. }
  120. catch(...)
  121. {
  122. return 0;
  123. }
  124. }
  125. STDMETHODIMP_(ULONG) CViewProvClassFactory :: Release ()
  126. {
  127. SetStructuredExceptionHandler seh;
  128. LONG ref = 0;
  129. try
  130. {
  131. if ( ( ref = InterlockedDecrement ( & m_referenceCount ) ) == 0 )
  132. {
  133. delete this ;
  134. }
  135. }
  136. catch(Structured_Exception e_SE)
  137. {
  138. ref = 0;
  139. }
  140. catch(Heap_Exception e_HE)
  141. {
  142. ref = 0;
  143. }
  144. catch(...)
  145. {
  146. ref = 0;
  147. }
  148. return ref ;
  149. }
  150. //***************************************************************************
  151. //
  152. // CViewProvClassFactory::LockServer
  153. //
  154. // Purpose:
  155. // Increments or decrements the lock count of the DLL. If the
  156. // lock count goes to zero and there are no objects, the DLL
  157. // is allowed to unload. See DllCanUnloadNow.
  158. //
  159. // Parameters:
  160. // fLock BOOL specifying whether to increment or
  161. // decrement the lock count.
  162. //
  163. // Return Value:
  164. // HRESULT NOERROR always.
  165. //***************************************************************************
  166. STDMETHODIMP CViewProvClassFactory :: LockServer ( BOOL fLock )
  167. {
  168. SetStructuredExceptionHandler seh;
  169. try
  170. {
  171. if ( fLock )
  172. {
  173. InterlockedIncrement ( & locksInProgress ) ;
  174. }
  175. else
  176. {
  177. InterlockedDecrement ( & locksInProgress ) ;
  178. }
  179. return S_OK ;
  180. }
  181. catch(Structured_Exception e_SE)
  182. {
  183. return E_UNEXPECTED;
  184. }
  185. catch(Heap_Exception e_HE)
  186. {
  187. return E_OUTOFMEMORY;
  188. }
  189. catch(...)
  190. {
  191. return E_UNEXPECTED;
  192. }
  193. }
  194. //***************************************************************************
  195. //
  196. // CViewProvClassFactory::CreateInstance
  197. //
  198. // Purpose: Instantiates a Provider object returning an interface pointer.
  199. //
  200. // Parameters:
  201. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  202. // being used in an aggregation.
  203. // riid REFIID identifying the interface the caller
  204. // desires to have for the new object.
  205. // ppvObj PPVOID in which to store the desired
  206. // interface pointer for the new object.
  207. //
  208. // Return Value:
  209. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  210. // if we cannot support the requested interface.
  211. //***************************************************************************
  212. STDMETHODIMP CViewProvClassFactory :: CreateInstance(LPUNKNOWN pUnkOuter ,
  213. REFIID riid,
  214. LPVOID FAR * ppvObject
  215. )
  216. {
  217. HRESULT status = E_FAIL;
  218. SetStructuredExceptionHandler seh;
  219. try
  220. {
  221. if ( pUnkOuter )
  222. {
  223. status = CLASS_E_NOAGGREGATION;
  224. }
  225. else
  226. {
  227. CViewProvServ* prov = new CViewProvServ;
  228. status = prov->QueryInterface (riid, ppvObject);
  229. if (NOERROR != status)
  230. {
  231. delete prov;
  232. }
  233. }
  234. }
  235. catch(Structured_Exception e_SE)
  236. {
  237. status = E_UNEXPECTED;
  238. }
  239. catch(Heap_Exception e_HE)
  240. {
  241. status = E_OUTOFMEMORY;
  242. }
  243. catch(...)
  244. {
  245. status = E_UNEXPECTED;
  246. }
  247. return status ;
  248. }