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.

228 lines
5.4 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: 9/16/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 Instance Provider factory.
  18. //
  19. //***************************************************************************
  20. #include "precomp.h"
  21. CDSInstanceProviderInitializer *CDSInstanceProviderClassFactory::s_pDSInstanceProviderInitializer = NULL;
  22. //***************************************************************************
  23. //
  24. // CDSInstanceProviderClassFactory::CDSInstanceProviderClassFactory
  25. // CDSInstanceProviderClassFactory::~CDSInstanceProviderClassFactory
  26. //
  27. // Constructor Parameters:
  28. // None
  29. //***************************************************************************
  30. CDSInstanceProviderClassFactory :: CDSInstanceProviderClassFactory ()
  31. {
  32. m_ReferenceCount = 0 ;
  33. InterlockedIncrement(&g_lComponents);
  34. }
  35. CDSInstanceProviderClassFactory::~CDSInstanceProviderClassFactory ()
  36. {
  37. InterlockedDecrement(&g_lComponents);
  38. }
  39. //***************************************************************************
  40. //
  41. // CDSInstanceProviderClassFactory::QueryInterface
  42. // CDSInstanceProviderClassFactory::AddRef
  43. // CDSInstanceProviderClassFactory::Release
  44. //
  45. // Purpose: Standard COM routines needed for all interfaces
  46. //
  47. //***************************************************************************
  48. STDMETHODIMP CDSInstanceProviderClassFactory::QueryInterface (
  49. REFIID iid ,
  50. LPVOID FAR *iplpv
  51. )
  52. {
  53. *iplpv = NULL ;
  54. if ( iid == IID_IUnknown )
  55. {
  56. *iplpv = ( LPVOID ) this ;
  57. }
  58. else if ( iid == IID_IClassFactory )
  59. {
  60. *iplpv = ( LPVOID ) this ;
  61. }
  62. else
  63. {
  64. return E_NOINTERFACE;
  65. }
  66. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  67. return S_OK;
  68. }
  69. STDMETHODIMP_( ULONG ) CDSInstanceProviderClassFactory :: AddRef ()
  70. {
  71. return InterlockedIncrement ( & m_ReferenceCount ) ;
  72. }
  73. STDMETHODIMP_(ULONG) CDSInstanceProviderClassFactory :: Release ()
  74. {
  75. LONG ref ;
  76. if ( ( ref = InterlockedDecrement ( & m_ReferenceCount ) ) == 0 )
  77. {
  78. delete this ;
  79. return 0 ;
  80. }
  81. else
  82. {
  83. return ref ;
  84. }
  85. }
  86. //***************************************************************************
  87. //
  88. // CDSInstanceProviderClassFactory::CreateInstance
  89. //
  90. // Purpose: Instantiates a Provider object returning an interface pointer.
  91. //
  92. // Parameters:
  93. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  94. // being used in an aggregation.
  95. // riid REFIID identifying the interface the caller
  96. // desires to have for the new object.
  97. // ppvObj PPVOID in which to store the desired
  98. // interface pointer for the new object.
  99. //
  100. // Return Value:
  101. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  102. // if we cannot support the requested interface.
  103. //***************************************************************************
  104. STDMETHODIMP CDSInstanceProviderClassFactory :: CreateInstance (
  105. LPUNKNOWN pUnkOuter ,
  106. REFIID riid ,
  107. LPVOID FAR * ppvObject
  108. )
  109. {
  110. HRESULT status = S_OK ;
  111. // We do not support aggregation
  112. if ( pUnkOuter )
  113. {
  114. status = CLASS_E_NOAGGREGATION ;
  115. }
  116. else
  117. {
  118. // Check to see if the static members have been initialized
  119. // Create any initializer objects required for the classes
  120. EnterCriticalSection(&g_StaticsCreationDeletion);
  121. if(!s_pDSInstanceProviderInitializer)
  122. {
  123. BOOL bLocObjectAllocated = FALSE;
  124. try
  125. {
  126. // This might have been created by the CreateInstance() function of the
  127. // other DS Providers (Class, ClassAssociation)
  128. if( !g_pLogObject )
  129. {
  130. g_pLogObject = new ProvDebugLog(DSPROVIDER);
  131. bLocObjectAllocated = TRUE;
  132. }
  133. g_pLogObject->WriteW(L"CDSInstanceProviderClassFactory::CreateInstance() called\r\n");
  134. s_pDSInstanceProviderInitializer = new CDSInstanceProviderInitializer();
  135. }
  136. catch(Heap_Exception e_HE)
  137. {
  138. if ( bLocObjectAllocated && g_pLogObject )
  139. {
  140. delete g_pLogObject;
  141. g_pLogObject = NULL;
  142. }
  143. if ( s_pDSInstanceProviderInitializer )
  144. {
  145. delete s_pDSInstanceProviderInitializer;
  146. s_pDSInstanceProviderInitializer = NULL;
  147. }
  148. status = E_OUTOFMEMORY ;
  149. }
  150. }
  151. LeaveCriticalSection(&g_StaticsCreationDeletion);
  152. if(SUCCEEDED(status))
  153. {
  154. CLDAPInstanceProvider *lpunk = NULL;
  155. try
  156. {
  157. lpunk = new CLDAPInstanceProvider();
  158. status = lpunk->QueryInterface ( riid , ppvObject ) ;
  159. if ( FAILED ( status ) )
  160. {
  161. delete lpunk ;
  162. }
  163. }
  164. catch(Heap_Exception e_HE)
  165. {
  166. status = E_OUTOFMEMORY ;
  167. }
  168. }
  169. }
  170. return status ;
  171. }
  172. //***************************************************************************
  173. //
  174. // CDSInstanceProviderClassFactory::LockServer
  175. //
  176. // Purpose:
  177. // Increments or decrements the lock count of the DLL. If the
  178. // lock count goes to zero and there are no objects, the DLL
  179. // is allowed to unload. See DllCanUnloadNow.
  180. //
  181. // Parameters:
  182. // fLock BOOL specifying whether to increment or
  183. // decrement the lock count.
  184. //
  185. // Return Value:
  186. // HRESULT NOERROR always.
  187. //***************************************************************************
  188. STDMETHODIMP CDSInstanceProviderClassFactory :: LockServer ( BOOL fLock )
  189. {
  190. if ( fLock )
  191. {
  192. InterlockedIncrement ( & g_lServerLocks ) ;
  193. }
  194. else
  195. {
  196. InterlockedDecrement ( & g_lServerLocks ) ;
  197. }
  198. return S_OK ;
  199. }