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.

86 lines
2.8 KiB

  1. /*
  2. * spacket.h
  3. *
  4. * Copyright (c) 1997-98 by Microsoft Corporation, Redmond, WA
  5. *
  6. * Abstract:
  7. * This is the implementation 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. * When Unlock messages are received, the lock count is decremented. When
  37. * the lock count is 0, the packet deletes itself (it commits
  38. * suicide). Note that for this reason, no other object should explicitly
  39. * delete a packet object.
  40. *
  41. * Caveats:
  42. * None.
  43. *
  44. * Authors:
  45. * Christos Tsollis
  46. */
  47. #include "precomp.h"
  48. // Constructor for the SimplePacket class.
  49. SimplePacket::SimplePacket(BOOL fPacketDirectionUp)
  50. :
  51. lLock (1),
  52. Packet_Direction_Up (fPacketDirectionUp)
  53. {
  54. }
  55. // Destructor for the SimplePacket class
  56. SimplePacket::~SimplePacket (void)
  57. {
  58. }
  59. /*
  60. * Unlock ()
  61. *
  62. * Public
  63. *
  64. */
  65. Void SimplePacket::Unlock ()
  66. {
  67. /*
  68. * Check to make sure that the packet is locked before allowing it to
  69. * be unlocked.
  70. */
  71. ASSERT (lLock > 0);
  72. /*
  73. * If the lock count has reached zero, it is necessary to perform
  74. * a suicide check. This method will determine if there is any need
  75. * to continue to exist.
  76. */
  77. if (InterlockedDecrement(&lLock) == 0)
  78. delete this;
  79. }