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.

240 lines
8.6 KiB

  1. /*****************************************************************************
  2. * (C) COPYRIGHT MICROSOFT CORPORATION, 2002
  3. *
  4. * AUTHOR: ByronC
  5. *
  6. * DATE: 3/22/2002
  7. *
  8. * @doc INTERNAL
  9. *
  10. * @module ClientEventTransport.cpp - Implementation for the client-side transport mechanism to receive events |
  11. *
  12. * This file contains the implementation for the ClientEventTransport base
  13. * class. It is used to shield the higher-level run-time event notification
  14. * classes from the particulars of a specific transport mechanism.
  15. *
  16. *****************************************************************************/
  17. #include "cplusinc.h"
  18. #include "coredbg.h"
  19. /*****************************************************************************
  20. * @doc INTERNAL
  21. *
  22. * @mfunc | ClientEventTransport | ClientEventTransport |
  23. *
  24. * We initialize all member variables. In general, this sets the values to 0,
  25. * except:
  26. * <nl><md ClientEventTransport::m_ulSig> is set to be ClientEventTransport_UNINIT_SIG.
  27. *
  28. *****************************************************************************/
  29. ClientEventTransport::ClientEventTransport() :
  30. m_ulSig(ClientEventTransport_UNINIT_SIG),
  31. m_hPendingEvent(NULL)
  32. {
  33. DBG_FN(ClientEventTransport constructor);
  34. }
  35. /*****************************************************************************
  36. * @doc INTERNAL
  37. *
  38. * @mfunc | ClientEventTransport | ~ClientEventTransport |
  39. *
  40. * Do any cleanup that is not already done.
  41. *
  42. * Also:
  43. * <nl><md ClientEventTransport::m_ulSig> is set to be ClientEventTransport_DEL_SIG.
  44. *
  45. *****************************************************************************/
  46. ClientEventTransport::~ClientEventTransport()
  47. {
  48. DBG_FN(~ClientEventTransport);
  49. if (m_hPendingEvent)
  50. {
  51. CloseHandle(m_hPendingEvent);
  52. m_hPendingEvent = NULL;
  53. }
  54. m_ulSig = ClientEventTransport_DEL_SIG;
  55. }
  56. /*****************************************************************************
  57. * @doc INTERNAL
  58. *
  59. * @mfunc HRESULT | ClientEventTransport | Initialize |
  60. *
  61. * This method creates the event object that the caller uses to wait on
  62. * for event notifications.
  63. *
  64. * If this method succeeds, the signature is updated to be
  65. * ClientEventTransport_INIT_SIG.
  66. *
  67. * This method is idempotent.
  68. *
  69. * @rvalue S_OK |
  70. * The method succeeded.
  71. * @rvalue E_XXXXXXXX |
  72. * We failed to initialize this object correctly - it should
  73. * be deleted. It is not valid to use this uninitialized object.
  74. *****************************************************************************/
  75. HRESULT ClientEventTransport::Initialize()
  76. {
  77. HRESULT hr = S_OK;
  78. if (!m_hPendingEvent)
  79. {
  80. m_hPendingEvent = CreateEvent(NULL, // Default security - this is not a named event
  81. FALSE, // We want this to be AutoReset
  82. FALSE, // Unsignalled initially
  83. NULL); // No name
  84. if (!m_hPendingEvent)
  85. {
  86. DWORD dwError = GetLastError();
  87. hr = HRESULT_FROM_WIN32(dwError);
  88. //
  89. // Log the error
  90. //
  91. DBG_ERR(("Runtime event Error: Failed to create event object, erro code = 0x%08X\n", dwError));
  92. }
  93. if (SUCCEEDED(hr))
  94. {
  95. m_ulSig = ClientEventTransport_INIT_SIG;
  96. }
  97. }
  98. return hr;
  99. }
  100. /*****************************************************************************
  101. * @doc INTERNAL
  102. *
  103. * @mfunc HRESULT | ClientEventTransport | OpenConnectionToServer |
  104. *
  105. * This method is imlemented by sub-classes to find and connect to the WIA
  106. * service. If successful, callers should clean-up by calling
  107. * <mf ClientEventTransport::CloseConnectionToServer>.
  108. *
  109. * @rvalue S_OK |
  110. * The method succeeded. This base class does not do anything here.
  111. *****************************************************************************/
  112. HRESULT ClientEventTransport::OpenConnectionToServer()
  113. {
  114. HRESULT hr = S_OK;
  115. return hr;
  116. }
  117. /*****************************************************************************
  118. * @doc INTERNAL
  119. *
  120. * @mfunc HRESULT | ClientEventTransport | CloseConnectionToServer |
  121. *
  122. * This method is imlemented by sub-classes to close any resources used to
  123. * connect to the WIA service in <mf ClientEventTransport::OpenConnectionToServer>.
  124. *
  125. * @rvalue S_OK |
  126. * The method succeeded. This base class does not do anything here.
  127. *****************************************************************************/
  128. HRESULT ClientEventTransport::CloseConnectionToServer()
  129. {
  130. HRESULT hr = S_OK;
  131. return hr;
  132. }
  133. /*****************************************************************************
  134. * @doc INTERNAL
  135. *
  136. * @mfunc HRESULT | ClientEventTransport | OpenNotificationChannel |
  137. *
  138. * Sub-classes use this method to set up the mechanism by which the client
  139. * will receive notifications.
  140. *
  141. * @rvalue S_OK |
  142. * The method succeeded. This base class does not do anything here.
  143. *****************************************************************************/
  144. HRESULT ClientEventTransport::OpenNotificationChannel()
  145. {
  146. HRESULT hr = S_OK;
  147. return hr;
  148. }
  149. /*****************************************************************************
  150. * @doc INTERNAL
  151. *
  152. * @mfunc HRESULT | ClientEventTransport | CloseNotificationChannel |
  153. *
  154. * Sub-classes use this method to tear down the mechanism by which the client
  155. * could receive notifications set up in the .
  156. *
  157. * @rvalue S_OK |
  158. * The method succeeded. This base class does not do anything here.
  159. *****************************************************************************/
  160. HRESULT ClientEventTransport::CloseNotificationChannel()
  161. {
  162. HRESULT hr = S_OK;
  163. return hr;
  164. }
  165. /*****************************************************************************
  166. * @doc INTERNAL
  167. *
  168. * @mfunc HRESULT | ClientEventTransport | SendRegisterUnregisterInfo |
  169. *
  170. * @parm EventRegistrationInfo* | pEventRegistrationInfo |
  171. * The address of a caller's event registration information.
  172. *
  173. * Sub-classes use this method to inform the WIA Service of the client's specific
  174. * registration/unregistration requests. For example, a registration might let
  175. * the WIA Service know that the client would like to be informed when Event X from
  176. * from Device Foo occurs.
  177. *
  178. * @rvalue S_OK |
  179. * The method succeeded. This base class does not do anything here.
  180. *****************************************************************************/
  181. HRESULT ClientEventTransport::SendRegisterUnregisterInfo(
  182. EventRegistrationInfo *pEventRegistrationInfo)
  183. {
  184. HRESULT hr = S_OK;
  185. return hr;
  186. }
  187. /*****************************************************************************
  188. * @doc INTERNAL
  189. *
  190. * @mfunc HANDLE | ClientEventTransport | getNotificationHandle |
  191. *
  192. * Retrieves a HANDLE which callers can Wait on to receive event notifications.
  193. *
  194. * The typical use is: once a client has established a connection to the
  195. * server, and has registered for events, it will call this method and wait
  196. * for this object to be signalled. When the object is signalled, it means
  197. * that one of the registered for events occured.
  198. *
  199. * @rvalue NULL |
  200. * There is no handle. Generally, this should only happen if
  201. * the object has not been initialized.
  202. *****************************************************************************/
  203. HANDLE ClientEventTransport::getNotificationHandle()
  204. {
  205. return m_hPendingEvent;
  206. }
  207. /*****************************************************************************
  208. * @doc INTERNAL
  209. *
  210. * @mfunc HRESULT | ClientEventTransport | FillEventData |
  211. *
  212. * Description goes here
  213. *
  214. * @parm WiaEventInfo* | pWiaEventInfo |
  215. * Address of the caller allocated <c WiaEventInfo>. The members of this structure
  216. * are filled out with the relevant event info. It is the caller's
  217. * responsibility to free and memory allocated for the structure members.
  218. *
  219. * @rvalue S_OK |
  220. * The method succeeded. This base class does not do anything here.
  221. *****************************************************************************/
  222. HRESULT ClientEventTransport::FillEventData(
  223. WiaEventInfo *pWiaEventInfo)
  224. {
  225. HRESULT hr = S_OK;
  226. return hr;
  227. }