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