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.

176 lines
6.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: EventPrxy.Cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 3 April, 2002
  10. *
  11. * DESCRIPTION:
  12. * Implements client-side hooks for WIA event notification support.
  13. *
  14. *******************************************************************************/
  15. #include <windows.h>
  16. #include <wia.h>
  17. //
  18. // Global object needed to receive WIA run-time events
  19. //
  20. #include "stirpc.h"
  21. #include "coredbg.h"
  22. #include "simlist.h"
  23. #include "lock.h"
  24. #include "EventRegistrationInfo.h"
  25. #include "WiaEventInfo.h"
  26. #include "ClientEventRegistrationInfo.h"
  27. #include "ClientEventTransport.h"
  28. #include "AsyncRPCEventTransport.h"
  29. #include "RegistrationCookie.h"
  30. #include "WiaEventReceiver.h"
  31. #include "stilib.h"
  32. //
  33. // This is the quickest, safest way to instantiate our global Event Receiver object.
  34. // Instantiating it this way ensures proper cleanup on the server when this object is destroyed
  35. // when the App exists normally.
  36. //
  37. WiaEventReceiver g_WiaEventReceiver(new AsyncRPCEventTransport());
  38. //remove
  39. extern void Trace(LPCSTR fmt, ...);
  40. /*******************************************************************************
  41. *
  42. * IWiaDevMgr_RegisterEventCallbackInterface_Proxy
  43. *
  44. * DESCRIPTION:
  45. * Proxy code to catch runtime event registrations. Since the service runs under
  46. * LocalService account, it will not have required access to callback into the
  47. * application (in most cases). Therefore, we catch this here and establish
  48. * our own notification channel to the server.
  49. *
  50. * PARAMETERS:
  51. * Same as IWiaDevMgr::RegisterEventCallbackInterface()
  52. *
  53. *******************************************************************************/
  54. HRESULT _stdcall IWiaDevMgr_RegisterEventCallbackInterface_Proxy(
  55. IWiaDevMgr __RPC_FAR *This,
  56. LONG lFlags,
  57. BSTR bstrDeviceID,
  58. const GUID *pEventGUID,
  59. IWiaEventCallback *pIWiaEventCallback,
  60. IUnknown **pEventObject)
  61. {
  62. ClientEventRegistrationInfo *pClientEventRegistrationInfo = NULL;
  63. RegistrationCookie *pRegistrationCookie = NULL;
  64. HRESULT hr = S_OK;
  65. //
  66. // Do parameter validation
  67. //
  68. if (!pEventGUID)
  69. {
  70. hr = E_INVALIDARG;
  71. DBG_ERR(("Client called IWiaDevMgr_RegisterEventCallbackInterface with NULL pEventGUID"));
  72. }
  73. if (!pIWiaEventCallback)
  74. {
  75. hr = E_INVALIDARG;
  76. DBG_ERR(("Client called IWiaDevMgr_RegisterEventCallbackInterface with NULL pIWiaEventCallback"));
  77. }
  78. if (!pEventObject)
  79. {
  80. hr = E_INVALIDARG;
  81. DBG_ERR(("Client called IWiaDevMgr_RegisterEventCallbackInterface with NULL pEventObject"));
  82. }
  83. //
  84. // Initialize the OUT parameters
  85. //
  86. *pEventObject = NULL;
  87. if (SUCCEEDED(hr))
  88. {
  89. //
  90. // We need to send the registration to the service to deal with
  91. // as appropriate.
  92. // Notice that we need to hand back an IUnknown event object. This is
  93. // considered to be the server's event registration cookie. Releasing the
  94. // cookie unregisters the client for this registration.
  95. // We create this cookie later on, if we can successfully send the
  96. // registration to the service.
  97. //
  98. pClientEventRegistrationInfo = new ClientEventRegistrationInfo(lFlags,
  99. *pEventGUID,
  100. bstrDeviceID,
  101. pIWiaEventCallback);
  102. if (pClientEventRegistrationInfo)
  103. {
  104. //
  105. // Send the registration info.
  106. //
  107. hr = g_WiaEventReceiver.SendRegisterUnregisterInfo(pClientEventRegistrationInfo);
  108. if (SUCCEEDED(hr))
  109. {
  110. //
  111. // Create the event registration cookie. We only create the cookie after successfully
  112. // registering with the server, because the cookie object holds an automatic ref count
  113. // on the client's pIWiaEventCallback interface. There's no reason to do this
  114. // if registration was not successful.
  115. //
  116. pRegistrationCookie = new RegistrationCookie(&g_WiaEventReceiver, pClientEventRegistrationInfo);
  117. if (pRegistrationCookie)
  118. {
  119. //
  120. // Set the [out] Event object to be our cookie
  121. //
  122. *pEventObject = pRegistrationCookie;
  123. }
  124. else
  125. {
  126. DBG_ERR(("Could not register client for runtime event. We appear to be out of memory"));
  127. hr = E_OUTOFMEMORY;
  128. }
  129. }
  130. else
  131. {
  132. DBG_ERR(("Could not successfully send runtime event information from client to WIA Service"));
  133. }
  134. pClientEventRegistrationInfo->Release();
  135. pClientEventRegistrationInfo = NULL;
  136. }
  137. else
  138. {
  139. DBG_ERR(("Could not register client for runtime event - we appear to be out of memory"));
  140. hr = E_OUTOFMEMORY;
  141. }
  142. }
  143. return hr;
  144. }
  145. /*******************************************************************************
  146. *
  147. * IWiaDevMgr_RegisterEventCallbackInterface_Stub
  148. *
  149. * Never called.
  150. *
  151. *******************************************************************************/
  152. HRESULT _stdcall IWiaDevMgr_RegisterEventCallbackInterface_Stub(
  153. IWiaDevMgr __RPC_FAR *This,
  154. LONG lFlags,
  155. BSTR bstrDeviceID,
  156. const GUID *pEventGUID,
  157. IWiaEventCallback *pIWiaEventCallback,
  158. IUnknown **pEventObject)
  159. {
  160. return S_OK;
  161. }