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.

241 lines
4.1 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. classfac.cxx
  5. Abstract:
  6. Implements the Class Factory for the SENS Subscriber.
  7. Author:
  8. Gopal Parupudi <GopalP>
  9. [Notes:]
  10. optional-notes
  11. Revision History:
  12. GopalP 11/17/1997 Start.
  13. --*/
  14. #include <common.hxx>
  15. #include <ole2.h>
  16. #include <sensevts.h>
  17. #include "sinkcomn.hxx"
  18. #include "classfac.hxx"
  19. #include "cimpnet.hxx"
  20. #include "cimplogn.hxx"
  21. //
  22. // Global counts for the number of objects in the server and the number of
  23. // locks.
  24. //
  25. ULONG g_cObj = 0L;
  26. ULONG g_cLock = 0L;
  27. //
  28. // Constructor and Destructor
  29. //
  30. CSensSinkCF::CSensSinkCF(
  31. void
  32. ) : m_cRef(1L)
  33. {
  34. }
  35. CSensSinkCF::~CSensSinkCF(
  36. void
  37. )
  38. {
  39. // Empty Destructor.
  40. }
  41. //
  42. // QI
  43. //
  44. STDMETHODIMP
  45. CSensSinkCF::QueryInterface(
  46. REFIID riid,
  47. LPVOID *ppv
  48. )
  49. {
  50. HRESULT hr = S_OK;
  51. *ppv = NULL; // To handle failure cases
  52. // IUnknown or IClassFactory
  53. if (IsEqualIID(riid, IID_IUnknown) ||
  54. IsEqualIID(riid, IID_IClassFactory))
  55. {
  56. *ppv = (LPUNKNOWN) this;
  57. }
  58. else
  59. {
  60. hr = E_NOINTERFACE;
  61. }
  62. if (NULL != *ppv)
  63. {
  64. ((LPUNKNOWN)*ppv)->AddRef();
  65. }
  66. return hr;
  67. }
  68. //
  69. // AddRef
  70. //
  71. STDMETHODIMP_(ULONG)
  72. CSensSinkCF::AddRef(
  73. void
  74. )
  75. {
  76. return InterlockedIncrement((PLONG) &m_cRef);
  77. }
  78. //
  79. // Release
  80. //
  81. STDMETHODIMP_(ULONG)
  82. CSensSinkCF::Release(
  83. void
  84. )
  85. {
  86. ULONG cRefT;
  87. cRefT = InterlockedDecrement((PLONG) &m_cRef);
  88. if (0 == m_cRef)
  89. {
  90. // Invoke the callback function.
  91. ObjectDestroyed();
  92. delete this;
  93. }
  94. return cRefT;
  95. }
  96. //
  97. // CreateInstance
  98. //
  99. STDMETHODIMP
  100. CSensSinkCF::CreateInstance(
  101. LPUNKNOWN pUnkOuter,
  102. REFIID riid,
  103. LPVOID *ppvObj
  104. )
  105. {
  106. LPCIMPISENSNETWORK pObjNet;
  107. LPCIMPISENSLOGON pObjLogn;
  108. HRESULT hr;
  109. DebugTraceGuid("CSensSinkCF::CreateInstance()", riid);
  110. hr = E_OUTOFMEMORY;
  111. *ppvObj = NULL;
  112. pObjNet = NULL;
  113. pObjLogn = NULL;
  114. //
  115. // Return the appropriate interface pointer.
  116. //
  117. if (IsEqualIID(riid, IID_ISensNetwork) ||
  118. IsEqualIID(riid, IID_IUnknown))
  119. {
  120. SensPrintA(SENS_INFO, ("\t| ClassFactory::CreateInstance(ISensNetwork)\n"));
  121. pObjNet = new CImpISensNetwork(ObjectDestroyed);
  122. if (NULL != pObjNet)
  123. {
  124. hr = pObjNet->QueryInterface(riid, ppvObj);
  125. SensPrintA(SENS_INFO, ("\t| QI on CImpISensNetwork returned 0x%x\n", hr));
  126. }
  127. }
  128. else
  129. if (IsEqualIID(riid, IID_ISensLogon))
  130. {
  131. SensPrintA(SENS_INFO, ("\t| ClassFactory::CreateInstance(ISensLogon)\n"));
  132. pObjLogn = new CImpISensLogon(ObjectDestroyed);
  133. if (NULL != pObjLogn)
  134. {
  135. hr = pObjLogn->QueryInterface(riid, ppvObj);
  136. SensPrintA(SENS_INFO, ("\t| QI on CImpISensLogon returned 0x%x\n", hr));
  137. }
  138. }
  139. else
  140. {
  141. hr = E_NOINTERFACE;
  142. }
  143. if (NULL != *ppvObj)
  144. {
  145. InterlockedIncrement((PLONG) &g_cObj);
  146. }
  147. SensPrintA(SENS_INFO, ("\t| Returning 0x%x from CF:CreateInstance\n", hr));
  148. return hr;
  149. }
  150. //
  151. // LockServer
  152. //
  153. STDMETHODIMP
  154. CSensSinkCF::LockServer(
  155. BOOL fLock
  156. )
  157. {
  158. if (fLock)
  159. {
  160. InterlockedIncrement((PLONG) &g_cLock);
  161. }
  162. else
  163. {
  164. InterlockedDecrement((PLONG) &g_cLock);
  165. InterlockedIncrement((PLONG) &g_cObj);
  166. ObjectDestroyed(); // this does a --g_cObj
  167. }
  168. return NOERROR;
  169. }
  170. //
  171. // ObjectDestroyed
  172. //
  173. void FAR PASCAL
  174. ObjectDestroyed(
  175. void
  176. )
  177. {
  178. if ((0 == InterlockedDecrement((PLONG) &g_cObj)) &&
  179. (0 == g_cLock))
  180. {
  181. SensPrintA(SENS_INFO, ("\t| ObjectDestroyed: g_cObj = %d and g_cLock = %d\n", g_cObj, g_cLock));
  182. SensPrintA(SENS_INFO, ("\t| Shutting down the app. Calling PostQuitMessage(0)\n"));
  183. PostQuitMessage(0);
  184. }
  185. }