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.

410 lines
10 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. // ***************************************************************************
  5. //
  6. // Original Author: Rajesh Rao
  7. //
  8. // $Author: rajeshr $
  9. // $Date: 6/11/98 4:43p $
  10. // $Workfile:classfac.cpp $
  11. //
  12. // $Modtime: 6/11/98 11:21a $
  13. // $Revision: 1 $
  14. // $Nokeywords: $
  15. //
  16. //
  17. // Description: Contains the implementation of the DS Class Provider factory.
  18. // Currently it always creates the LDAP CLass Provider. It remains to be decided as to how this can
  19. // be changed
  20. //
  21. //***************************************************************************
  22. #include "precomp.h"
  23. // Initializer objects required by the classes used by the DLL
  24. CDSClassProviderInitializer *CDSClassProviderClassFactory::s_pDSClassProviderInitializer = NULL;
  25. CLDAPClassProviderInitializer *CDSClassProviderClassFactory::s_pLDAPClassProviderInitializer = NULL;
  26. //***************************************************************************
  27. //
  28. // CDSClassProviderClassFactory::CDSClassProviderClassFactory
  29. // CDSClassProviderClassFactory::~CDSClassProviderClassFactory
  30. //
  31. // Constructor Parameters:
  32. // None
  33. //***************************************************************************
  34. CDSClassProviderClassFactory :: CDSClassProviderClassFactory ()
  35. {
  36. m_ReferenceCount = 0 ;
  37. InterlockedIncrement(&g_lComponents);
  38. }
  39. CDSClassProviderClassFactory::~CDSClassProviderClassFactory ()
  40. {
  41. InterlockedDecrement(&g_lComponents);
  42. }
  43. //***************************************************************************
  44. //
  45. // CDSClassProviderClassFactory::QueryInterface
  46. // CDSClassProviderClassFactory::AddRef
  47. // CDSClassProviderClassFactory::Release
  48. //
  49. // Purpose: Standard COM routines needed for all interfaces
  50. //
  51. //***************************************************************************
  52. STDMETHODIMP CDSClassProviderClassFactory::QueryInterface (
  53. REFIID iid ,
  54. LPVOID FAR *iplpv
  55. )
  56. {
  57. *iplpv = NULL ;
  58. if ( iid == IID_IUnknown )
  59. {
  60. *iplpv = ( LPVOID ) this ;
  61. }
  62. else if ( iid == IID_IClassFactory )
  63. {
  64. *iplpv = ( LPVOID ) this ;
  65. }
  66. else
  67. {
  68. return E_NOINTERFACE;
  69. }
  70. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  71. return S_OK;
  72. }
  73. STDMETHODIMP_( ULONG ) CDSClassProviderClassFactory :: AddRef ()
  74. {
  75. return InterlockedIncrement ( & m_ReferenceCount ) ;
  76. }
  77. STDMETHODIMP_(ULONG) CDSClassProviderClassFactory :: Release ()
  78. {
  79. LONG ref ;
  80. if ( ( ref = InterlockedDecrement ( & m_ReferenceCount ) ) == 0 )
  81. {
  82. delete this ;
  83. return 0 ;
  84. }
  85. else
  86. {
  87. return ref ;
  88. }
  89. }
  90. //***************************************************************************
  91. //
  92. // CDSClassProviderClassFactory::CreateInstance
  93. //
  94. // Purpose: Instantiates a Provider object returning an interface pointer.
  95. //
  96. // Parameters:
  97. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  98. // being used in an aggregation.
  99. // riid REFIID identifying the interface the caller
  100. // desires to have for the new object.
  101. // ppvObj PPVOID in which to store the desired
  102. // interface pointer for the new object.
  103. //
  104. // Return Value:
  105. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  106. // if we cannot support the requested interface.
  107. //***************************************************************************
  108. STDMETHODIMP CDSClassProviderClassFactory :: CreateInstance (
  109. LPUNKNOWN pUnkOuter ,
  110. REFIID riid ,
  111. LPVOID FAR * ppvObject
  112. )
  113. {
  114. HRESULT status = S_OK ;
  115. // We do not support aggregation
  116. if ( pUnkOuter )
  117. {
  118. status = CLASS_E_NOAGGREGATION ;
  119. }
  120. else
  121. {
  122. // Check to see if the static members have been initialized
  123. // Create any initializer objects required for the classes
  124. EnterCriticalSection(&g_StaticsCreationDeletion);
  125. if(!s_pDSClassProviderInitializer)
  126. {
  127. BOOL bLogObjectAllocated = FALSE;
  128. try
  129. {
  130. g_pLogObject->WriteW(L"CDSClassProviderClassFactory::CreateInstance() called\r\n");
  131. s_pDSClassProviderInitializer = new CDSClassProviderInitializer();
  132. s_pLDAPClassProviderInitializer = new CLDAPClassProviderInitializer();
  133. }
  134. catch(Heap_Exception e_HE)
  135. {
  136. if ( s_pDSClassProviderInitializer )
  137. {
  138. delete s_pDSClassProviderInitializer;
  139. s_pDSClassProviderInitializer = NULL;
  140. }
  141. if ( s_pLDAPClassProviderInitializer )
  142. {
  143. delete s_pLDAPClassProviderInitializer;
  144. s_pLDAPClassProviderInitializer = NULL;
  145. }
  146. status = E_OUTOFMEMORY ;
  147. }
  148. }
  149. LeaveCriticalSection(&g_StaticsCreationDeletion);
  150. if(SUCCEEDED(status))
  151. {
  152. CLDAPClassProvider *lpunk = NULL;
  153. try
  154. {
  155. lpunk = new CLDAPClassProvider();
  156. status = lpunk->QueryInterface ( riid , ppvObject ) ;
  157. if ( FAILED ( status ) )
  158. {
  159. delete lpunk ;
  160. }
  161. }
  162. catch(Heap_Exception e_HE)
  163. {
  164. if ( lpunk )
  165. {
  166. delete lpunk ;
  167. lpunk = NULL;
  168. }
  169. status = E_OUTOFMEMORY ;
  170. }
  171. }
  172. }
  173. return status ;
  174. }
  175. //***************************************************************************
  176. //
  177. // CDSClassProviderClassFactory::LockServer
  178. //
  179. // Purpose:
  180. // Increments or decrements the lock count of the DLL. If the
  181. // lock count goes to zero and there are no objects, the DLL
  182. // is allowed to unload. See DllCanUnloadNow.
  183. //
  184. // Parameters:
  185. // fLock BOOL specifying whether to increment or
  186. // decrement the lock count.
  187. //
  188. // Return Value:
  189. // HRESULT NOERROR always.
  190. //***************************************************************************
  191. STDMETHODIMP CDSClassProviderClassFactory :: LockServer ( BOOL fLock )
  192. {
  193. if ( fLock )
  194. {
  195. InterlockedIncrement ( & g_lServerLocks ) ;
  196. }
  197. else
  198. {
  199. InterlockedDecrement ( & g_lServerLocks ) ;
  200. }
  201. return S_OK ;
  202. }
  203. //***************************************************************************
  204. //
  205. // CDSClassAssociationsProviderClassFactory::CDSClassAssociationsProviderClassFactory
  206. // CDSClassAssociationsProviderClassFactory::~CDSClassAssociationsProviderClassFactory
  207. //
  208. // Constructor Parameters:
  209. // None
  210. //***************************************************************************
  211. CDSClassAssociationsProviderClassFactory :: CDSClassAssociationsProviderClassFactory ()
  212. {
  213. m_ReferenceCount = 0 ;
  214. InterlockedIncrement(&g_lComponents);
  215. }
  216. CDSClassAssociationsProviderClassFactory::~CDSClassAssociationsProviderClassFactory ()
  217. {
  218. InterlockedDecrement(&g_lComponents);
  219. }
  220. //***************************************************************************
  221. //
  222. // CDSClassAssociationsProviderClassFactory::QueryInterface
  223. // CDSClassAssociationsProviderClassFactory::AddRef
  224. // CDSClassAssociationsProviderClassFactory::Release
  225. //
  226. // Purpose: Standard COM routines needed for all interfaces
  227. //
  228. //***************************************************************************
  229. STDMETHODIMP CDSClassAssociationsProviderClassFactory::QueryInterface (
  230. REFIID iid ,
  231. LPVOID FAR *iplpv
  232. )
  233. {
  234. *iplpv = NULL ;
  235. if ( iid == IID_IUnknown )
  236. {
  237. *iplpv = ( LPVOID ) this ;
  238. }
  239. else if ( iid == IID_IClassFactory )
  240. {
  241. *iplpv = ( LPVOID ) this ;
  242. }
  243. else
  244. {
  245. return E_NOINTERFACE;
  246. }
  247. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  248. return S_OK;
  249. }
  250. STDMETHODIMP_( ULONG ) CDSClassAssociationsProviderClassFactory :: AddRef ()
  251. {
  252. return InterlockedIncrement ( & m_ReferenceCount ) ;
  253. }
  254. STDMETHODIMP_(ULONG) CDSClassAssociationsProviderClassFactory :: Release ()
  255. {
  256. LONG ref ;
  257. if ( ( ref = InterlockedDecrement ( & m_ReferenceCount ) ) == 0 )
  258. {
  259. delete this ;
  260. return 0 ;
  261. }
  262. else
  263. {
  264. return ref ;
  265. }
  266. }
  267. //***************************************************************************
  268. //
  269. // CDSClassAssociationsProviderClassFactory::CreateInstance
  270. //
  271. // Purpose: Instantiates a Provider object returning an interface pointer.
  272. //
  273. // Parameters:
  274. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  275. // being used in an aggregation.
  276. // riid REFIID identifying the interface the caller
  277. // desires to have for the new object.
  278. // ppvObj PPVOID in which to store the desired
  279. // interface pointer for the new object.
  280. //
  281. // Return Value:
  282. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  283. // if we cannot support the requested interface.
  284. //***************************************************************************
  285. STDMETHODIMP CDSClassAssociationsProviderClassFactory :: CreateInstance (
  286. LPUNKNOWN pUnkOuter ,
  287. REFIID riid ,
  288. LPVOID FAR * ppvObject
  289. )
  290. {
  291. HRESULT status = S_OK ;
  292. // We do not support aggregation
  293. if ( pUnkOuter )
  294. {
  295. status = CLASS_E_NOAGGREGATION ;
  296. }
  297. else
  298. {
  299. CLDAPClassAsssociationsProvider *lpunk = NULL;
  300. // Check to see if the static members have been initialized
  301. // Create any initializer objects required for the classes
  302. EnterCriticalSection(&g_StaticsCreationDeletion);
  303. BOOL bLogObjectAllocated = FALSE;
  304. try
  305. {
  306. g_pLogObject->WriteW(L"CDSClassAssociationsProviderClassFactory::CreateInstance() called\r\n");
  307. lpunk = new CLDAPClassAsssociationsProvider();
  308. status = lpunk->QueryInterface ( riid , ppvObject ) ;
  309. if ( FAILED ( status ) )
  310. {
  311. delete lpunk ;
  312. }
  313. }
  314. catch(Heap_Exception e_HE)
  315. {
  316. if ( lpunk )
  317. {
  318. delete lpunk;
  319. lpunk = NULL;
  320. }
  321. status = E_OUTOFMEMORY ;
  322. }
  323. LeaveCriticalSection(&g_StaticsCreationDeletion);
  324. }
  325. return status ;
  326. }
  327. //***************************************************************************
  328. //
  329. // CDSClassAssociationsProviderClassFactory::LockServer
  330. //
  331. // Purpose:
  332. // Increments or decrements the lock count of the DLL. If the
  333. // lock count goes to zero and there are no objects, the DLL
  334. // is allowed to unload. See DllCanUnloadNow.
  335. //
  336. // Parameters:
  337. // fLock BOOL specifying whether to increment or
  338. // decrement the lock count.
  339. //
  340. // Return Value:
  341. // HRESULT NOERROR always.
  342. //***************************************************************************
  343. STDMETHODIMP CDSClassAssociationsProviderClassFactory :: LockServer ( BOOL fLock )
  344. {
  345. if ( fLock )
  346. {
  347. InterlockedIncrement ( & g_lServerLocks ) ;
  348. }
  349. else
  350. {
  351. InterlockedDecrement ( & g_lServerLocks ) ;
  352. }
  353. return S_OK ;
  354. }