SNMP++  3.3.11
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$
60 
61 #ifndef _SNMP_MSGQUEUE_H_
62 #define _SNMP_MSGQUEUE_H_
63 
64 //----[ includes ]-----------------------------------------------------
65 #include <libsnmp.h>
66 
67 #ifndef WIN32
68 #if !(defined CPU && CPU == PPC603)
69 #include <sys/time.h> // time stuff and fd_set
70 #endif
71 #endif
72 
73 //----[ snmp++ includes ]----------------------------------------------
74 #include "snmp_pp/config_snmp_pp.h"
75 #include "snmp_pp/address.h"
76 #include "snmp_pp/target.h"
77 #include "snmp_pp/pdu.h"
78 #include "snmp_pp/msec.h"
79 #include "snmp_pp/uxsnmp.h"
80 #include "snmp_pp/eventlist.h"
81 
82 #ifdef SNMP_PP_NAMESPACE
83 namespace Snmp_pp {
84 #endif
85 
86 
87 //----[ CSNMPMessage class ]-------------------------------------------
88 
89  /*-----------------------------------------------------------*/
90  /* CSNMPMessage */
91  /* a description of a single MIB access operation. */
92  /*-----------------------------------------------------------*/
94 {
95  public:
96  CSNMPMessage(unsigned long id,
97  Snmp * snmp,
98  SnmpSocket socket,
99  const SnmpTarget &target,
100  Pdu &pdu,
101  unsigned char * rawPdu,
102  size_t rawPduLen,
103  const Address & address,
104  snmp_callback callBack,
105  void * callData);
106  virtual ~CSNMPMessage();
107  unsigned long GetId() const { return m_uniqueId; };
108  void ResetId(const unsigned long newId) { m_uniqueId = newId; };
109  void SetSendTime();
110  void GetSendTime(msec &sendTime) const { sendTime = m_sendTime; };
111  SnmpSocket GetSocket() const { return m_socket; };
112  int SetPdu(const int reason, const Pdu &pdu, const UdpAddress &fromaddress);
113  int GetPdu(int &reason, Pdu &pdu)
114  { pdu = m_pdu; reason = m_reason; return 0; };
115  int GetReceived() const { return m_received; };
116  int ResendMessage();
117  int Callback(const int reason);
118  SnmpTarget *GetTarget() { return m_target; };
119  bool IsLocked() const { return m_locked; };
120  void SetLocked(const bool l) { m_locked = l; };
121 
122  protected:
123 
124  unsigned long m_uniqueId;
130  unsigned char * m_rawPdu;
131  size_t m_rawPduLen;
134  void * m_callData;
135  int m_reason;
137  bool m_locked;
138 };
139 
140  /*-----------------------------------------------------------*/
141  /* CSNMPMessageQueue */
142  /* class describing a collection of outstanding SNMP msgs. */
143  /*-----------------------------------------------------------*/
145 {
146  public:
147  CSNMPMessageQueue(EventListHolder *holder, Snmp *session);
148  virtual ~CSNMPMessageQueue();
149  CSNMPMessage *AddEntry(unsigned long id, Snmp *snmp, SnmpSocket socket,
150  const SnmpTarget &target, Pdu &pdu, unsigned char * rawPdu,
151  size_t rawPduLen, const Address & address,
152  snmp_callback callBack, void * callData);
153  CSNMPMessage *GetEntry(const unsigned long uniqueId);
154  int DeleteEntry(const unsigned long uniqueId);
155  void DeleteSocketEntry(const SnmpSocket socket);
156  // find the next msg that will timeout
157  CSNMPMessage *GetNextTimeoutEntry();
158  // find the next timeout
159  int GetNextTimeout(msec &sendTime);
160 #ifdef HAVE_POLL_SYSCALL
161  int GetFdCount();
162  bool GetFdArray(struct pollfd *readfds, int &remaining);
163  int HandleEvents(const struct pollfd *readfds, const int fds);
164 #else
165  // set up parameters for select
166  void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
167  fd_set &exceptfds);
168  int HandleEvents(const int maxfds,
169  const fd_set &readfds,
170  const fd_set &writefds,
171  const fd_set &exceptfds);
172 #endif
173 
174  // return number of outstanding messages
175  int GetCount() { return m_msgCount; };
176 
177  int DoRetries(const msec &sendtime);
178 
179  int Done();
180  int Done(unsigned long);
181 
182  protected:
183 
184  /*---------------------------------------------------------*/
185  /* CSNMPMessageQueueElt */
186  /* a container for a single item on a linked lists of */
187  /* CSNMPMessages. */
188  /*---------------------------------------------------------*/
190  {
191  public:
193  CSNMPMessageQueueElt *next,
194  CSNMPMessageQueueElt *previous);
195 
197  CSNMPMessageQueueElt *GetNext() { return m_Next; }
198  CSNMPMessage *GetMessage() { return m_message; }
199  CSNMPMessage *TestId(const unsigned long uniqueId);
200 
201  private:
202 
206  };
207 
212 };
213 
214 #ifdef SNMP_PP_NAMESPACE
215 } // end of namespace Snmp_pp
216 #endif
217 
218 #endif // _SNMP_MSGQUEUE_H_
class CSNMPMessageQueueElt * m_previous
Definition: msgqueue.h:205
int m_reason
Definition: msgqueue.h:135
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:78
bool m_locked
Definition: msgqueue.h:137
void * m_callData
Definition: msgqueue.h:134
class CSNMPMessageQueueElt * m_Next
Definition: msgqueue.h:204
Time handling...
Definition: msec.h:70
msec m_sendTime
Definition: msgqueue.h:125
EventListHolder * my_holder
Definition: msgqueue.h:210
size_t m_rawPduLen
Definition: msgqueue.h:131
SNMP class definition.
Definition: uxsnmp.h:107
void ResetId(const unsigned long newId)
Definition: msgqueue.h:108
SnmpTarget * m_target
Definition: msgqueue.h:128
void GetSendTime(msec &sendTime) const
Definition: msgqueue.h:110
unsigned char * m_rawPdu
Definition: msgqueue.h:130
#define DLLOPT
SnmpTarget * GetTarget()
Definition: msgqueue.h:118
int m_received
Definition: msgqueue.h:136
bool IsLocked() const
Definition: msgqueue.h:119
Base class of all Address classes.
Definition: address.h:125
void SetLocked(const bool l)
Definition: msgqueue.h:120
SnmpSocket GetSocket() const
Definition: msgqueue.h:111
int GetReceived() const
Definition: msgqueue.h:115
Snmp * m_snmp
Definition: msgqueue.h:126
Snmp * m_snmpSession
Definition: msgqueue.h:211
unsigned long GetId() const
Definition: msgqueue.h:107
int SnmpSocket
snmp_callback m_callBack
Definition: msgqueue.h:133
SnmpSocket m_socket
Definition: msgqueue.h:127
Pdu class...
Definition: pdu.h:82
int GetPdu(int &reason, Pdu &pdu)
Definition: msgqueue.h:113
CSNMPMessageQueueElt * GetNext()
Definition: msgqueue.h:197
CSNMPMessageQueueElt m_head
Definition: msgqueue.h:208
Address * m_address
Definition: msgqueue.h:132
Abstract class used to provide a virtual interface into Targets.
Definition: target.h:93