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.

214 lines
5.3 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. g_pLogObject->WriteW(L"CDSInstanceProviderClassFactory::CreateInstance() called\r\n");
  127. s_pDSInstanceProviderInitializer = new CDSInstanceProviderInitializer();
  128. }
  129. catch(Heap_Exception e_HE)
  130. {
  131. if ( s_pDSInstanceProviderInitializer )
  132. {
  133. delete s_pDSInstanceProviderInitializer;
  134. s_pDSInstanceProviderInitializer = NULL;
  135. }
  136. status = E_OUTOFMEMORY ;
  137. }
  138. }
  139. LeaveCriticalSection(&g_StaticsCreationDeletion);
  140. if(SUCCEEDED(status))
  141. {
  142. CLDAPInstanceProvider *lpunk = NULL;
  143. try
  144. {
  145. lpunk = new CLDAPInstanceProvider();
  146. status = lpunk->QueryInterface ( riid , ppvObject ) ;
  147. if ( FAILED ( status ) )
  148. {
  149. delete lpunk ;
  150. }
  151. }
  152. catch(Heap_Exception e_HE)
  153. {
  154. status = E_OUTOFMEMORY ;
  155. }
  156. }
  157. }
  158. return status ;
  159. }
  160. //***************************************************************************
  161. //
  162. // CDSInstanceProviderClassFactory::LockServer
  163. //
  164. // Purpose:
  165. // Increments or decrements the lock count of the DLL. If the
  166. // lock count goes to zero and there are no objects, the DLL
  167. // is allowed to unload. See DllCanUnloadNow.
  168. //
  169. // Parameters:
  170. // fLock BOOL specifying whether to increment or
  171. // decrement the lock count.
  172. //
  173. // Return Value:
  174. // HRESULT NOERROR always.
  175. //***************************************************************************
  176. STDMETHODIMP CDSInstanceProviderClassFactory :: LockServer ( BOOL fLock )
  177. {
  178. if ( fLock )
  179. {
  180. InterlockedIncrement ( & g_lServerLocks ) ;
  181. }
  182. else
  183. {
  184. InterlockedDecrement ( & g_lServerLocks ) ;
  185. }
  186. return S_OK ;
  187. }