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.

252 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 2000, Microsoft Corporation
  3. Module Name:
  4. dispatcher.h
  5. Abstract:
  6. This derivation from the base Socket class is to Create Accept dispatcher.
  7. Customers will register to this Dispatcher Giving it a struct which explains
  8. what type of connections are expected to be dispatched to them.
  9. Source specific or original destination specific dispatches can be requested.
  10. Author:
  11. Savas Guven (savasg) 25-Oct-2000
  12. Revision History:
  13. Savas Guven (savasg) 25-Oct-2000
  14. --*/
  15. #ifndef _DISPATCHER_HEADER_
  16. #define _DISPATCHER_HEADER_
  17. //
  18. // Forward definition
  19. //
  20. class CSockDispatcher;
  21. class DispatcheeNode;
  22. VOID
  23. DispatcherAcceptCompletionRoutine
  24. (
  25. ULONG ErrorCode,
  26. ULONG BytesTransferred,
  27. PNH_BUFFER Bufferp
  28. );
  29. typedef enum _ICQ_DIRECTION_FLAGS
  30. {
  31. IcqFlagNeutral = 0x00,
  32. IcqFlagOutgoing = eALG_OUTBOUND,
  33. IcqFlagIncoming = eALG_INBOUND
  34. } ICQ_DIRECTION_FLAGS, *PICQ_DIRECTION_FLAGS;
  35. typedef ICQ_DIRECTION_FLAGS DISPATCHER_DIRECTION_FLAGS, \
  36. * PDISPATCHER_DIRECTION_FLAGS;
  37. //
  38. //
  39. typedef class _DispatchRequest : public virtual GENERIC_NODE
  40. {
  41. public:
  42. ULONG srcIp;
  43. USHORT srcPort;
  44. ULONG dstIp;
  45. USHORT dstPort;
  46. DISPATCHER_DIRECTION_FLAGS DirectionContext;
  47. } DispatchRequest, *PDispatchRequest;
  48. //
  49. //
  50. //
  51. typedef struct _DispatchReply
  52. {
  53. DispatchRequest dispatch;
  54. PCNhSock Socketp;
  55. } DispatchReply, *PDispatchReply;
  56. //
  57. // D I S P A T C H E E
  58. //
  59. typedef class _Dispatchee : public virtual GENERIC_NODE
  60. {
  61. //friend CSockDispatcher;
  62. friend DispatcheeNode;
  63. public:
  64. _Dispatchee();
  65. virtual ~_Dispatchee() ;
  66. //#if DBG
  67. virtual void ComponentCleanUpRoutine(void);
  68. virtual void StopSync(void) {};
  69. virtual PCHAR GetObjectName();
  70. //#endif
  71. virtual ULONG DispatchCompletionRoutine
  72. (
  73. PDispatchReply DispatchReplyp
  74. );
  75. virtual SetID(ULONG ID) { DispatchUniqueId = ID;}
  76. virtual ULONG GetID(void) {return DispatchUniqueId; }
  77. protected:
  78. ISecondaryControlChannel* IncomingRedirectForPeerToClientp;
  79. ULONG DispatchUniqueId;
  80. static const PCHAR ObjectNamep;
  81. } DISPATCHEE, *PDISPATCHEE;
  82. //
  83. // D I S P A T C H E E _ N O D E
  84. //
  85. class DispatcheeNode: public virtual GENERIC_NODE
  86. {
  87. public:
  88. // also sets the Node search Keys appropriately.
  89. // DispatcheeNode(PDISPATCHEE);
  90. VOID InitDispatcheeNode(PDISPATCHEE);
  91. virtual ~DispatcheeNode();
  92. void ComponentCleanUpRoutine(void);
  93. PCHAR GetObjectName(void);
  94. // searches the list of Request made by this DispatchTo client
  95. ULONG isDispatchYours(PDispatchReply DispatchReplyp);
  96. ULONG AddDispatchRequest(PDispatchRequest DispatchRequestp);
  97. ULONG DeleteDispatchRequest(PDispatchRequest DispatchRequestp);
  98. PDISPATCHEE GetDispatchee() { return DispatchTop; }
  99. ULONG GetOriginalDestination(ULONG SrcAddress,
  100. USHORT SrcPort,
  101. PULONG DestAddrp,
  102. PUSHORT DestPortp);
  103. protected:
  104. static const PCHAR ObjectNamep;
  105. PDISPATCHEE DispatchTop;
  106. CLIST listRequests; // Node of Requests
  107. };
  108. //
  109. //
  110. //
  111. class CSockDispatcher: public virtual _CNhSock
  112. {
  113. public:
  114. friend VOID DispatcherAcceptCompletionRoutine
  115. (
  116. ULONG ErrorCode,
  117. ULONG BytesTransferred,
  118. PNH_BUFFER Bufferp
  119. );
  120. CSockDispatcher();
  121. CSockDispatcher(ULONG IpAddress, USHORT port);
  122. ~CSockDispatcher();
  123. //
  124. // Initializes the socket portion of the Dispatcher.
  125. //
  126. ULONG InitDispatcher(
  127. ULONG IpAddress,
  128. USHORT port
  129. );
  130. //
  131. // The inherited ComponentCleanupRoutine ala SYNC object
  132. //
  133. virtual void ComponentCleanUpRoutine(void);
  134. virtual void StopSync(void);
  135. PCHAR GetObjectName();
  136. //
  137. // A Dispatchee registers itself and gets a Unique ID
  138. //
  139. ULONG InitDispatchee(PDISPATCHEE Dispatchp);
  140. ULONG RemoveDispatchee(PDISPATCHEE Dispatchp);
  141. //
  142. // Get the port on which the Dispatch is occuring
  143. //
  144. ULONG GetDispatchInfo(
  145. PULONG IPp OPTIONAL,
  146. PUSHORT Portp OPTIONAL
  147. );
  148. //
  149. // Add a Dispatch request - searches for the correct node
  150. // and then calls the nodes AddDispatchReq to add the req to the List of existing reqs.
  151. //
  152. ULONG AddDispatchRequest(
  153. PDISPATCHEE Dispatchp,
  154. PDispatchRequest DispatchRequestp
  155. );
  156. //
  157. // Delete a Dispatch request - searches the correct node and
  158. // then calls the nodes own DeleteDispatchReq to delete the req from the List
  159. //
  160. ULONG DeleteDispatchRequest(
  161. PDispatchRequest DispatchRequestp
  162. );
  163. //
  164. // Get Original Destination for Accepted Socket
  165. //
  166. ULONG GetOriginalDestination(
  167. PNH_BUFFER Bufferp,
  168. PULONG OrigDestAddrp,
  169. PUSHORT OrigDestPortp
  170. );
  171. private:
  172. CLIST listDispNodes; // and their requests.
  173. static ULONG UniqueId;
  174. static const PCHAR ObjectNamep;
  175. };
  176. #endif //_DISPATCHER_HEADER_