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.

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