]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/include/snmp_pp/msgqueue.h
Initial adding
[ssmd.git] / 3rdparty / snmp++ / include / snmp_pp / msgqueue.h
1 /*_############################################################################
2   _## 
3   _##  msgqueue.h  
4   _##
5   _##  SNMP++v3.2.25
6   _##  -----------------------------------------------
7   _##  Copyright (c) 2001-2010 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, Thu Sep  2 00:07:47 CEST 2010 
27   _##  
28   _##########################################################################*/
29 /*===================================================================
30
31   Copyright (c) 1999
32   Hewlett-Packard Company
33
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.
44
45       M S G Q U E U E . H
46
47       CSNMPMessageQueue CLASS DEFINITION
48
49       COPYRIGHT HEWLETT PACKARD COMPANY 1999
50
51       INFORMATION NETWORKS DIVISION
52
53       NETWORK MANAGEMENT SECTION
54
55       DESIGN + AUTHOR:     Tom Murray
56
57       DESCRIPTION:
58         Queue for holing SNMP event sources (outstanding snmp messages)
59
60 =====================================================================*/
61 // $Id: msgqueue.h 1541 2009-05-29 11:29:22Z katz $
62
63 #ifndef _MSGQUEUE
64 #define _MSGQUEUE
65
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.
72 #ifndef WIN32
73 #if !(defined CPU && CPU == PPC603)
74 #include <sys/time.h>   // time stuff and fd_set
75 #endif
76 #endif
77
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"
86
87 #ifdef SNMP_PP_NAMESPACE
88 namespace Snmp_pp {
89 #endif
90
91 //----[ defines ]------------------------------------------------------
92
93
94
95 //----[ CSNMPMessage class ]-------------------------------------------
96
97
98   /*-----------------------------------------------------------*/
99   /* CSNMPMessage                                              */
100   /*   a description of a single MIB access operation.         */
101   /*-----------------------------------------------------------*/
102 class DLLOPT CSNMPMessage
103 {
104  public:
105   CSNMPMessage(unsigned long id,
106                Snmp * snmp,
107                SnmpSocket socket,
108                const SnmpTarget &target,
109                Pdu &pdu,
110                unsigned char * rawPdu,
111                size_t rawPduLen,
112                const Address & address,
113                snmp_callback callBack,
114                void * callData);
115   virtual ~CSNMPMessage();
116   unsigned long GetId() const { return m_uniqueId; };
117   void ResetId(const unsigned long newId) { m_uniqueId = newId; };
118   void SetSendTime();
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; };
125   int ResendMessage();
126   int Callback(const int reason);
127   SnmpTarget *GetTarget() { return m_target; };
128
129  protected:
130
131   unsigned long   m_uniqueId;
132   msec            m_sendTime;
133   Snmp *          m_snmp;
134   SnmpSocket      m_socket;
135   SnmpTarget *    m_target;
136   Pdu             m_pdu;
137   unsigned char * m_rawPdu;
138   size_t          m_rawPduLen;
139   Address *       m_address;
140   snmp_callback   m_callBack;
141   void *          m_callData;
142   int             m_reason;
143   int             m_received;
144 };
145
146   /*-----------------------------------------------------------*/
147   /* CSNMPMessageQueue                                         */
148   /*   class describing a collection of outstanding SNMP msgs. */
149   /*-----------------------------------------------------------*/
150 class DLLOPT CSNMPMessageQueue: public CEvents
151 {
152  public:
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
167     int GetFdCount();
168     bool GetFdArray(struct pollfd *readfds, int &remaining);
169     int HandleEvents(const struct pollfd *readfds, const int fds);
170 #else
171   // set up parameters for select
172     void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
173                   fd_set &exceptfds);
174     int HandleEvents(const int maxfds,
175                      const fd_set &readfds,
176                      const fd_set &writefds,
177                      const fd_set &exceptfds);
178 #endif
179
180   // return number of outstanding messages
181     int GetCount() { return m_msgCount; };
182
183     int DoRetries(const msec &sendtime);
184
185     int Done();
186     int Done(unsigned long);
187
188  protected:
189
190     /*---------------------------------------------------------*/
191     /* CSNMPMessageQueueElt                                    */
192     /*   a container for a single item on a linked lists of    */
193     /*  CSNMPMessages.                                         */
194     /*---------------------------------------------------------*/
195     class DLLOPT CSNMPMessageQueueElt
196     {
197      public:
198       CSNMPMessageQueueElt(CSNMPMessage *message,
199                            CSNMPMessageQueueElt *next,
200                            CSNMPMessageQueueElt *previous);
201
202       ~CSNMPMessageQueueElt();
203       CSNMPMessageQueueElt *GetNext() { return m_Next; }
204       CSNMPMessage *GetMessage() { return m_message; }
205       CSNMPMessage *TestId(const unsigned long uniqueId);
206
207      private:
208
209       CSNMPMessage *m_message;
210       class CSNMPMessageQueueElt *m_Next;
211       class CSNMPMessageQueueElt *m_previous;
212     };
213
214     CSNMPMessageQueueElt m_head;
215     int m_msgCount;
216     EventListHolder *my_holder;
217     Snmp *m_snmpSession;
218 };
219
220 #ifdef SNMP_PP_NAMESPACE
221 } // end of namespace Snmp_pp
222 #endif 
223
224 #endif