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