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.

160 lines
7.0 KiB

  1. /*****************************************************************************
  2. * (C) COPYRIGHT MICROSOFT CORPORATION, 2002
  3. *
  4. * AUTHOR: ByronC
  5. *
  6. * DATE: 3/30/2002
  7. *
  8. * @doc INTERNAL
  9. *
  10. * @module WiaEventReceiver.h - Definitions for <c WiaEventReceiver> |
  11. *
  12. * This file contains the class definition for <c WiaEventReceiver>.
  13. *
  14. *****************************************************************************/
  15. //
  16. // Defines
  17. //
  18. #define WiaEventReceiver_UNINIT_SIG 0x55726557
  19. #define WiaEventReceiver_INIT_SIG 0x49726557
  20. #define WiaEventReceiver_TERM_SIG 0x54726557
  21. #define WiaEventReceiver_DEL_SIG 0x44726557
  22. /*****************************************************************************
  23. *
  24. * @doc INTERNAL
  25. *
  26. * @class WiaEventReceiver | This client-side class receives event notifications from the WIA service
  27. *
  28. * @comm
  29. * There is a single instance of this class per client. It is responsible
  30. * for letting the WIA service know that this client needs event notifications,
  31. * and it informs the WIA Service of the client's specific event
  32. * registrations/unregistrations.
  33. *
  34. * When an event is received, it walks its list of registrations, and for
  35. * everyone that is a match for the current event, it uses the Callback
  36. * Interface stored in the registration info to notify the client of the event.
  37. *
  38. * To shield this class from specifics related to a specific event notification
  39. * transport machanism, it makes use of the <c ClientEventTransport> class.
  40. *
  41. *****************************************************************************/
  42. class ClientEventTransport;
  43. class WiaEventInfo;
  44. class ClientEventRegistrationInfo;
  45. class WiaEventReceiver
  46. {
  47. //@access Public members
  48. public:
  49. // @cmember Constructor
  50. WiaEventReceiver(ClientEventTransport *pClientEventTransport);
  51. // @cmember Destructor
  52. virtual ~WiaEventReceiver();
  53. // @cmember This method is called to start receiving notifications. This method is idempotent.
  54. virtual HRESULT Start();
  55. // @cmember This method is called to stop receiving notifications. This method is idempotent.
  56. virtual VOID Stop();
  57. // @cmember Make event callbacks to let this client know of an event notification
  58. virtual HRESULT NotifyCallbacksOfEvent(WiaEventInfo *pWiaEventInfo);
  59. // @cmember Informs service of client's specific registration/unregistration requests
  60. virtual HRESULT SendRegisterUnregisterInfo(ClientEventRegistrationInfo *pEventRegistrationInfo);
  61. // @cmember Procedure used to run the event thread which waits for event notifications
  62. static DWORD WINAPI EventThreadProc(LPVOID lpParameter);
  63. //@access Private members
  64. private:
  65. // @cmember Walks event registration list and releases all elements.
  66. VOID DestroyRegistrationList();
  67. // @cmember Checks whether a semantically equal <c ClientEventRegistrationInfo> is in the list
  68. ClientEventRegistrationInfo* FindEqualEventRegistration(ClientEventRegistrationInfo *pEventRegistrationInfo);
  69. // @cmember Signature of class
  70. ULONG m_ulSig;
  71. // @cmember Ref count
  72. ULONG m_cRef;
  73. // @cmember Class used to implement the notification transport
  74. ClientEventTransport *m_pClientEventTransport;
  75. // @cmember List holding the client's event registration data
  76. CSimpleLinkedList<ClientEventRegistrationInfo*> m_ListOfEventRegistrations;
  77. // @cmember Handle to the thread we create to wait for event notifications.
  78. HANDLE m_hEventThread;
  79. // @cmember ID of the event thread we created.
  80. DWORD m_dwEventThreadID;
  81. // @cmember Synchronization primitive used to protect access to this class
  82. CRIT_SECT m_csReceiverSync;
  83. // @cmember Signifies whether we are running or stopped
  84. BOOL m_bIsRunning;
  85. //
  86. // Comments for member variables
  87. //
  88. // @mdata ULONG | WiaEventReceiver | m_ulSig |
  89. // The signature for this class, used for debugging purposes.
  90. // Doing a <nl>"db [addr_of_class]"<nl> would yield one of the following
  91. // signatures for this class:
  92. // @flag WiaEventReceiver_UNINIT_SIG | 'WerU' - Object has not been successfully
  93. // initialized
  94. // @flag WiaEventReceiver_INIT_SIG | 'WerI' - Object has been successfully
  95. // initialized
  96. // @flag WiaEventReceiver_TERM_SIG | 'WerT' - Object is in the process of
  97. // terminating.
  98. // @flag WiaEventReceiver_INIT_SIG | 'WerD' - Object has been deleted
  99. // (destructor was called)
  100. //
  101. // @mdata ULONG | WiaEventReceiver | m_cRef |
  102. // The reference count for this class. Used for lifetime
  103. // management.
  104. //
  105. // @mdata ClientEventTransport* | WiaEventReceiver | m_pClientEventTransport |
  106. // Class used to implement the notification transport. This extra layer of
  107. // abstraction is used to shield us from the implmentation details of various
  108. // transport mechanisms. E.g. using AsyncRPC requires keeping track of
  109. // the RPC_ASYNC_STATE, which the <c WiaEventReceiver> doesn't need/want to deal
  110. // with.
  111. //
  112. // @mdata CSimpleLinkedList<lt>ClientEventRegistrationInfo*<gt> | WiaEventReceiver | m_ListOfEventRegistrations |
  113. // List holding the client's event registration data. When an event is received,
  114. // we walk this list of registrations and make the callback for any that match.
  115. // Each registration info also holds the callback interface pointer.
  116. //
  117. // @mdata HANDLE | WiaEventReceiver | m_hEventThread |
  118. // Handle to the thread we create to wait for event notifications. Notice that there
  119. // is only one thread per client. This thread waits on the event handle received from
  120. // <mf ClientEventTransport::getNotificationHandle>.
  121. //
  122. // @mdata DWORD | WiaEventReceiver | m_dwEventThreadID |
  123. // ID of the event thread we created. This is used to store which thread should be actively
  124. // waiting for event notifications. It's conveivable, that in a multi-threaded application,
  125. // many <mf WiaEventReceiver::Start>/<mf WiaEventReceiver::Stop> calls could be made very
  126. // close together. The possibility exists that one of the threads previously started, now stopped,
  127. // has not completely shut down yet. Therefore, each running thread checks its ID against this
  128. // thread id. If they do not match, it means this thread is not the event thread, and should therefore
  129. // exit.
  130. //
  131. // @mdata CRIT_SECT | WiaEventReceiver | m_csReceiverSync |
  132. // This synchronization class is used to ensure internal data entegrity.
  133. //
  134. // @mdata BOOL | WiaEventReceiver | m_bIsRunning |
  135. // Signifies whether we are running or stopped. We are running if <mf WiaEventReceiver::Start>
  136. // was called successfully. We are stopped if we could not start, or <mf WiaEventReceiver::Stop>
  137. // was called without a subsequent call to <mf WiaEventReceiver::Start>.
  138. };
  139. extern WiaEventReceiver g_WiaEventReceiver;