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.

291 lines
5.8 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. cimppwr.cxx
  5. Abstract:
  6. The core implementation for the ISensOnNow interface.
  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 <oleauto.h>
  17. #include <tchar.h>
  18. #include "sinkcomn.hxx"
  19. #include "cimppwr.hxx"
  20. #include "sensevts.h"
  21. extern ITypeInfo *gpITypeInfoLogon;
  22. //
  23. // Constructors and Destructors
  24. //
  25. CImpISensOnNow::CImpISensOnNow(
  26. void
  27. ) : m_cRef(0L), m_pfnDestroy(NULL)
  28. {
  29. }
  30. CImpISensOnNow::CImpISensOnNow(
  31. LPFNDESTROYED pfnDestroy
  32. ) : m_cRef(0L), m_pfnDestroy(pfnDestroy)
  33. {
  34. }
  35. CImpISensOnNow::~CImpISensOnNow(
  36. void
  37. )
  38. {
  39. // Empty destructor
  40. }
  41. //
  42. // Standard QueryInterface
  43. //
  44. STDMETHODIMP
  45. CImpISensOnNow::QueryInterface(
  46. REFIID riid,
  47. LPVOID *ppv
  48. )
  49. {
  50. DebugTraceGuid("CImpISensOnNow::QueryInterface()", riid);
  51. HRESULT hr = S_OK;
  52. *ppv = NULL; // To handle failure cases
  53. // IUnknown
  54. if (IsEqualIID(riid, IID_IUnknown))
  55. {
  56. *ppv = (LPUNKNOWN) this;
  57. }
  58. else
  59. // IDispatch
  60. if (IsEqualIID(riid, IID_IDispatch))
  61. {
  62. *ppv = (IDispatch *) this;
  63. }
  64. else
  65. // ISensOnNow
  66. if (IsEqualIID(riid, IID_ISensOnNow))
  67. {
  68. *ppv = (ISensOnNow *) this;
  69. }
  70. else
  71. {
  72. hr = E_NOINTERFACE;
  73. }
  74. if (NULL != *ppv)
  75. {
  76. ((LPUNKNOWN)*ppv)->AddRef();
  77. }
  78. return hr;
  79. }
  80. //
  81. // Standard AddRef and Release
  82. //
  83. STDMETHODIMP_(ULONG)
  84. CImpISensOnNow::AddRef(
  85. void
  86. )
  87. {
  88. return InterlockedIncrement((PLONG) &m_cRef);
  89. }
  90. STDMETHODIMP_(ULONG)
  91. CImpISensOnNow::Release(
  92. void
  93. )
  94. {
  95. ULONG cRefT;
  96. cRefT = InterlockedDecrement((PLONG) &m_cRef);
  97. if (0 == m_cRef)
  98. {
  99. // Invoke the callback function.
  100. if (NULL != m_pfnDestroy)
  101. {
  102. (*m_pfnDestroy)();
  103. }
  104. delete this;
  105. }
  106. return cRefT;
  107. }
  108. //
  109. // IDispatch member function implementations.
  110. //
  111. STDMETHODIMP
  112. CImpISensOnNow::GetTypeInfoCount(
  113. UINT *pCountITypeInfo
  114. )
  115. {
  116. SensPrint(SENS_INFO, (SENS_STRING("\t| CImpISensOnNow::GetTypeInfoCount() called.\n")));
  117. // We implement GetTypeInfo, so return 1.
  118. *pCountITypeInfo = 1;
  119. return NOERROR;
  120. }
  121. STDMETHODIMP
  122. CImpISensOnNow::GetTypeInfo(
  123. UINT iTypeInfo,
  124. LCID lcid,
  125. ITypeInfo **ppITypeInfo
  126. )
  127. {
  128. SensPrint(SENS_INFO, (SENS_STRING("\t| CImpISensOnNow::GetTypeInfo() called.\n")));
  129. *ppITypeInfo = NULL;
  130. if (iTypeInfo != 0)
  131. {
  132. return DISP_E_BADINDEX;
  133. }
  134. // Call AddRef and return the pointer.
  135. gpITypeInfoLogon->AddRef();
  136. *ppITypeInfo = gpITypeInfoLogon;
  137. return S_OK;
  138. }
  139. STDMETHODIMP
  140. CImpISensOnNow::GetIDsOfNames(
  141. REFIID riid,
  142. LPOLESTR *arrNames,
  143. UINT cNames,
  144. LCID lcid,
  145. DISPID *arrDispIDs)
  146. {
  147. HRESULT hr;
  148. SensPrint(SENS_INFO, (SENS_STRING("\t| CImpISensOnNow::GetIDsOfNames() called.\n")));
  149. if (riid != IID_NULL)
  150. {
  151. return DISP_E_UNKNOWNINTERFACE;
  152. }
  153. hr = gpITypeInfoLogon->GetIDsOfNames(
  154. arrNames,
  155. cNames,
  156. arrDispIDs
  157. );
  158. return hr;
  159. }
  160. STDMETHODIMP
  161. CImpISensOnNow::Invoke(
  162. DISPID dispID,
  163. REFIID riid,
  164. LCID lcid,
  165. WORD wFlags,
  166. DISPPARAMS *pDispParams,
  167. VARIANT *pvarResult,
  168. EXCEPINFO *pExecpInfo,
  169. UINT *puArgErr
  170. )
  171. {
  172. HRESULT hr;
  173. SensPrint(SENS_INFO, (SENS_STRING("\t| CImpISensOnNow::Invoke() called.\n")));
  174. if (riid != IID_NULL)
  175. {
  176. return DISP_E_UNKNOWNINTERFACE;
  177. }
  178. hr = gpITypeInfoLogon->Invoke(
  179. (IDispatch*) this,
  180. dispID,
  181. wFlags,
  182. pDispParams,
  183. pvarResult,
  184. pExecpInfo,
  185. puArgErr
  186. );
  187. SensPrint(SENS_INFO, (SENS_STRING("\t| CImpISensOnNow::Invoke() returned 0x%x\n"), hr));
  188. return hr;
  189. }
  190. STDMETHODIMP
  191. CImpISensOnNow::OnACPower(
  192. void
  193. )
  194. {
  195. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  196. SensPrint(SENS_INFO, (SENS_STRING("CImpISensOnNow::OnACPower() called\n")));
  197. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  198. return S_OK;
  199. }
  200. STDMETHODIMP
  201. CImpISensOnNow::OnBatteryPower(
  202. DWORD dwBatteryLifePercent
  203. )
  204. {
  205. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  206. SensPrint(SENS_INFO, (SENS_STRING("CImpISensOnNow::OnBatteryPower() called\n\n")));
  207. SensPrint(SENS_INFO, (SENS_STRING(" dwBatteryLifePercent - %d\n"), dwBatteryLifePercent));
  208. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  209. return S_OK;
  210. }
  211. STDMETHODIMP
  212. CImpISensOnNow::BatteryLow(
  213. DWORD dwBatteryLifePercent
  214. )
  215. {
  216. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  217. SensPrint(SENS_INFO, (SENS_STRING("CImpISensOnNow::BatteryLow() called\n\n")));
  218. SensPrint(SENS_INFO, (SENS_STRING(" dwBatteryLifePercent - %d\n"), dwBatteryLifePercent));
  219. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  220. return S_OK;
  221. }