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.

167 lines
4.4 KiB

  1. /*
  2. * spacket.h
  3. *
  4. * Copyright (c) 1997-98 by Microsoft Corporation, Redmond, WA
  5. *
  6. * Abstract:
  7. * This is the interface file for the SimplePacket class. Instances of this
  8. * class represent Protocol Data Units (PDUs) as they flow through the
  9. * system. Objects of this class can not be instantiated, because it's a
  10. * pure virtual class. It exists only to be inherited from. The Packet
  11. * and DataPacket classes inherit from this one.
  12. *
  13. * A packet object can be created in 2 different ways. It can be created
  14. * with either decoded data or encoded data. During instantiation, the
  15. * new packet object will calculate how much memory it will need to
  16. * hold both the encoded and decoded data, and attempts to allocate that
  17. * memory. If it cannot, then it will report an error, and the newly
  18. * created object should be immediately destroyed. If the allocations are
  19. * successful, then the packet will report success, but WILL NOT yet put
  20. * any data into those allocated buffers.
  21. *
  22. * When a Lock message is sent to the object, it will put encoded
  23. * data into the pre-allocated encode buffer. If the packet was created
  24. * with decoded data, then this will entail an encode operation. However,
  25. * if the packet was created with encoded data, then it is smart enough
  26. * to just COPY the encoded data into the internal buffer, thus avoiding
  27. * the overhead associated with the encode operation.
  28. *
  29. * When a Lock message is sent to the object, it will put decoded
  30. * data into the pre-allocated decode buffer. If the packet was created
  31. * with encoded data, then this will entail a decode operation. However,
  32. * if the packet was created with decoded data, then it is smart enough
  33. * to just COPY the decoded data into the internal buffer, thus avoiding
  34. * the overhead associated with the decode operation.
  35. *
  36. * Caveats:
  37. * None.
  38. *
  39. * Authors:
  40. * Christos Tsollis
  41. */
  42. #ifndef _SIMPLE_PACKET_
  43. #define _SIMPLE_PACKET_
  44. /*
  45. * This typedef is used to define possible return values from various public
  46. * member functions of this class.
  47. */
  48. typedef enum
  49. {
  50. PACKET_NO_ERROR,
  51. PACKET_MALLOC_FAILURE,
  52. PACKET_INCOMPATIBLE_PROTOCOL
  53. } PacketError;
  54. typedef PacketError * PPacketError;
  55. /*
  56. * Definition of class Packet.
  57. */
  58. class SimplePacket
  59. {
  60. public:
  61. SimplePacket(BOOL fPacketDirectionUp);
  62. virtual ~SimplePacket(void) = 0;
  63. Void Lock(void)
  64. {
  65. InterlockedIncrement(&lLock);
  66. ASSERT (lLock > 0);
  67. };
  68. UINT GetEncodedDataLength(void)
  69. {
  70. return (Encoded_Data_Length);
  71. };
  72. void Unlock(void);
  73. LPBYTE GetEncodedData (void)
  74. {
  75. ASSERT (m_EncodedPDU);
  76. return m_EncodedPDU;
  77. };
  78. virtual PVoid GetDecodedData(void) = 0;
  79. virtual BOOL IsDataPacket (void) = 0;
  80. virtual int GetPDUType (void) = 0;
  81. protected:
  82. long lLock;
  83. LPBYTE m_EncodedPDU; // The encoded data pdu.
  84. BOOL Packet_Direction_Up;
  85. UINT Encoded_Data_Length; // the size of the whole encoded PDU.
  86. };
  87. /*
  88. * SimplePacket ()
  89. *
  90. * Functional Description:
  91. * This is the default constructor of a SimplePacket. It initializes
  92. * the few member variables to default values.
  93. *
  94. /*
  95. * ~SimplePacket ()
  96. *
  97. * Functional Description:
  98. * Destructor for the SimplePacket class.
  99. *
  100. * Formal Parameters:
  101. * None.
  102. *
  103. * Return Value:
  104. * None.
  105. *
  106. * Side Effects:
  107. * None.
  108. *
  109. * Caveats:
  110. * None.
  111. */
  112. /*
  113. * GetEncodedData ()
  114. *
  115. * Functional Description:
  116. * The GetEncodedData method returns a pointer to the encoded data
  117. * buffer. If the Packet object is oriented differently than desired
  118. * by the caller of this method, then the packet coder is called to
  119. * reverse the direction of the PDU.
  120. *
  121. * Formal Parameters:
  122. * None.
  123. *
  124. * Return Value:
  125. * A pointer to the encoded data. If an encoding error occurs, this
  126. * method will return NULL.
  127. *
  128. * Side Effects:
  129. * None.
  130. *
  131. * Caveats:
  132. * None.
  133. */
  134. /*
  135. * GetDecodedData ()
  136. *
  137. * Functional Description:
  138. * The GetDecodedData method returns a pointer to the decoded data
  139. * buffer.
  140. *
  141. * Formal Parameters:
  142. * None.
  143. *
  144. * Return Value:
  145. * A pointer to the decoded data. If an decoding error occurs, this
  146. * method will return NULL.
  147. *
  148. * Side Effects:
  149. * None.
  150. *
  151. * Caveats:
  152. * None.
  153. */
  154. #endif