SNMP++  3.3.11
eventlist.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## eventlist.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  E V E N T L I S T . H
44 
45  CEventList 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 holding all event sources (snmp messages, user
57  defined input sources, user defined timeouts, etc)
58 =====================================================================*/
59 // $Id$
60 
61 #ifndef _SNMP_EVENTLIST_H_
62 #define _SNMP_EVENTLIST_H_
63 
64 //----[ includes ]-----------------------------------------------------
65 #include <libsnmp.h>
66 #include <limits.h>
67 #include <sys/types.h>
68 #ifdef WIN32
69 #include <time.h>
70 #else
71 #if !(defined CPU && CPU == PPC603)
72 #include <sys/time.h> // time stuff and fd_set
73 #endif
74 #include <float.h>
75 #endif
76 
77 #include "snmp_pp/config_snmp_pp.h"
78 #include "snmp_pp/reentrant.h"
79 
80 #ifdef SNMP_PP_NAMESPACE
81 namespace Snmp_pp {
82 #endif
83 
84 #define MAX_UINT32 MAXLONG
85 
86 class msec;
87 class Pdu;
88 
89 //----[ CEvents class ]------------------------------------------------
91  public:
92 
93  // allow destruction of derived classes
94  virtual ~CEvents() {};
95 
96  // find the next timeout
97  virtual int GetNextTimeout(msec &sendTime) = 0;
98 
99  // set up parameters for select/poll
100 #ifdef HAVE_POLL_SYSCALL
101  virtual int GetFdCount() = 0;
102  virtual bool GetFdArray(struct pollfd *readfds, int &remaining) = 0;
103  virtual int HandleEvents(const struct pollfd *readfds, const int fds) = 0;
104 #else
105  virtual void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
106  fd_set &exceptfds) = 0;
107  // process events pending on the active file descriptors
108  virtual int HandleEvents(const int maxfds,
109  const fd_set &readfds,
110  const fd_set &writefds,
111  const fd_set &exceptfds) = 0;
112 #endif
113  // return number of outstanding messages
114  virtual int GetCount() = 0;
115 
116  // process any timeout events
117  virtual int DoRetries(const msec &sendtime) = 0;
118 
119  // check to see if there is a termination condition
120  virtual int Done() = 0;
121 };
122 
123 
125  public:
126  CEventList() : m_head(0, 0, 0), m_msgCount(0), m_done(0) {};
127  ~CEventList();
128 
129  // add an event source to the list
130  CEvents *AddEntry(CEvents *events);
131 
132  // tell main_loop to exit after one pass
133  void SetDone() REENTRANT({ m_done += 1; });
134 
135  // see if main loop should terminate
136  int GetDone() { return m_done; };
137 
138  // find the time of the next event that will timeout
139  int GetNextTimeout(msec &sendTime);
140 
141 #ifdef HAVE_POLL_SYSCALL
142  int GetFdCount();
143  bool GetFdArray(struct pollfd *readfds, int &remaining);
144  int HandleEvents(const struct pollfd *readfds, const int fds);
145 #else
146  // set up paramters for select
147  void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
148  fd_set &exceptfds);
149 
150  // process events pending on the active file descriptors
151  int HandleEvents(const int maxfds,
152  const fd_set &readfds,
153  const fd_set &writefds,
154  const fd_set &exceptfds);
155 #endif
156 
157  // return number of outstanding messages
158  int GetCount() { return m_msgCount; };
159 
160 
161  // process any timeout events
162  int DoRetries(const msec &sendtime);
163 
164  // check to see if there is a termination condition
165  int Done();
166 
167  private:
168 
170  {
171  public:
172  CEventListElt(CEvents *events,
173  CEventListElt *next,
174  CEventListElt *previous);
175 
176  ~CEventListElt();
177  CEventListElt *GetNext() { return m_Next; }
178  CEvents *GetEvents() { return m_events; }
179 
180  private:
181 
185  };
186 
189  int m_done;
190 };
191 
192 #ifdef SNMP_PP_NAMESPACE
193 } // end of namespace Snmp_pp
194 #endif
195 
196 #endif // _SNMP_EVENTLIST_H_
int m_done
Definition: eventlist.h:189
Time handling...
Definition: msec.h:70
CEventListElt m_head
Definition: eventlist.h:187
int GetDone()
Definition: eventlist.h:136
void SetDone() REENTRANT(
Definition: eventlist.h:133
#define DLLOPT
class CEventListElt * m_Next
Definition: eventlist.h:183
#define REENTRANT(x)
Definition: reentrant.h:79
class CEventListElt * m_previous
Definition: eventlist.h:184
int m_msgCount
Definition: eventlist.h:188
virtual ~CEvents()
Definition: eventlist.h:94
Pdu class...
Definition: pdu.h:82
int GetCount()
Definition: eventlist.h:158
CEventListElt * GetNext()
Definition: eventlist.h:177