Source code of Windows XP (NT5)
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.

242 lines
7.2 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1995-1996 **/
  4. /***************************************************************************/
  5. /****************************************************************************
  6. events.hpp
  7. Nov. 95 LenS
  8. Event handler infrastructure.
  9. CSequentialEventList assumes that all activity occurs on a single thread.
  10. It is the responsibility of the users to do the sychronization and thread
  11. context switches for this to happen.
  12. ****************************************************************************/
  13. #ifndef EVENTS_INC
  14. #define EVENTS_INC
  15. // #include <referenc.h>
  16. #include <inodecnt.h>
  17. #include "ernccons.h"
  18. #include "cuserdta.hpp"
  19. class DCRNCConference;
  20. class CLogicalConnection;
  21. #define QUERY_IND_WORK_OWNER ((LPVOID) 1)
  22. class CWorkItem
  23. {
  24. friend class CSequentialWorkList;
  25. public:
  26. CWorkItem(LPVOID pOwner) : m_pOwner(pOwner) { }
  27. virtual CWorkItem::~CWorkItem(void) = 0;
  28. virtual void DoWork(void) = 0;
  29. BOOL IsOwnedBy(LPVOID pOwner) { return (pOwner == m_pOwner);};
  30. protected:
  31. LPVOID m_pOwner;
  32. };
  33. // Invited by a remote node.
  34. class CInviteIndWork : public CWorkItem
  35. {
  36. public:
  37. CInviteIndWork(PCONFERENCE pConference,
  38. LPCWSTR wszCallerID,
  39. CLogicalConnection * _pConEntry);
  40. ~CInviteIndWork(void);
  41. void DoWork(void);
  42. LPWSTR GetCallerID(void) {return m_pwszCallerID;};
  43. private:
  44. PCONFERENCE m_pConf;
  45. LPWSTR m_pwszCallerID;
  46. BOOL m_fSecure;
  47. };
  48. // joined by a remote node
  49. class CJoinIndWork : public CWorkItem
  50. {
  51. public:
  52. CJoinIndWork(GCCResponseTag Tag,
  53. PCONFERENCE pConference,
  54. LPCWSTR wszCallerID,
  55. CLogicalConnection *pConEntry,
  56. HRESULT *pRetCode);
  57. ~CJoinIndWork(void);
  58. void DoWork(void);
  59. HRESULT Respond(GCCResult Result);
  60. PCONFERENCE GetConference(void) { return m_pConf; };
  61. LPWSTR GetCallerID(void) { return m_pwszCallerID; };
  62. CLogicalConnection *GetConEntry(void) { return m_pConEntry; };
  63. private:
  64. GCCResponseTag m_nResponseTag;
  65. PCONFERENCE m_pConf;
  66. LPWSTR m_pwszCallerID;
  67. CLogicalConnection *m_pConEntry;
  68. };
  69. class CQueryRemoteWork : public CWorkItem
  70. {
  71. public:
  72. CQueryRemoteWork(LPVOID pContext, GCCAsymmetryType, LPCSTR pcszNodeAddr, BOOL fSecure, HRESULT *);
  73. ~CQueryRemoteWork(void);
  74. void DoWork(void);
  75. void HandleQueryConfirmation(QueryConfirmMessage * pQueryMessage);
  76. void SyncQueryRemoteResult(void);
  77. void AsyncQueryRemoteResult(void);
  78. int GenerateRand(void);
  79. void SetHr(HRESULT hr) { m_hr = hr; }
  80. BOOL IsInUnknownQueryRequest(void) { return m_fInUnknownQueryRequest; }
  81. ConnectionHandle GetConnectionHandle(void) { return m_hGCCConnHandle; }
  82. void GetAsymIndicator ( GCCAsymmetryIndicator *pIndicator )
  83. {
  84. pIndicator->asymmetry_type = m_LocalAsymIndicator.asymmetry_type;
  85. pIndicator->random_number = m_LocalAsymIndicator.random_number;
  86. }
  87. private:
  88. ConnectionHandle m_hGCCConnHandle;
  89. GCCAsymmetryType m_eAsymType;
  90. LPSTR m_pszAddress;
  91. LPWSTR *m_apConfNames;
  92. HRESULT m_hr;
  93. BOOL m_fRemoteIsMCU;
  94. GCCAsymmetryIndicator m_LocalAsymIndicator;
  95. BOOL m_fInUnknownQueryRequest;
  96. int m_nRandSeed;
  97. BOOL m_fSecure;
  98. LPWSTR *m_apConfDescriptors;
  99. };
  100. // The CSequentialWorkList class is used to process a series
  101. // of asynchronous requests one at a time.
  102. // The user subclasses CWorkItem and puts the CWorkItem object into
  103. // the list by calling CSequentialWorkList::Add().
  104. // When it is its turn to be processed (i.e. there are no pending requests),
  105. // CWorkItem::Handle() is called. When the asynchonous work is done,
  106. // the user calls CSequentialWorkList::Remove which takes the CWorkItem
  107. // object out of the list, destroys it and calls CWorkItem::Handle() for
  108. // the next CWorkItem in the list (if any).
  109. class CSequentialWorkList : public CList
  110. {
  111. DEFINE_CLIST(CSequentialWorkList, CWorkItem*)
  112. public:
  113. ~CSequentialWorkList(void)
  114. {
  115. // Don't want to destroy an event list with pending events.
  116. // Codework: build I/O rundown into a generic event list,
  117. // and subclass.
  118. ASSERT(IsEmpty());
  119. }
  120. void AddWorkItem(CWorkItem * pWorkItem);
  121. void RemoveWorkItem(CWorkItem * pWorkItem);
  122. void PurgeListEntriesByOwner(DCRNCConference *pOwner);
  123. void DeleteList(void);
  124. };
  125. #define DEFINE_SEQ_WORK_LIST(_NewClass_,_PtrItemType_) \
  126. public: \
  127. _NewClass_(UINT cMaxItems = CLIST_DEFAULT_MAX_ITEMS) : CSequentialWorkList(cMaxItems) { ASSERT(sizeof(_PtrItemType_) == sizeof(CWorkItem*)); } \
  128. _NewClass_(_NewClass_ *pSrc) : CSequentialWorkList((CSequentialWorkList *) pSrc) { ASSERT(sizeof(_PtrItemType_) == sizeof(CWorkItem*)); } \
  129. _NewClass_(_NewClass_ &Src) : CSequentialWorkList((CSequentialWorkList *) &Src) { ASSERT(sizeof(_PtrItemType_) == sizeof(CWorkItem*)); } \
  130. BOOL Append(_PtrItemType_ pData) { return CSequentialWorkList::Append((CWorkItem*) pData); } \
  131. BOOL Prepend(_PtrItemType_ pData) { return CSequentialWorkList::Prepend((CWorkItem*) pData); } \
  132. BOOL Remove(_PtrItemType_ pData) { return CSequentialWorkList::Remove((CWorkItem*) pData); } \
  133. BOOL Find(_PtrItemType_ pData) { return CSequentialWorkList::Find((CWorkItem*) pData); } \
  134. _PtrItemType_ Get(void) { return (_PtrItemType_) CSequentialWorkList::Get(); } \
  135. _PtrItemType_ PeekHead(void) { return (_PtrItemType_) CSequentialWorkList::PeekHead(); } \
  136. _PtrItemType_ Iterate(void) { return (_PtrItemType_) CSequentialWorkList::Iterate(); }
  137. class CInviteIndWorkList : public CSequentialWorkList
  138. {
  139. DEFINE_SEQ_WORK_LIST(CInviteIndWorkList, CInviteIndWork*)
  140. public:
  141. void AddWorkItem(CInviteIndWork * pWorkItem)
  142. {
  143. CSequentialWorkList::AddWorkItem(pWorkItem);
  144. }
  145. void RemoveWorkItem(CInviteIndWork * pWorkItem)
  146. {
  147. CSequentialWorkList::RemoveWorkItem(pWorkItem);
  148. }
  149. };
  150. class CJoinIndWorkList : public CSequentialWorkList
  151. {
  152. DEFINE_SEQ_WORK_LIST(CJoinIndWorkList, CJoinIndWork*)
  153. public:
  154. void AddWorkItem(CJoinIndWork * pWorkItem)
  155. {
  156. CSequentialWorkList::AddWorkItem(pWorkItem);
  157. }
  158. void RemoveWorkItem(CJoinIndWork * pWorkItem)
  159. {
  160. CSequentialWorkList::RemoveWorkItem(pWorkItem);
  161. }
  162. };
  163. class CQueryRemoteWorkList : public CSequentialWorkList
  164. {
  165. DEFINE_SEQ_WORK_LIST(CQueryRemoteWorkList, CQueryRemoteWork*)
  166. public:
  167. void AddWorkItem(CQueryRemoteWork * pWorkItem)
  168. {
  169. CSequentialWorkList::AddWorkItem(pWorkItem);
  170. }
  171. void RemoveWorkItem(CQueryRemoteWork * pWorkItem)
  172. {
  173. CSequentialWorkList::RemoveWorkItem(pWorkItem);
  174. }
  175. HRESULT Cancel ( LPVOID pCallerContext );
  176. };
  177. extern CQueryRemoteWorkList *g_pQueryRemoteList;
  178. #endif /* ndef EVENTS_INC */