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.

207 lines
3.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. cfacpwr.cxx
  5. Abstract:
  6. Implements the Class Factory for the SENS ISensOnNow 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 "cfacpwr.hxx"
  19. #include "cimppwr.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. CISensOnNowCF::CISensOnNowCF(
  30. void
  31. ) : m_cRef(1L)
  32. {
  33. }
  34. CISensOnNowCF::~CISensOnNowCF(
  35. void
  36. )
  37. {
  38. // Empty Destructor.
  39. }
  40. //
  41. // QI
  42. //
  43. STDMETHODIMP
  44. CISensOnNowCF::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. CISensOnNowCF::AddRef(
  72. void
  73. )
  74. {
  75. return InterlockedIncrement((PLONG) &m_cRef);
  76. }
  77. //
  78. // Release
  79. //
  80. STDMETHODIMP_(ULONG)
  81. CISensOnNowCF::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. CISensOnNowCF::CreateInstance(
  100. LPUNKNOWN pUnkOuter,
  101. REFIID riid,
  102. LPVOID *ppvObj
  103. )
  104. {
  105. LPCIMPISENSONNOW pObjPower;
  106. HRESULT hr;
  107. DebugTraceGuid("CISensOnNowCF::CreateInstance()", riid);
  108. hr = E_OUTOFMEMORY;
  109. *ppvObj = NULL;
  110. pObjPower = NULL;
  111. //
  112. // Return the appropriate interface pointer.
  113. //
  114. if (IsEqualIID(riid, IID_ISensOnNow) ||
  115. IsEqualIID(riid, IID_IUnknown))
  116. {
  117. SensPrintA(SENS_INFO, ("\t| ClassFactory::CreateInstance(ISensNetwork)\n"));
  118. pObjPower = new CImpISensOnNow(ObjectDestroyed);
  119. if (NULL != pObjPower)
  120. {
  121. hr = pObjPower->QueryInterface(riid, ppvObj);
  122. SensPrintA(SENS_INFO, ("\t| QI on CImpISensOnNow 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. CISensOnNowCF::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. }