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.

376 lines
6.0 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. cfaclogn.cxx
  5. Abstract:
  6. Implements the Class Factory for the SENS ISensLogon 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 "cfaclogn.hxx"
  19. #include "cimplogn.hxx"
  20. //
  21. // Global counts for the number of objects in the server and the number of
  22. // locks.
  23. //
  24. extern ULONG g_cObj;
  25. extern ULONG g_cLock;
  26. //
  27. // Constructor and Destructor
  28. //
  29. CISensLogonCF::CISensLogonCF(
  30. void
  31. ) : m_cRef(1L)
  32. {
  33. }
  34. CISensLogonCF::~CISensLogonCF(
  35. void
  36. )
  37. {
  38. // Empty Destructor.
  39. }
  40. //
  41. // QI
  42. //
  43. STDMETHODIMP
  44. CISensLogonCF::QueryInterface(
  45. REFIID riid,
  46. LPVOID *ppv
  47. )
  48. {
  49. HRESULT hr = S_OK;
  50. *ppv = NULL; // To handle failure cases
  51. // IUnknown or IClassFactory
  52. if (IsEqualIID(riid, IID_IUnknown) ||
  53. IsEqualIID(riid, IID_IClassFactory))
  54. {
  55. *ppv = (LPUNKNOWN) this;
  56. }
  57. else
  58. {
  59. hr = E_NOINTERFACE;
  60. }
  61. if (NULL != *ppv)
  62. {
  63. ((LPUNKNOWN)*ppv)->AddRef();
  64. }
  65. return hr;
  66. }
  67. //
  68. // AddRef
  69. //
  70. STDMETHODIMP_(ULONG)
  71. CISensLogonCF::AddRef(
  72. void
  73. )
  74. {
  75. return InterlockedIncrement((PLONG) &m_cRef);
  76. }
  77. //
  78. // Release
  79. //
  80. STDMETHODIMP_(ULONG)
  81. CISensLogonCF::Release(
  82. void
  83. )
  84. {
  85. ULONG cRefT;
  86. cRefT = InterlockedDecrement((PLONG) &m_cRef);
  87. if (0 == m_cRef)
  88. {
  89. // Invoke the callback function.
  90. ObjectDestroyed();
  91. delete this;
  92. }
  93. return cRefT;
  94. }
  95. //
  96. // CreateInstance
  97. //
  98. STDMETHODIMP
  99. CISensLogonCF::CreateInstance(
  100. LPUNKNOWN pUnkOuter,
  101. REFIID riid,
  102. LPVOID *ppvObj
  103. )
  104. {
  105. LPCIMPISENSLOGON pObjLogn;
  106. HRESULT hr;
  107. DebugTraceGuid("CISensLogonCF::CreateInstance()", riid);
  108. hr = E_OUTOFMEMORY;
  109. *ppvObj = NULL;
  110. pObjLogn = NULL;
  111. //
  112. // Return the appropriate interface pointer.
  113. //
  114. if (IsEqualIID(riid, IID_ISensLogon) ||
  115. IsEqualIID(riid, IID_IUnknown))
  116. {
  117. SensPrintA(SENS_INFO, ("\t| ClassFactory::CreateInstance(ISensLogon)\n"));
  118. pObjLogn = new CImpISensLogon(ObjectDestroyed);
  119. if (NULL != pObjLogn)
  120. {
  121. hr = pObjLogn->QueryInterface(riid, ppvObj);
  122. SensPrintA(SENS_INFO, ("\t| QI on CImpISensLogon returned 0x%x\n", hr));
  123. }
  124. }
  125. else
  126. {
  127. hr = E_NOINTERFACE;
  128. }
  129. if (NULL != *ppvObj)
  130. {
  131. InterlockedIncrement((PLONG) &g_cObj);
  132. }
  133. SensPrintA(SENS_INFO, ("\t| Returning 0x%x from CF:CreateInstance\n", hr));
  134. return hr;
  135. }
  136. //
  137. // LockServer
  138. //
  139. STDMETHODIMP
  140. CISensLogonCF::LockServer(
  141. BOOL fLock
  142. )
  143. {
  144. if (fLock)
  145. {
  146. InterlockedIncrement((PLONG) &g_cLock);
  147. }
  148. else
  149. {
  150. InterlockedDecrement((PLONG) &g_cLock);
  151. InterlockedIncrement((PLONG) &g_cObj);
  152. ObjectDestroyed(); // this does a --g_cObj
  153. }
  154. return NOERROR;
  155. }
  156. //
  157. // Class Factory for ISensLogon2 implementation
  158. //
  159. //
  160. // Constructor and Destructor
  161. //
  162. CISensLogon2CF::CISensLogon2CF(
  163. void
  164. ) : m_cRef(1L)
  165. {
  166. }
  167. CISensLogon2CF::~CISensLogon2CF(
  168. void
  169. )
  170. {
  171. // Empty Destructor.
  172. }
  173. //
  174. // QI
  175. //
  176. STDMETHODIMP
  177. CISensLogon2CF::QueryInterface(
  178. REFIID riid,
  179. LPVOID *ppv
  180. )
  181. {
  182. HRESULT hr = S_OK;
  183. *ppv = NULL; // To handle failure cases
  184. // IUnknown or IClassFactory
  185. if (IsEqualIID(riid, IID_IUnknown) ||
  186. IsEqualIID(riid, IID_IClassFactory))
  187. {
  188. *ppv = (LPUNKNOWN) this;
  189. }
  190. else
  191. {
  192. hr = E_NOINTERFACE;
  193. }
  194. if (NULL != *ppv)
  195. {
  196. ((LPUNKNOWN)*ppv)->AddRef();
  197. }
  198. return hr;
  199. }
  200. //
  201. // AddRef
  202. //
  203. STDMETHODIMP_(ULONG)
  204. CISensLogon2CF::AddRef(
  205. void
  206. )
  207. {
  208. return InterlockedIncrement((PLONG) &m_cRef);
  209. }
  210. //
  211. // Release
  212. //
  213. STDMETHODIMP_(ULONG)
  214. CISensLogon2CF::Release(
  215. void
  216. )
  217. {
  218. ULONG cRefT;
  219. cRefT = InterlockedDecrement((PLONG) &m_cRef);
  220. if (0 == m_cRef)
  221. {
  222. // Invoke the callback function.
  223. ObjectDestroyed();
  224. delete this;
  225. }
  226. return cRefT;
  227. }
  228. //
  229. // CreateInstance
  230. //
  231. STDMETHODIMP
  232. CISensLogon2CF::CreateInstance(
  233. LPUNKNOWN pUnkOuter,
  234. REFIID riid,
  235. LPVOID *ppvObj
  236. )
  237. {
  238. LPCIMPISENSLOGON2 pObjLogn2;
  239. HRESULT hr;
  240. DebugTraceGuid("CISensLogon2CF::CreateInstance()", riid);
  241. hr = E_OUTOFMEMORY;
  242. *ppvObj = NULL;
  243. pObjLogn2 = NULL;
  244. //
  245. // Return the appropriate interface pointer.
  246. //
  247. if (IsEqualIID(riid, IID_ISensLogon2) ||
  248. IsEqualIID(riid, IID_IUnknown))
  249. {
  250. SensPrintA(SENS_INFO, ("\t| ClassFactory::CreateInstance(ISensLogon2)\n"));
  251. pObjLogn2 = new CImpISensLogon2(ObjectDestroyed);
  252. if (NULL != pObjLogn2)
  253. {
  254. hr = pObjLogn2->QueryInterface(riid, ppvObj);
  255. SensPrintA(SENS_INFO, ("\t| QI on CImpISensLogon2 returned 0x%x\n", hr));
  256. }
  257. }
  258. else
  259. {
  260. hr = E_NOINTERFACE;
  261. }
  262. if (NULL != *ppvObj)
  263. {
  264. InterlockedIncrement((PLONG) &g_cObj);
  265. }
  266. SensPrintA(SENS_INFO, ("\t| Returning 0x%x from CF:CreateInstance\n", hr));
  267. return hr;
  268. }
  269. //
  270. // LockServer
  271. //
  272. STDMETHODIMP
  273. CISensLogon2CF::LockServer(
  274. BOOL fLock
  275. )
  276. {
  277. if (fLock)
  278. {
  279. InterlockedIncrement((PLONG) &g_cLock);
  280. }
  281. else
  282. {
  283. InterlockedDecrement((PLONG) &g_cLock);
  284. InterlockedIncrement((PLONG) &g_cObj);
  285. ObjectDestroyed(); // this does a --g_cObj
  286. }
  287. return NOERROR;
  288. }