1 /*_############################################################################
6 _## -----------------------------------------------
7 _## Copyright (c) 2001-2010 Jochen Katz, Frank Fock
9 _## This software is based on SNMP++2.6 from Hewlett Packard:
11 _## Copyright (c) 1996
12 _## Hewlett-Packard Company
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.
26 _## Stuttgart, Germany, Thu Sep 2 00:07:47 CEST 2010
28 _##########################################################################*/
29 /*===================================================================
32 Hewlett-Packard Company
34 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
35 Permission to use, copy, modify, distribute and/or sell this software
36 and/or its documentation is hereby granted without fee. User agrees
37 to display the above copyright notice and this license notice in all
38 copies of the software and any documentation of the software. User
39 agrees to assume all liability for the use of the software; Hewlett-Packard
40 makes no representations about the suitability of this software for any
41 purpose. It is provided "AS-IS without warranty of any kind,either express
42 or implied. User hereby grants a royalty-free license to any and all
43 derivatives based upon this software code base.
47 CSNMPMessageQueue CLASS DEFINITION
49 COPYRIGHT HEWLETT PACKARD COMPANY 1999
51 INFORMATION NETWORKS DIVISION
53 NETWORK MANAGEMENT SECTION
55 DESIGN + AUTHOR: Tom Murray
58 Queue for holing SNMP event sources (outstanding snmp messages)
60 =====================================================================*/
61 // $Id: msgqueue.h 1541 2009-05-29 11:29:22Z katz $
66 //----[ includes ]-----------------------------------------------------
67 #include <sys/types.h> // NOTE: due to 10.10 bug, order is important
68 // in that all routines must include types.h
69 // and time.h in same order otherwise you
70 // will get conflicting definitions of
71 // "fd_set" resulting in link time errors.
73 #if !(defined CPU && CPU == PPC603)
74 #include <sys/time.h> // time stuff and fd_set
78 //----[ snmp++ includes ]----------------------------------------------
79 #include "snmp_pp/config_snmp_pp.h"
80 #include "snmp_pp/address.h"
81 #include "snmp_pp/target.h"
82 #include "snmp_pp/pdu.h"
83 #include "snmp_pp/msec.h"
84 #include "snmp_pp/uxsnmp.h"
85 #include "snmp_pp/eventlist.h"
87 #ifdef SNMP_PP_NAMESPACE
91 //----[ defines ]------------------------------------------------------
95 //----[ CSNMPMessage class ]-------------------------------------------
98 /*-----------------------------------------------------------*/
100 /* a description of a single MIB access operation. */
101 /*-----------------------------------------------------------*/
102 class DLLOPT CSNMPMessage
105 CSNMPMessage(unsigned long id,
108 const SnmpTarget &target,
110 unsigned char * rawPdu,
112 const Address & address,
113 snmp_callback callBack,
115 virtual ~CSNMPMessage();
116 unsigned long GetId() const { return m_uniqueId; };
117 void ResetId(const unsigned long newId) { m_uniqueId = newId; };
119 void GetSendTime(msec &sendTime) const { sendTime = m_sendTime; };
120 SnmpSocket GetSocket() const { return m_socket; };
121 int SetPdu(const int reason, const Pdu &pdu, const UdpAddress &fromaddress);
122 int GetPdu(int &reason, Pdu &pdu)
123 { pdu = m_pdu; reason = m_reason; return 0; };
124 int GetReceived() const { return m_received; };
126 int Callback(const int reason);
127 SnmpTarget *GetTarget() { return m_target; };
131 unsigned long m_uniqueId;
135 SnmpTarget * m_target;
137 unsigned char * m_rawPdu;
140 snmp_callback m_callBack;
146 /*-----------------------------------------------------------*/
147 /* CSNMPMessageQueue */
148 /* class describing a collection of outstanding SNMP msgs. */
149 /*-----------------------------------------------------------*/
150 class DLLOPT CSNMPMessageQueue: public CEvents
153 CSNMPMessageQueue(EventListHolder *holder, Snmp *session);
154 virtual ~CSNMPMessageQueue();
155 CSNMPMessage *AddEntry(unsigned long id, Snmp *snmp, SnmpSocket socket,
156 const SnmpTarget &target, Pdu &pdu, unsigned char * rawPdu,
157 size_t rawPduLen, const Address & address,
158 snmp_callback callBack, void * callData);
159 CSNMPMessage *GetEntry(const unsigned long uniqueId);
160 int DeleteEntry(const unsigned long uniqueId);
161 void DeleteSocketEntry(const SnmpSocket socket);
162 // find the next msg that will timeout
163 CSNMPMessage *GetNextTimeoutEntry();
164 // find the next timeout
165 int GetNextTimeout(msec &sendTime);
166 #ifdef HAVE_POLL_SYSCALL
168 bool GetFdArray(struct pollfd *readfds, int &remaining);
169 int HandleEvents(const struct pollfd *readfds, const int fds);
171 // set up parameters for select
172 void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
174 int HandleEvents(const int maxfds,
175 const fd_set &readfds,
176 const fd_set &writefds,
177 const fd_set &exceptfds);
180 // return number of outstanding messages
181 int GetCount() { return m_msgCount; };
183 int DoRetries(const msec &sendtime);
186 int Done(unsigned long);
190 /*---------------------------------------------------------*/
191 /* CSNMPMessageQueueElt */
192 /* a container for a single item on a linked lists of */
194 /*---------------------------------------------------------*/
195 class DLLOPT CSNMPMessageQueueElt
198 CSNMPMessageQueueElt(CSNMPMessage *message,
199 CSNMPMessageQueueElt *next,
200 CSNMPMessageQueueElt *previous);
202 ~CSNMPMessageQueueElt();
203 CSNMPMessageQueueElt *GetNext() { return m_Next; }
204 CSNMPMessage *GetMessage() { return m_message; }
205 CSNMPMessage *TestId(const unsigned long uniqueId);
209 CSNMPMessage *m_message;
210 class CSNMPMessageQueueElt *m_Next;
211 class CSNMPMessageQueueElt *m_previous;
214 CSNMPMessageQueueElt m_head;
216 EventListHolder *my_holder;
220 #ifdef SNMP_PP_NAMESPACE
221 } // end of namespace Snmp_pp