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.

185 lines
5.4 KiB

  1. //***************************************************************************
  2. //
  3. // File:
  4. //
  5. // Module: MS SNMP Provider
  6. //
  7. // Purpose:
  8. //
  9. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. /*--------------------------------------------------
  13. Filename: message.hpp
  14. Author: B.Rajeev
  15. Purpose: Provides declarations for the Message and
  16. WaitingMessage classes.
  17. --------------------------------------------------*/
  18. #ifndef __MESSAGE__
  19. #define __MESSAGE__
  20. #include "forward.h"
  21. #include "common.h"
  22. #include "error.h"
  23. #include "reg.h"
  24. #include "timer.h"
  25. /*--------------------------------------------------
  26. Overview:
  27. Message: Stores the parameters passed to the session with
  28. a call to the SendFrame method. A message may either be
  29. transmitted immediately or enqueued in the FlowControlMechanism
  30. queue for future transmission. After transmission, the message
  31. becomes a part of a WaitingMessage.
  32. WaitingMessage: Encapsulates the state maintained for each outstanding
  33. reply. This includes its timer_event_id, retransmission
  34. information (Message ptr) etc.
  35. Note - A Message/WaitingMessage may be cancelled at any time
  36. --------------------------------------------------*/
  37. class Message
  38. {
  39. SessionFrameId session_frame_id;
  40. SnmpPdu *snmp_pdu;
  41. SnmpOperation &operation;
  42. public:
  43. Message(IN const SessionFrameId session_frame_id,
  44. IN SnmpPdu &snmp_pdu,
  45. IN SnmpOperation &snmp_operation);
  46. SessionFrameId GetSessionFrameId(void) const;
  47. SnmpOperation &GetOperation(void) const;
  48. void SetSnmpPdu(IN SnmpPdu &snmp_pdu);
  49. SnmpPdu &GetSnmpPdu(void) const;
  50. ~Message(void);
  51. };
  52. // instances store the list of request ids used for a waiting message
  53. typedef CList<RequestId, RequestId> RequestIdList;
  54. // encapsulates state for a message that is transmitted and
  55. // subsequently waits for a reply. It uses the timer to rexmt
  56. // the message and if the reply isn't forthcoming, informs the
  57. // flow control mechanism that no reply has been received. When
  58. // a reply is received it informs the fc mech. of the event
  59. // Each transmission of the waiting message uses a different request id
  60. class WaitingMessage
  61. {
  62. // it operates in the session's context
  63. SnmpImpSession *session;
  64. Message *message;
  65. SnmpPdu *reply_snmp_pdu;
  66. TransportFrameId last_transport_frame_id;
  67. TimerEventId m_TimerEventId ;
  68. // stores the list of request ids used for the waiting message
  69. // (inclusive of the original transmission)
  70. RequestIdList request_id_list;
  71. UINT max_rexns;
  72. UINT rexns_left;
  73. UINT strobes;
  74. BOOL sent_message_processed;
  75. BOOL active;
  76. // deregisters the waiting message from the message registry
  77. // for each request id stored in the RequestIdList
  78. void DeregisterRequestIds();
  79. public:
  80. // initializes the private variables. in future,
  81. // max_rexns and timeout_period might be obtained this way
  82. // rather than from the session
  83. WaitingMessage(IN SnmpImpSession &session, IN Message &message);
  84. // returns the private message
  85. Message *GetMessage(void)
  86. {
  87. return message;
  88. }
  89. TimerEventId GetTimerEventId () ;
  90. void SetTimerEventId ( TimerEventId a_TimerEventId ) ;
  91. // sends the message. involves request_id generation,
  92. // registering with the message_registry, decoding the
  93. // message, updating the pdu and registering a timer event
  94. void Transmit();
  95. // used by the timer to notify the waiting message of
  96. // a timer event. if need, the message is retransmitted.
  97. // when all rexns are exhausted, ReceiveReply is called
  98. void TimerNotification(void);
  99. // A call to this function signifies that state corresponding to the
  100. // waiting_message need not be kept any further
  101. // it notifies the flow control mechanism of the termination
  102. // which destroys the waiting_message
  103. void ReceiveReply(IN const SnmpPdu *snmp_pdu,
  104. IN SnmpErrorReport &snmp_error_report = SnmpErrorReport(Snmp_Success, Snmp_No_Error));
  105. // The WinSnmp implementation, posts an event when a message is received,
  106. // however, when a call is made to the library to receive a message,
  107. // it hands them out in no specific order. Therefore, responses may
  108. // be received before their corresponding SENT_FRAME event is processed.
  109. // The following methods are concerned with buffering and
  110. // retrieving such snmp pdus.
  111. // buffers the snmp pdu received as a reply
  112. void BufferReply(IN const SnmpPdu &reply_snmp_pdu);
  113. // returns TRUE if a reply has been buffered
  114. BOOL ReplyBuffered();
  115. // returns a ptr to the buffered reply pdu, if buffered
  116. // otherwise a null ptr is returned
  117. // IMPORTANT: it sets the reply_snmp_pdu to NULL, so that it may
  118. // not be deleted when the waiting message is destroyed
  119. SnmpPdu *GetBufferedReply();
  120. // informs the waiting message that a sent message has been
  121. // processed
  122. void SetSentMessageProcessed();
  123. // if a sent message has been processed, it returns TRUE, else FALSE
  124. BOOL GetSentMessageProcessed();
  125. // an exit fn - prepares an error report and calls
  126. // ReceiveReply to signal a non-receipt
  127. void WrapUp( IN SnmpErrorReport &error_report =
  128. SnmpErrorReport(Snmp_Error, Snmp_Local_Error) );
  129. void SelfDestruct(void);
  130. // if required, it cancels registration with the message_registry and
  131. // the timer event with the timer, deletes message ptr
  132. ~WaitingMessage(void);
  133. };
  134. #endif // __MESSAGE__