SNMP++  3.3.4
msgqueue.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## msgqueue.h
4  _##
5  _## SNMP++ v3.3
6  _## -----------------------------------------------
7  _## Copyright (c) 2001-2013 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  _##########################################################################*/
27 /*===================================================================
28 
29  Copyright (c) 1999
30  Hewlett-Packard Company
31 
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 
43  M S G Q U E U E . H
44 
45  CSNMPMessageQueue CLASS DEFINITION
46 
47  COPYRIGHT HEWLETT PACKARD COMPANY 1999
48 
49  INFORMATION NETWORKS DIVISION
50 
51  NETWORK MANAGEMENT SECTION
52 
53  DESIGN + AUTHOR: Tom Murray
54 
55  DESCRIPTION:
56  Queue for holing SNMP event sources (outstanding snmp messages)
57 
58 =====================================================================*/
59 // $Id: msgqueue.h 2359 2013-05-09 20:07:01Z fock $
60 
61 #ifndef _MSGQUEUE
62 #define _MSGQUEUE
63 
64 //----[ includes ]-----------------------------------------------------
65 #include <sys/types.h> // NOTE: due to 10.10 bug, order is important
66  // in that all routines must include types.h
67  // and time.h in same order otherwise you
68  // will get conflicting definitions of
69  // "fd_set" resulting in link time errors.
70 #ifndef WIN32
71 #if !(defined CPU && CPU == PPC603)
72 #include <sys/time.h> // time stuff and fd_set
73 #endif
74 #endif
75 
76 //----[ snmp++ includes ]----------------------------------------------
77 #include "snmp_pp/config_snmp_pp.h"
78 #include "snmp_pp/address.h"
79 #include "snmp_pp/target.h"
80 #include "snmp_pp/pdu.h"
81 #include "snmp_pp/msec.h"
82 #include "snmp_pp/uxsnmp.h"
83 #include "snmp_pp/eventlist.h"
84 
85 #ifdef SNMP_PP_NAMESPACE
86 namespace Snmp_pp {
87 #endif
88 
89 //----[ defines ]------------------------------------------------------
90 
91 
92 
93 //----[ CSNMPMessage class ]-------------------------------------------
94 
95 
96  /*-----------------------------------------------------------*/
97  /* CSNMPMessage */
98  /* a description of a single MIB access operation. */
99  /*-----------------------------------------------------------*/
101 {
102  public:
103  CSNMPMessage(unsigned long id,
104  Snmp * snmp,
105  SnmpSocket socket,
106  const SnmpTarget &target,
107  Pdu &pdu,
108  unsigned char * rawPdu,
109  size_t rawPduLen,
110  const Address & address,
111  snmp_callback callBack,
112  void * callData);
113  virtual ~CSNMPMessage();
114  unsigned long GetId() const { return m_uniqueId; };
115  void ResetId(const unsigned long newId) { m_uniqueId = newId; };
116  void SetSendTime();
117  void GetSendTime(msec &sendTime) const { sendTime = m_sendTime; };
118  SnmpSocket GetSocket() const { return m_socket; };
119  int SetPdu(const int reason, const Pdu &pdu, const UdpAddress &fromaddress);
120  int GetPdu(int &reason, Pdu &pdu)
121  { pdu = m_pdu; reason = m_reason; return 0; };
122  int GetReceived() const { return m_received; };
123  int ResendMessage();
124  int Callback(const int reason);
125  SnmpTarget *GetTarget() { return m_target; };
126  bool IsLocked() const { return m_locked; };
127  void SetLocked(const bool l) { m_locked = l; };
128 
129  protected:
130 
131  unsigned long m_uniqueId;
137  unsigned char * m_rawPdu;
138  size_t m_rawPduLen;
141  void * m_callData;
142  int m_reason;
144  bool m_locked;
145 };
146 
147  /*-----------------------------------------------------------*/
148  /* CSNMPMessageQueue */
149  /* class describing a collection of outstanding SNMP msgs. */
150  /*-----------------------------------------------------------*/
152 {
153  public:
154  CSNMPMessageQueue(EventListHolder *holder, Snmp *session);
155  virtual ~CSNMPMessageQueue();
156  CSNMPMessage *AddEntry(unsigned long id, Snmp *snmp, SnmpSocket socket,
157  const SnmpTarget &target, Pdu &pdu, unsigned char * rawPdu,
158  size_t rawPduLen, const Address & address,
159  snmp_callback callBack, void * callData);
160  CSNMPMessage *GetEntry(const unsigned long uniqueId);
161  int DeleteEntry(const unsigned long uniqueId);
162  void DeleteSocketEntry(const SnmpSocket socket);
163  // find the next msg that will timeout
164  CSNMPMessage *GetNextTimeoutEntry();
165  // find the next timeout
166  int GetNextTimeout(msec &sendTime);
167 #ifdef HAVE_POLL_SYSCALL
168  int GetFdCount();
169  bool GetFdArray(struct pollfd *readfds, int &remaining);
170  int HandleEvents(const struct pollfd *readfds, const int fds);
171 #else
172  // set up parameters for select
173  void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
174  fd_set &exceptfds);
175  int HandleEvents(const int maxfds,
176  const fd_set &readfds,
177  const fd_set &writefds,
178  const fd_set &exceptfds);
179 #endif
180 
181  // return number of outstanding messages
182  int GetCount() { return m_msgCount; };
183 
184  int DoRetries(const msec &sendtime);
185 
186  int Done();
187  int Done(unsigned long);
188 
189  protected:
190 
191  /*---------------------------------------------------------*/
192  /* CSNMPMessageQueueElt */
193  /* a container for a single item on a linked lists of */
194  /* CSNMPMessages. */
195  /*---------------------------------------------------------*/
197  {
198  public:
200  CSNMPMessageQueueElt *next,
201  CSNMPMessageQueueElt *previous);
202 
204  CSNMPMessageQueueElt *GetNext() { return m_Next; }
205  CSNMPMessage *GetMessage() { return m_message; }
206  CSNMPMessage *TestId(const unsigned long uniqueId);
207 
208  private:
209 
213  };
214 
219 };
220 
221 #ifdef SNMP_PP_NAMESPACE
222 } // end of namespace Snmp_pp
223 #endif
224 
225 #endif
class CSNMPMessageQueueElt * m_previous
Definition: msgqueue.h:212
void GetSendTime(msec &sendTime) const
Definition: msgqueue.h:117
int m_reason
Definition: msgqueue.h:142
bool m_locked
Definition: msgqueue.h:144
void * m_callData
Definition: msgqueue.h:141
class CSNMPMessageQueueElt * m_Next
Definition: msgqueue.h:211
Time handling...
Definition: msec.h:79
msec m_sendTime
Definition: msgqueue.h:132
unsigned long GetId() const
Definition: msgqueue.h:114
EventListHolder * my_holder
Definition: msgqueue.h:217
size_t m_rawPduLen
Definition: msgqueue.h:138
SNMP class defintion.
Definition: uxsnmp.h:99
void ResetId(const unsigned long newId)
Definition: msgqueue.h:115
SnmpTarget * m_target
Definition: msgqueue.h:135
unsigned char * m_rawPdu
Definition: msgqueue.h:137
#define DLLOPT
SnmpTarget * GetTarget()
Definition: msgqueue.h:125
int m_received
Definition: msgqueue.h:143
Base class of all Address classes.
Definition: address.h:125
void SetLocked(const bool l)
Definition: msgqueue.h:127
Snmp * m_snmp
Definition: msgqueue.h:133
Snmp * m_snmpSession
Definition: msgqueue.h:218
bool IsLocked() const
Definition: msgqueue.h:126
int SnmpSocket
snmp_callback m_callBack
Definition: msgqueue.h:140
SnmpSocket m_socket
Definition: msgqueue.h:134
Pdu class...
Definition: pdu.h:81
int GetPdu(int &reason, Pdu &pdu)
Definition: msgqueue.h:120
CSNMPMessageQueueElt * GetNext()
Definition: msgqueue.h:204
SnmpSocket GetSocket() const
Definition: msgqueue.h:118
CSNMPMessageQueueElt m_head
Definition: msgqueue.h:215
Address * m_address
Definition: msgqueue.h:139
void(* snmp_callback)(int reason, Snmp *session, Pdu &pdu, SnmpTarget &target, void *data)
Async methods of the class Snmp require the caller to provide a callback address of a function with t...
Definition: uxsnmp.h:77
Abstract class used to provide a virtual interface into Targets.
Definition: target.h:92
int GetReceived() const
Definition: msgqueue.h:122