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.

394 lines
10 KiB

  1. /*
  2. * datapkt.h
  3. *
  4. * Copyright (c) 1997 by Microsoft Corporation, Redmond, WA
  5. *
  6. * Abstract:
  7. * This is the interface file for the MCS Data Packet class. Instances of this
  8. * class represent MCS Data Protocol Data Units (Data PDUs) as they flow through the
  9. * system. These instances allocate the memory required to hold both
  10. * encoded and decoded versions of the PDU, and make sure that no PDU
  11. * is ever encoded or decoded more than once. However, they differ from normal
  12. * packets, in that there is only one copy of the user data in the encoded
  13. * and decoded buffers. The use of lock counts
  14. * allows multiple objects in the system to reference and use the same
  15. * packet object at the same time. This class inherits from the SimplePacket
  16. * class, which is a pure virtual class.
  17. *
  18. * A data packet object can be created in two different ways. It can be created
  19. * with either decoded data or encoded data. During instantiation, the
  20. * new packet object will include the memory it will need to
  21. * hold both the encoded and decoded data
  22. * The DataPacket class, however, does not put any data into those buffers.
  23. *
  24. * When a Lock message is sent to the object, it will put encoded
  25. * data into the encode buffer. If the packet was created
  26. * with decoded data, then this will entail an encode operation. However,
  27. * if the packet was created with encoded data, then it is smart enough
  28. * to just COPY the encoded data into the internal buffer, thus avoiding
  29. * the overhead associated with the encode operation.
  30. *
  31. * When a Lock message is sent to the object, it will put decoded
  32. * data into the pre-allocated decode buffer. If the packet was created
  33. * with encoded data, then this will entail a decode operation. However,
  34. * if the packet was created with decoded data, then it is smart enough
  35. * to just COPY the decoded data into the internal buffer, thus avoiding
  36. * the overhead associated with the decode operation.
  37. *
  38. * When Unlock messages are received, the lock count is decremented. When a packet's
  39. * lock count is 0, the packet deletes itself (it commits
  40. * suicide). Note that for this reason, no other object should explicitly
  41. * delete a packet object.
  42. *
  43. * Caveats:
  44. * None.
  45. *
  46. * Authors:
  47. * Christos Tsollis
  48. */
  49. #ifndef _DATAPACKET_
  50. #define _DATAPACKET_
  51. #include "mpdutype.h"
  52. /*
  53. * Definition of class DataPacket.
  54. */
  55. class DataPacket;
  56. typedef DataPacket * PDataPacket;
  57. class DataPacket : public SimplePacket
  58. {
  59. public:
  60. static Void AllocateMemoryPool (long maximum_objects);
  61. static Void FreeMemoryPool ();
  62. PVoid operator new (size_t);
  63. Void operator delete (PVoid object);
  64. DataPacket (ASN1choice_t choice,
  65. PUChar data_ptr,
  66. ULong data_length,
  67. UINT channel_id,
  68. Priority priority,
  69. Segmentation segmentation,
  70. UINT initiator_id,
  71. SendDataFlags flags,
  72. PMemory memory,
  73. PPacketError packet_error);
  74. DataPacket( PTransportData pTransportData,
  75. BOOL fPacketDirectionUp);
  76. virtual ~DataPacket ();
  77. Void SetDirection (DBBoolean packet_direction_up);
  78. virtual PVoid GetDecodedData(void);
  79. virtual BOOL IsDataPacket (void);
  80. virtual int GetPDUType (void);
  81. BOOL Equivalent (PDataPacket);
  82. Priority GetPriority (void)
  83. {
  84. return ((Priority) m_DecodedPDU.u.send_data_request.
  85. data_priority);
  86. };
  87. UserID GetInitiator (void)
  88. {
  89. return (m_DecodedPDU.u.send_data_request.initiator);
  90. };
  91. ChannelID GetChannelID (void)
  92. {
  93. return (m_DecodedPDU.u.send_data_request.channel_id);
  94. };
  95. Segmentation GetSegmentation (void)
  96. {
  97. return (m_DecodedPDU.u.send_data_request.segmentation);
  98. };
  99. LPBYTE GetUserData (void)
  100. {
  101. return ((LPBYTE) m_DecodedPDU.u.send_data_request.user_data.value);
  102. };
  103. UINT GetUserDataLength (void)
  104. {
  105. return (m_DecodedPDU.u.send_data_request.user_data.length);
  106. };
  107. PMemory GetMemory (void)
  108. {
  109. return (m_Memory);
  110. };
  111. BOOL IsEncodedDataBroken (void)
  112. {
  113. return (m_EncodedDataBroken);
  114. };
  115. void SetMessageType(UINT nMsgType) { m_nMessageType = nMsgType; }
  116. UINT GetMessageType(void) { return m_nMessageType; }
  117. protected:
  118. static PVoid * Object_Array;
  119. static long Object_Count;
  120. BOOL fPreAlloc;
  121. DomainMCSPDU m_DecodedPDU; // The decoded data PDU (w/o the user data)
  122. PMemory m_Memory; // Memory object pointing to big buffer which contains the object's buffer.
  123. BOOL m_fIncoming; // Does this packet represent recv data?
  124. BOOL m_EncodedDataBroken;
  125. UINT m_nMessageType; // for retry in CUser::SendDataIndication
  126. };
  127. /*
  128. * Void AllocateMemoryPool (
  129. * long maximum_objects);
  130. *
  131. * Functional Description:
  132. * This is a static member function that should only be called during MCS
  133. * initialization (exactly once). It allocates a memory block that will
  134. * be used to hold all instances of this class during the operation of
  135. * the system. This allows us to VERY efficiently allocate and destroy
  136. * instances of this class.
  137. *
  138. * Formal Parameters:
  139. * maximum_objects
  140. * This is the maximum number of objects of this class that can exist
  141. * in the system at the same time. This is used to determine how much
  142. * memory to allocate to hold the objects. Once this number of
  143. * objects exist, all calls to "new" will return NULL.
  144. *
  145. * Return Value:
  146. * None.
  147. *
  148. * Side Effects:
  149. * None.
  150. *
  151. * Caveats:
  152. * None.
  153. */
  154. /*
  155. * Void FreeMemoryPool ();
  156. *
  157. * Functional Description:
  158. * This is a static member function that should only be called during a
  159. * shutdown of MCS (exactly once). It frees up the memory pool allocated
  160. * to hold all instances of this class. Note that calling this function
  161. * will cause ALL existing instances of this class to be invalid (they
  162. * no longer exist, and should not be referenced).
  163. *
  164. * Formal Parameters:
  165. * None.
  166. *
  167. * Return Value:
  168. * None.
  169. *
  170. * Side Effects:
  171. * Any existing instances of this class are no longer valid and should not
  172. * be referenced.
  173. *
  174. * Caveats:
  175. * None.
  176. */
  177. /*
  178. * PVoid operator new (
  179. * size_t object_size);
  180. *
  181. * Functional Description:
  182. * This is an override of the "new" operator for this class. Since all
  183. * instances of this class come from a single memory pool allocated up
  184. * front, this function merely pops the first entry from the list of
  185. * available objects.
  186. *
  187. * Formal Parameters:
  188. * None.
  189. *
  190. * Return Value:
  191. * Pointer to an object of this class, or NULL if no memory is available.
  192. *
  193. * Side Effects:
  194. * None.
  195. *
  196. * Caveats:
  197. * None.
  198. */
  199. /*
  200. * Void operator delete (
  201. * PVoid object);
  202. *
  203. * Functional Description:
  204. * This function is used to free up a previously allocated object of this
  205. * class. Note that it is VERY important not to call this function with an
  206. * invalid address, because no error checking is performed. This decision
  207. * was made due to speed requirements.
  208. *
  209. * Formal Parameters:
  210. * None.
  211. *
  212. * Return Value:
  213. * None.
  214. *
  215. * Side Effects:
  216. * None.
  217. *
  218. * Caveats:
  219. * None.
  220. */
  221. /*
  222. * DataPacket( PUChar pEncodedData,
  223. * ULong ulEncodedDataSize,
  224. * BOOL fPacketDirectionUp,
  225. * PPacketError pePktErr)
  226. *
  227. * Functional Description:
  228. * This version of the constructor is used to create a Data Packet object
  229. * for incomming PDUs when the packet is to be created from an encoded
  230. * data stream containing the PDU data to be decoded.
  231. *
  232. * Formal Parameters:
  233. * pEncodedData (i)
  234. * Pointer to the input encoded PDU.
  235. * ulEncodedDataSize (i)
  236. * The length in bytes of the input encoded PDU.
  237. * fPacketDirectionUp (i)
  238. * The packet_direction_up flag indicates the initial orientation of
  239. * the packet. Valid values are:
  240. * TRUE - The packet's direction is up.
  241. * FALSE - The packet's direction is down.
  242. * pePktErr (o)
  243. * When the constructor returns control to the calling function, this
  244. * variable will be set to one of the return values listed below.
  245. *
  246. * Return Value:
  247. * None.
  248. *
  249. * Side Effects:
  250. * None.
  251. *
  252. * Caveats:
  253. * None.
  254. */
  255. /*
  256. * DataPacket (ASN1choice_t choice,
  257. * PUChar data_ptr,
  258. * ULong data_length,
  259. * UINT channel_id,
  260. * Priority priority,
  261. * Segmentation segmentation,
  262. * UINT initiator_id,
  263. * PPacketError packet_error)
  264. *
  265. * Functional Description:
  266. * This constructor is used for outgoing data packets.
  267. * It needs to copy the data into the encoded PDU buffer
  268. * that will be allocated by this constructor.
  269. *
  270. * Formal Parameters:
  271. * choice (i)
  272. * Either normal or uniform send data PDU
  273. * data_ptr (i)
  274. * Pointer to the user data for this data PDU.
  275. * data_length (i)
  276. * The length of the user data
  277. * channel_id (i)
  278. * The MCS channel on which the data will be xmitted.
  279. * priority (i)
  280. * Data priority
  281. * segmentation (i)
  282. * The segmentation bits for the packet
  283. * initiator_id (i)
  284. * MCS user id of the user (application) sending the data
  285. * packet_error (o)
  286. * Ptr to location for storing the success/failure code for the constructor.
  287. *
  288. * Return Value:
  289. * None.
  290. *
  291. * Side Effects:
  292. * None.
  293. *
  294. * Caveats:
  295. * None.
  296. */
  297. /*
  298. * ~DataPacket ()
  299. *
  300. * Functional Description:
  301. * Destructor for the DataPacket class. The destructor ensures that all
  302. * resources that have been allocated are freed.
  303. *
  304. * Formal Parameters:
  305. * None.
  306. *
  307. * Return Value:
  308. * None.
  309. *
  310. * Side Effects:
  311. * None.
  312. *
  313. * Caveats:
  314. * None.
  315. */
  316. /*
  317. * GetDecodedData ()
  318. *
  319. * Functional Description:
  320. * The GetDecodedData method returns a pointer to the decoded data
  321. * buffer.
  322. *
  323. * Formal Parameters:
  324. * None.
  325. *
  326. * Return Value:
  327. * A pointer to the decoded data. If an decoding error occurs, this
  328. * method will return NULL.
  329. *
  330. * Side Effects:
  331. * None.
  332. *
  333. * Caveats:
  334. * None.
  335. */
  336. /*
  337. * GetEncodedDataLength ()
  338. *
  339. * Functional Description:
  340. * This method returns the encoded data's length.
  341. *
  342. * Formal Parameters:
  343. * None.
  344. *
  345. * Return Value:
  346. * The number of bytes in the encoded data.
  347. *
  348. * Side Effects:
  349. * None.
  350. *
  351. * Caveats:
  352. * None.
  353. */
  354. /*
  355. * GetDecodedDataLength ()
  356. *
  357. * Functional Description:
  358. * This method returns the decoded data's length.
  359. *
  360. * Formal Parameters:
  361. * None.
  362. *
  363. * Return Value:
  364. * The number of bytes in the decoded data.
  365. *
  366. * Side Effects:
  367. * None.
  368. *
  369. * Caveats:
  370. * None.
  371. */
  372. #endif