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.

184 lines
4.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Confidential. Copyright (c) Microsoft Corporation 1999. All rights reserved
  4. //
  5. // File: Factory.cpp
  6. //
  7. // Description:
  8. //
  9. // History: 8-20-99 leonardm Created
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////////
  12. #include "uenv.h"
  13. #include "Factory.h"
  14. #include "diagprov.h"
  15. extern long g_cLock;
  16. ///////////////////////////////////////////////////////////////////////////////////
  17. //
  18. // Function:
  19. //
  20. // Description:
  21. //
  22. // Parameters:
  23. //
  24. // Return:
  25. //
  26. // History: 8/20/99 leonardm Created.
  27. //
  28. ///////////////////////////////////////////////////////////////////////////////////
  29. CProvFactory::CProvFactory() : m_cRef(1)
  30. {
  31. }
  32. ///////////////////////////////////////////////////////////////////////////////////
  33. //
  34. // Function:
  35. //
  36. // Description:
  37. //
  38. // Parameters:
  39. //
  40. // Return:
  41. //
  42. // History: 8/20/99 leonardm Created.
  43. //
  44. ///////////////////////////////////////////////////////////////////////////////////
  45. CProvFactory::~CProvFactory()
  46. {
  47. }
  48. ///////////////////////////////////////////////////////////////////////////////////
  49. //
  50. // Function:
  51. //
  52. // Description:
  53. //
  54. // Parameters:
  55. //
  56. // Return:
  57. //
  58. // History: 8/20/99 leonardm Created.
  59. //
  60. ///////////////////////////////////////////////////////////////////////////////////
  61. STDMETHODIMP CProvFactory::QueryInterface(REFIID riid, LPVOID* ppv)
  62. {
  63. if ( riid == IID_IUnknown || riid == IID_IClassFactory )
  64. {
  65. *ppv = this;
  66. AddRef();
  67. return S_OK;
  68. }
  69. else
  70. {
  71. *ppv = NULL;
  72. return E_NOINTERFACE;
  73. }
  74. }
  75. ///////////////////////////////////////////////////////////////////////////////////
  76. //
  77. // Function:
  78. //
  79. // Description:
  80. //
  81. // Parameters:
  82. //
  83. // Return:
  84. //
  85. // History: 8/20/99 leonardm Created.
  86. //
  87. ///////////////////////////////////////////////////////////////////////////////////
  88. STDMETHODIMP_(ULONG) CProvFactory::AddRef()
  89. {
  90. return InterlockedIncrement(&m_cRef);
  91. }
  92. ///////////////////////////////////////////////////////////////////////////////////
  93. //
  94. // Function:
  95. //
  96. // Description:
  97. //
  98. // Parameters:
  99. //
  100. // Return:
  101. //
  102. // History: 8/20/99 leonardm Created.
  103. //
  104. ///////////////////////////////////////////////////////////////////////////////////
  105. STDMETHODIMP_( ULONG ) CProvFactory::Release()
  106. {
  107. if (!InterlockedDecrement(&m_cRef))
  108. {
  109. delete this;
  110. return 0;
  111. }
  112. return m_cRef;
  113. }
  114. ///////////////////////////////////////////////////////////////////////////////////
  115. //
  116. // Function:
  117. //
  118. // Description:
  119. //
  120. // Parameters:
  121. //
  122. // Return:
  123. //
  124. // History: 8/20/99 leonardm Created.
  125. //
  126. ///////////////////////////////////////////////////////////////////////////////////
  127. STDMETHODIMP CProvFactory::CreateInstance(LPUNKNOWN punk, REFIID riid, LPVOID* ppv)
  128. {
  129. *ppv = NULL;
  130. if(punk != NULL)
  131. {
  132. return CLASS_E_NOAGGREGATION;
  133. }
  134. CSnapProv* pProvider = new CSnapProv();
  135. if (pProvider == NULL)
  136. {
  137. return E_OUTOFMEMORY;
  138. }
  139. HRESULT hr = pProvider->QueryInterface(riid, ppv);
  140. pProvider->Release();
  141. return hr;
  142. return S_OK;
  143. }
  144. ///////////////////////////////////////////////////////////////////////////////////
  145. //
  146. // Function:
  147. //
  148. // Description:
  149. //
  150. // Parameters:
  151. //
  152. // Return:
  153. //
  154. // History: 8/20/99 leonardm Created.
  155. //
  156. ///////////////////////////////////////////////////////////////////////////////////
  157. STDMETHODIMP CProvFactory::LockServer(BOOL bLock)
  158. {
  159. if (bLock)
  160. {
  161. InterlockedIncrement( &g_cLock );
  162. }
  163. else
  164. {
  165. InterlockedDecrement( &g_cLock );
  166. }
  167. return S_OK;
  168. }