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.

286 lines
6.0 KiB

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