msgqueue.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*_############################################################################
  2. _##
  3. _## msgqueue.h
  4. _##
  5. _## SNMP++v3.2.23
  6. _## -----------------------------------------------
  7. _## Copyright (c) 2001-2007 Jochen Katz, Frank Fock
  8. _##
  9. _## This software is based on SNMP++2.6 from Hewlett Packard:
  10. _##
  11. _## Copyright (c) 1996
  12. _## Hewlett-Packard Company
  13. _##
  14. _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  15. _## Permission to use, copy, modify, distribute and/or sell this software
  16. _## and/or its documentation is hereby granted without fee. User agrees
  17. _## to display the above copyright notice and this license notice in all
  18. _## copies of the software and any documentation of the software. User
  19. _## agrees to assume all liability for the use of the software;
  20. _## Hewlett-Packard and Jochen Katz make no representations about the
  21. _## suitability of this software for any purpose. It is provided
  22. _## "AS-IS" without warranty of any kind, either express or implied. User
  23. _## hereby grants a royalty-free license to any and all derivatives based
  24. _## upon this software code base.
  25. _##
  26. _## Stuttgart, Germany, Sun Nov 11 15:10:59 CET 2007
  27. _##
  28. _##########################################################################*/
  29. /*===================================================================
  30. Copyright (c) 1999
  31. Hewlett-Packard Company
  32. ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  33. Permission to use, copy, modify, distribute and/or sell this software
  34. and/or its documentation is hereby granted without fee. User agrees
  35. to display the above copyright notice and this license notice in all
  36. copies of the software and any documentation of the software. User
  37. agrees to assume all liability for the use of the software; Hewlett-Packard
  38. makes no representations about the suitability of this software for any
  39. purpose. It is provided "AS-IS without warranty of any kind,either express
  40. or implied. User hereby grants a royalty-free license to any and all
  41. derivatives based upon this software code base.
  42. M S G Q U E U E . H
  43. CSNMPMessageQueue CLASS DEFINITION
  44. COPYRIGHT HEWLETT PACKARD COMPANY 1999
  45. INFORMATION NETWORKS DIVISION
  46. NETWORK MANAGEMENT SECTION
  47. DESIGN + AUTHOR: Tom Murray
  48. LANGUAGE: ANSI C++
  49. DESCRIPTION:
  50. Queue for holing SNMP event sources (outstanding snmp messages)
  51. =====================================================================*/
  52. // $Id: msgqueue.h 306 2007-09-14 20:01:45Z katz $
  53. #ifndef _MSGQUEUE
  54. #define _MSGQUEUE
  55. //----[ includes ]-----------------------------------------------------
  56. #include <sys/types.h> // NOTE: due to 10.10 bug, order is important
  57. // in that all routines must include types.h
  58. // and time.h in same order otherwise you
  59. // will get conflicting definitions of
  60. // "fd_set" resulting in link time errors.
  61. #ifndef WIN32
  62. #if !(defined CPU && CPU == PPC603)
  63. #include <sys/time.h> // time stuff and fd_set
  64. #endif
  65. #endif
  66. //----[ snmp++ includes ]----------------------------------------------
  67. #include "snmp_pp/config_snmp_pp.h"
  68. #include "snmp_pp/address.h"
  69. #include "snmp_pp/target.h"
  70. #include "snmp_pp/pdu.h"
  71. #include "snmp_pp/msec.h"
  72. #include "snmp_pp/uxsnmp.h"
  73. #include "snmp_pp/eventlist.h"
  74. #ifdef SNMP_PP_NAMESPACE
  75. namespace Snmp_pp {
  76. #endif
  77. //----[ defines ]------------------------------------------------------
  78. //----[ CSNMPMessage class ]-------------------------------------------
  79. /*-----------------------------------------------------------*/
  80. /* CSNMPMessage */
  81. /* a description of a single MIB access operation. */
  82. /*-----------------------------------------------------------*/
  83. class DLLOPT CSNMPMessage
  84. {
  85. public:
  86. CSNMPMessage(unsigned long id,
  87. Snmp * snmp,
  88. SnmpSocket socket,
  89. const SnmpTarget &target,
  90. Pdu &pdu,
  91. unsigned char * rawPdu,
  92. size_t rawPduLen,
  93. const Address & address,
  94. snmp_callback callBack,
  95. void * callData);
  96. virtual ~CSNMPMessage();
  97. unsigned long GetId() const { return m_uniqueId; };
  98. void ResetId(const unsigned long newId) { m_uniqueId = newId; };
  99. void SetSendTime();
  100. void GetSendTime(msec &sendTime) const { sendTime = m_sendTime; };
  101. SnmpSocket GetSocket() const { return m_socket; };
  102. int SetPdu(const int reason, const Pdu &pdu, const UdpAddress &fromaddress);
  103. int GetPdu(int &reason, Pdu &pdu)
  104. { pdu = m_pdu; reason = m_reason; return 0; };
  105. int GetReceived() const { return m_received; };
  106. int ResendMessage();
  107. int Callback(const int reason);
  108. SnmpTarget *GetTarget() { return m_target; };
  109. protected:
  110. unsigned long m_uniqueId;
  111. msec m_sendTime;
  112. Snmp * m_snmp;
  113. SnmpSocket m_socket;
  114. SnmpTarget * m_target;
  115. Pdu m_pdu;
  116. unsigned char * m_rawPdu;
  117. size_t m_rawPduLen;
  118. Address * m_address;
  119. snmp_callback m_callBack;
  120. void * m_callData;
  121. int m_reason;
  122. int m_received;
  123. };
  124. /*-----------------------------------------------------------*/
  125. /* CSNMPMessageQueue */
  126. /* class describing a collection of outstanding SNMP msgs. */
  127. /*-----------------------------------------------------------*/
  128. class DLLOPT CSNMPMessageQueue: public CEvents
  129. {
  130. public:
  131. CSNMPMessageQueue(EventListHolder *holder, Snmp *session);
  132. virtual ~CSNMPMessageQueue();
  133. CSNMPMessage *AddEntry(unsigned long id, Snmp *snmp, SnmpSocket socket,
  134. const SnmpTarget &target, Pdu &pdu, unsigned char * rawPdu,
  135. size_t rawPduLen, const Address & address,
  136. snmp_callback callBack, void * callData);
  137. CSNMPMessage *GetEntry(const unsigned long uniqueId);
  138. int DeleteEntry(const unsigned long uniqueId);
  139. void DeleteSocketEntry(const SnmpSocket socket);
  140. // find the next msg that will timeout
  141. CSNMPMessage *GetNextTimeoutEntry();
  142. // find the next timeout
  143. int GetNextTimeout(msec &sendTime);
  144. // set up parameters for select
  145. void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
  146. fd_set &exceptfds);
  147. // return number of outstanding messages
  148. int GetCount() { return m_msgCount; };
  149. // tell the queue we are looking for an id
  150. void PushId(const unsigned long id);
  151. unsigned long PeekId();
  152. int HandleEvents(const int maxfds,
  153. const fd_set &readfds,
  154. const fd_set &writefds,
  155. const fd_set &exceptfds);
  156. int DoRetries(const msec &sendtime);
  157. int Done();
  158. int Done(unsigned long);
  159. protected:
  160. /*---------------------------------------------------------*/
  161. /* CSNMPMessageQueueElt */
  162. /* a container for a single item on a linked lists of */
  163. /* CSNMPMessages. */
  164. /*---------------------------------------------------------*/
  165. class DLLOPT CSNMPMessageQueueElt
  166. {
  167. public:
  168. CSNMPMessageQueueElt(CSNMPMessage *message,
  169. CSNMPMessageQueueElt *next,
  170. CSNMPMessageQueueElt *previous);
  171. ~CSNMPMessageQueueElt();
  172. CSNMPMessageQueueElt *GetNext() { return m_Next; }
  173. CSNMPMessage *GetMessage() { return m_message; }
  174. CSNMPMessage *TestId(const unsigned long uniqueId);
  175. private:
  176. CSNMPMessage *m_message;
  177. class CSNMPMessageQueueElt *m_Next;
  178. class CSNMPMessageQueueElt *m_previous;
  179. };
  180. CSNMPMessageQueueElt m_head;
  181. int m_msgCount;
  182. unsigned long *m_idStack;
  183. int m_stackTop;
  184. int m_stackSize;
  185. EventListHolder *my_holder;
  186. Snmp *m_snmpSession;
  187. };
  188. #ifdef SNMP_PP_NAMESPACE
  189. } // end of namespace Snmp_pp
  190. #endif
  191. #endif