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.

201 lines
4.7 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. CLASSFAC.CPP
  5. Abstract:
  6. Contains the class factory. This creates objects when
  7. connections are requested.
  8. History:
  9. a-davj 04-Mar-97 Created.
  10. --*/
  11. #include "precomp.h"
  12. #include <wbemidl.h>
  13. #include <wbemint.h>
  14. #include <reg.h>
  15. #include <strsafe.h>
  16. #include "wbemprox.h"
  17. #include "locator.h"
  18. #include "cprovloc.h"
  19. #include "comtrans.h"
  20. //***************************************************************************
  21. //
  22. // CLocatorFactory::CLocatorFactory
  23. //
  24. // DESCRIPTION:
  25. //
  26. // Constructor
  27. //
  28. //***************************************************************************
  29. CLocatorFactory::CLocatorFactory(DWORD dwType)
  30. {
  31. m_cRef=0L;
  32. m_dwType = dwType;
  33. InterlockedIncrement(&g_cObj);
  34. return;
  35. }
  36. //***************************************************************************
  37. //
  38. // CLocatorFactory::~CLocatorFactory
  39. //
  40. // DESCRIPTION:
  41. //
  42. // Destructor
  43. //
  44. //***************************************************************************
  45. CLocatorFactory::~CLocatorFactory(void)
  46. {
  47. InterlockedDecrement(&g_cObj);
  48. return;
  49. }
  50. //***************************************************************************
  51. //
  52. // CLocatorFactory::QueryInterface
  53. // CLocatorFactory::AddRef
  54. // CLocatorFactory::Release
  55. //
  56. // Purpose: Standard Ole routines needed for all interfaces
  57. //
  58. //***************************************************************************
  59. STDMETHODIMP CLocatorFactory::QueryInterface(REFIID riid
  60. , PPVOID ppv)
  61. {
  62. *ppv=NULL;
  63. if (IID_IUnknown==riid || IID_IClassFactory==riid)
  64. *ppv=this;
  65. if (NULL!=*ppv)
  66. {
  67. ((LPUNKNOWN)*ppv)->AddRef();
  68. return NOERROR;
  69. }
  70. return ResultFromScode(E_NOINTERFACE);
  71. }
  72. STDMETHODIMP_(ULONG) CLocatorFactory::AddRef(void)
  73. {
  74. InterlockedIncrement(&m_cRef);
  75. return m_cRef;
  76. }
  77. STDMETHODIMP_(ULONG) CLocatorFactory::Release(void)
  78. {
  79. long lTemp = InterlockedDecrement(&m_cRef);
  80. if (0L!=lTemp)
  81. return m_cRef;
  82. delete this;
  83. return 0L;
  84. }
  85. //***************************************************************************
  86. //
  87. // SCODE CLocatorFactory::CreateInstance
  88. //
  89. // Description:
  90. //
  91. // Instantiates a Provider object returning an interface pointer.
  92. //
  93. // Parameters:
  94. //
  95. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  96. // being used in an aggregation.
  97. // riid REFIID identifying the interface the caller
  98. // desires to have for the new object.
  99. // ppvObj PPVOID in which to store the desired
  100. // interface pointer for the new object.
  101. //
  102. // Return Value:
  103. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  104. // if we cannot support the requested interface.
  105. //***************************************************************************
  106. STDMETHODIMP CLocatorFactory::CreateInstance(
  107. IN LPUNKNOWN pUnkOuter,
  108. IN REFIID riid,
  109. OUT PPVOID ppvObj)
  110. {
  111. IUnknown * pObj = NULL;
  112. HRESULT hr;
  113. *ppvObj=NULL;
  114. hr=E_OUTOFMEMORY;
  115. // This object doesnt support aggregation.
  116. if (NULL!=pUnkOuter)
  117. return ResultFromScode(CLASS_E_NOAGGREGATION);
  118. //Create the object passing function to notify on destruction.
  119. if(m_dwType == LOCATOR)
  120. pObj=new CLocator();
  121. else if(m_dwType == ADMINLOC)
  122. pObj= new CProviderLoc(ADMINLOC);
  123. else if(m_dwType == AUTHLOC)
  124. pObj= new CProviderLoc(AUTHLOC);
  125. else if(m_dwType == UNAUTHLOC)
  126. pObj= new CProviderLoc(UNAUTHLOC);
  127. if (NULL==pObj)
  128. return hr;
  129. hr=pObj->QueryInterface(riid, ppvObj);
  130. //Kill the object if initial creation or Init failed.
  131. if (FAILED(hr))
  132. delete pObj;
  133. return hr;
  134. }
  135. //***************************************************************************
  136. //
  137. // SCODE CLocatorFactory::LockServer
  138. //
  139. // Description:
  140. //
  141. // Increments or decrements the lock count of the DLL. If the
  142. // lock count goes to zero and there are no objects, the DLL
  143. // is allowed to unload. See DllCanUnloadNow.
  144. //
  145. // Parameters:
  146. //
  147. // fLock BOOL specifying whether to increment or
  148. // decrement the lock count.
  149. //
  150. // Return Value:
  151. //
  152. // HRESULT NOERROR always.
  153. //***************************************************************************
  154. STDMETHODIMP CLocatorFactory::LockServer(IN BOOL fLock)
  155. {
  156. if (fLock)
  157. InterlockedIncrement((long *)&g_cLock);
  158. else
  159. InterlockedDecrement((long *)&g_cLock);
  160. return NOERROR;
  161. }