SNMP++  3.6.3
msgqueue.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## msgqueue.h
4  _##
5  _## SNMP++ v3.4
6  _## -----------------------------------------------
7  _## Copyright (c) 2001-2021 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, Frank Fock, and Jochen Katz make no representations
21  _## about the 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  void Update(unsigned char *rawPdu, size_t rawPduLen);
108  unsigned long GetId() const { return m_uniqueId; };
109  void ResetId(const unsigned long newId) { m_uniqueId = newId; };
110  void SetSendTime();
111  void GetSendTime(msec &sendTime) const { sendTime = m_sendTime; };
112  SnmpSocket GetSocket() const { return m_socket; };
113  int SetPdu(const int reason, const Pdu &pdu, const UdpAddress &fromaddress);
114  int GetPdu(int &reason, Pdu &pdu)
115  { pdu = m_pdu; reason = m_reason; return 0; };
116  int GetReceived() const { return m_received; };
117  int ResendMessage();
118  int Callback(const int reason);
119  SnmpTarget *GetTarget() { return m_target; };
120  bool IsLocked() const { return m_locked; };
121  void SetLocked(const bool l) { m_locked = l; };
122 
123  protected:
124 
125  unsigned long m_uniqueId;
131  unsigned char * m_rawPdu;
132  size_t m_rawPduLen;
135  void * m_callData;
136  int m_reason;
138  bool m_locked;
139 };
140 
141  /*-----------------------------------------------------------*/
142  /* CSNMPMessageQueue */
143  /* class describing a collection of outstanding SNMP msgs. */
144  /*-----------------------------------------------------------*/
146 {
147  public:
148  CSNMPMessageQueue(EventListHolder *holder, Snmp *session);
149  virtual ~CSNMPMessageQueue();
150  CSNMPMessage *AddEntry(unsigned long id, Snmp *snmp, SnmpSocket socket,
151  const SnmpTarget &target, Pdu &pdu, unsigned char * rawPdu,
152  size_t rawPduLen, const Address & address,
153  snmp_callback callBack, void * callData);
154  CSNMPMessage *GetEntry(const unsigned long uniqueId);
155  int DeleteEntry(const unsigned long uniqueId);
156  void DeleteSocketEntry(const SnmpSocket socket);
157  // find the next msg that will timeout
158  CSNMPMessage *GetNextTimeoutEntry();
159  // find the next timeout
160  int GetNextTimeout(msec &sendTime);
161 #ifdef HAVE_POLL_SYSCALL
162  int GetFdCount();
163  bool GetFdArray(struct pollfd *readfds, int &remaining);
164  int HandleEvents(const struct pollfd *readfds, const int fds);
165 #else
166  // set up parameters for select
167  void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
168  fd_set &exceptfds);
169  int HandleEvents(const int maxfds,
170  const fd_set &readfds,
171  const fd_set &writefds,
172  const fd_set &exceptfds);
173 #endif
174 
175  // return number of outstanding messages
176  int GetCount() { return m_msgCount; };
177 
178  int DoRetries(const msec &sendtime);
179 
180  int Done() { return 0; }
181 
182  int Done(unsigned long);
183 
184  protected:
185 
186  /*---------------------------------------------------------*/
187  /* CSNMPMessageQueueElt */
188  /* a container for a single item on a linked lists of */
189  /* CSNMPMessages. */
190  /*---------------------------------------------------------*/
192  {
193  public:
195  CSNMPMessageQueueElt *next,
196  CSNMPMessageQueueElt *previous);
197 
199  CSNMPMessageQueueElt *GetNext() { return m_Next; }
200  CSNMPMessage *GetMessage() { return m_message; }
201  CSNMPMessage *TestId(const unsigned long uniqueId);
202 
203  private:
204 
208  };
209 
214 };
215 
216 #ifdef SNMP_PP_NAMESPACE
217 } // end of namespace Snmp_pp
218 #endif
219 
220 #endif // _SNMP_MSGQUEUE_H_
class CSNMPMessageQueueElt * m_previous
Definition: msgqueue.h:207
int m_reason
Definition: msgqueue.h:136
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:138
void * m_callData
Definition: msgqueue.h:135
class CSNMPMessageQueueElt * m_Next
Definition: msgqueue.h:206
Time handling...
Definition: msec.h:70
msec m_sendTime
Definition: msgqueue.h:126
EventListHolder * my_holder
Definition: msgqueue.h:212
size_t m_rawPduLen
Definition: msgqueue.h:132
SNMP class definition.
Definition: uxsnmp.h:107
void ResetId(const unsigned long newId)
Definition: msgqueue.h:109
SnmpTarget * m_target
Definition: msgqueue.h:129
void GetSendTime(msec &sendTime) const
Definition: msgqueue.h:111
unsigned char * m_rawPdu
Definition: msgqueue.h:131
#define DLLOPT
SnmpTarget * GetTarget()
Definition: msgqueue.h:119
int m_received
Definition: msgqueue.h:137
bool IsLocked() const
Definition: msgqueue.h:120
Base class of all Address classes.
Definition: address.h:127
void SetLocked(const bool l)
Definition: msgqueue.h:121
SnmpSocket GetSocket() const
Definition: msgqueue.h:112
int GetReceived() const
Definition: msgqueue.h:116
Snmp * m_snmp
Definition: msgqueue.h:127
Snmp * m_snmpSession
Definition: msgqueue.h:213
unsigned long GetId() const
Definition: msgqueue.h:108
int SnmpSocket
snmp_callback m_callBack
Definition: msgqueue.h:134
SnmpSocket m_socket
Definition: msgqueue.h:128
Pdu class...
Definition: pdu.h:82
int GetPdu(int &reason, Pdu &pdu)
Definition: msgqueue.h:114
CSNMPMessageQueueElt * GetNext()
Definition: msgqueue.h:199
CSNMPMessageQueueElt m_head
Definition: msgqueue.h:210
Address * m_address
Definition: msgqueue.h:133
Abstract class used to provide a virtual interface into Targets.
Definition: target.h:93