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.

222 lines
4.6 KiB

  1. #ifndef __CLASSFACTORY_CPP
  2. #define __CLASSFACTORY_CPP
  3. /*++
  4. Copyright (C) 1996-2001 Microsoft Corporation
  5. Module Name:
  6. ClassFac.cpp
  7. Abstract:
  8. History:
  9. --*/
  10. #include "PreComp.h"
  11. #include <wbemint.h>
  12. #include "Globals.h"
  13. #include "CGlobals.h"
  14. #include "ProvResv.h"
  15. #include "ProvFact.h"
  16. #include "ProvSubS.h"
  17. #include "classfac.h"
  18. /******************************************************************************
  19. *
  20. * Name:
  21. *
  22. *
  23. * Description:
  24. *
  25. *
  26. *****************************************************************************/
  27. template <class Object,class ObjectInterface>
  28. CServerClassFactory <Object,ObjectInterface> :: CServerClassFactory <Object,ObjectInterface> () : m_ReferenceCount ( 0 )
  29. {
  30. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_CServerClassFactory_ObjectsInProgress ) ;
  31. ProviderSubSystem_Globals :: Increment_Global_Object_Count () ;
  32. }
  33. /******************************************************************************
  34. *
  35. * Name:
  36. *
  37. *
  38. * Description:
  39. *
  40. *
  41. *****************************************************************************/
  42. template <class Object,class ObjectInterface>
  43. CServerClassFactory <Object,ObjectInterface> :: ~CServerClassFactory <Object,ObjectInterface> ()
  44. {
  45. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_CServerClassFactory_ObjectsInProgress ) ;
  46. ProviderSubSystem_Globals :: Decrement_Global_Object_Count () ;
  47. }
  48. /******************************************************************************
  49. *
  50. * Name:
  51. *
  52. *
  53. * Description:
  54. *
  55. *
  56. *****************************************************************************/
  57. template <class Object,class ObjectInterface>
  58. STDMETHODIMP CServerClassFactory <Object,ObjectInterface> :: QueryInterface (
  59. REFIID iid ,
  60. LPVOID FAR *iplpv
  61. )
  62. {
  63. *iplpv = NULL ;
  64. if ( iid == IID_IUnknown )
  65. {
  66. *iplpv = ( LPVOID ) this ;
  67. }
  68. else if ( iid == IID_IClassFactory )
  69. {
  70. *iplpv = ( LPVOID ) ( IClassFactory * ) this ;
  71. }
  72. if ( *iplpv )
  73. {
  74. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  75. return ResultFromScode ( S_OK ) ;
  76. }
  77. else
  78. {
  79. return ResultFromScode ( E_NOINTERFACE ) ;
  80. }
  81. }
  82. /******************************************************************************
  83. *
  84. * Name:
  85. *
  86. *
  87. * Description:
  88. *
  89. *
  90. *****************************************************************************/
  91. template <class Object,class ObjectInterface>
  92. STDMETHODIMP_( ULONG ) CServerClassFactory <Object,ObjectInterface> :: AddRef ()
  93. {
  94. ULONG t_ReferenceCount = InterlockedIncrement ( & m_ReferenceCount ) ;
  95. return t_ReferenceCount ;
  96. }
  97. /******************************************************************************
  98. *
  99. * Name:
  100. *
  101. *
  102. * Description:
  103. *
  104. *
  105. *****************************************************************************/
  106. template <class Object,class ObjectInterface>
  107. STDMETHODIMP_(ULONG) CServerClassFactory <Object,ObjectInterface> :: Release ()
  108. {
  109. ULONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  110. if ( t_ReferenceCount == 0 )
  111. {
  112. delete this ;
  113. return 0 ;
  114. }
  115. else
  116. {
  117. return t_ReferenceCount ;
  118. }
  119. }
  120. /******************************************************************************
  121. *
  122. * Name:
  123. *
  124. *
  125. * Description:
  126. *
  127. *
  128. *****************************************************************************/
  129. template <class Object,class ObjectInterface>
  130. STDMETHODIMP CServerClassFactory <Object,ObjectInterface> :: CreateInstance (
  131. LPUNKNOWN pUnkOuter ,
  132. REFIID riid ,
  133. LPVOID FAR * ppvObject
  134. )
  135. {
  136. HRESULT status = S_OK ;
  137. if ( pUnkOuter )
  138. {
  139. status = CLASS_E_NOAGGREGATION ;
  140. }
  141. else
  142. {
  143. IUnknown *lpunk = ( ObjectInterface * ) new Object ( *ProviderSubSystem_Globals :: s_Allocator );
  144. if ( lpunk == NULL )
  145. {
  146. status = E_OUTOFMEMORY ;
  147. }
  148. else
  149. {
  150. status = lpunk->QueryInterface ( riid , ppvObject ) ;
  151. if ( FAILED ( status ) )
  152. {
  153. delete lpunk ;
  154. }
  155. else
  156. {
  157. }
  158. }
  159. }
  160. return status ;
  161. }
  162. /******************************************************************************
  163. *
  164. * Name:
  165. *
  166. *
  167. * Description:
  168. *
  169. *
  170. *****************************************************************************/
  171. template <class Object,class ObjectInterface>
  172. STDMETHODIMP CServerClassFactory <Object,ObjectInterface> :: LockServer ( BOOL fLock )
  173. {
  174. /*
  175. * Place code in critical section
  176. */
  177. if ( fLock )
  178. {
  179. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_LocksInProgress ) ;
  180. }
  181. else
  182. {
  183. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_LocksInProgress ) ;
  184. }
  185. return S_OK ;
  186. }
  187. #endif __CLASSFACTORY_CPP