1 /*_############################################################################
6 _## -----------------------------------------------
7 _## Copyright (c) 2001-2010 Jochen Katz, Frank Fock
9 _## This software is based on SNMP++2.6 from Hewlett Packard:
11 _## Copyright (c) 1996
12 _## Hewlett-Packard Company
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.
26 _## Stuttgart, Germany, Thu Sep 2 00:07:47 CEST 2010
28 _##########################################################################*/
29 /*===================================================================
32 Hewlett-Packard Company
34 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
35 Permission to use, copy, modify, distribute and/or sell this software
36 and/or its documentation is hereby granted without fee. User agrees
37 to display the above copyright notice and this license notice in all
38 copies of the software and any documentation of the software. User
39 agrees to assume all liability for the use of the software; Hewlett-Packard
40 makes no representations about the suitability of this software for any
41 purpose. It is provided "AS-IS without warranty of any kind,either express
42 or implied. User hereby grants a royalty-free license to any and all
43 derivatives based upon this software code base.
47 CEventList CLASS DEFINITION
49 COPYRIGHT HEWLETT PACKARD COMPANY 1999
51 INFORMATION NETWORKS DIVISION
53 NETWORK MANAGEMENT SECTION
55 DESIGN + AUTHOR: Tom Murray
58 Queue for holding all event sources (snmp messages, user
59 defined input sources, user defined timeouts, etc)
60 =====================================================================*/
61 // $Id: eventlist.h 1541 2009-05-29 11:29:22Z katz $
66 //----[ includes ]-----------------------------------------------------
68 #include <sys/types.h> // NOTE: due to 10.10 bug, order is important
69 // in that all routines must include types.h
70 // and time.h in same order otherwise you
71 // will get conflicting definitions of
72 // "fd_set" resulting in link time errors.
76 #if !(defined CPU && CPU == PPC603)
77 #include <sys/time.h> // time stuff and fd_set
82 #include "snmp_pp/config_snmp_pp.h"
83 #include "snmp_pp/reentrant.h"
85 #ifdef SNMP_PP_NAMESPACE
89 #define MAX_UINT32 MAXLONG
94 //----[ CEvents class ]------------------------------------------------
95 class DLLOPT CEvents: public SnmpSynchronized {
98 // allow destruction of derived classes
99 virtual ~CEvents() {};
101 // find the next timeout
102 virtual int GetNextTimeout(msec &sendTime) = 0;
104 // set up parameters for select/poll
105 #ifdef HAVE_POLL_SYSCALL
106 virtual int GetFdCount() = 0;
107 virtual bool GetFdArray(struct pollfd *readfds, int &remaining) = 0;
108 virtual int HandleEvents(const struct pollfd *readfds, const int fds) = 0;
110 virtual void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
111 fd_set &exceptfds) = 0;
112 // process events pending on the active file descriptors
113 virtual int HandleEvents(const int maxfds,
114 const fd_set &readfds,
115 const fd_set &writefds,
116 const fd_set &exceptfds) = 0;
118 // return number of outstanding messages
119 virtual int GetCount() = 0;
121 // process any timeout events
122 virtual int DoRetries(const msec &sendtime) = 0;
124 // check to see if there is a termination condition
125 virtual int Done() = 0;
129 class DLLOPT CEventList: public SnmpSynchronized {
131 CEventList() : m_head(0, 0, 0), m_msgCount(0), m_done(0) {};
134 // add an event source to the list
135 CEvents *AddEntry(CEvents *events);
137 // tell main_loop to exit after one pass
138 void SetDone() REENTRANT({ m_done += 1; });
140 // see if main loop should terminate
141 int GetDone() { return m_done; };
143 // find the time of the next event that will timeout
144 int GetNextTimeout(msec &sendTime);
146 #ifdef HAVE_POLL_SYSCALL
148 bool GetFdArray(struct pollfd *readfds, int &remaining);
149 int HandleEvents(const struct pollfd *readfds, const int fds);
151 // set up paramters for select
152 void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
155 // process events pending on the active file descriptors
156 int HandleEvents(const int maxfds,
157 const fd_set &readfds,
158 const fd_set &writefds,
159 const fd_set &exceptfds);
162 // return number of outstanding messages
163 int GetCount() { return m_msgCount; };
166 // process any timeout events
167 int DoRetries(const msec &sendtime);
169 // check to see if there is a termination condition
174 class DLLOPT CEventListElt
177 CEventListElt(CEvents *events,
179 CEventListElt *previous);
182 CEventListElt *GetNext() { return m_Next; }
183 CEvents *GetEvents() { return m_events; }
188 class CEventListElt *m_Next;
189 class CEventListElt *m_previous;
192 CEventListElt m_head;
197 #ifdef SNMP_PP_NAMESPACE
198 } // end of namespace Snmp_pp