]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/include/snmp_pp/eventlist.h
Initial adding
[ssmd.git] / 3rdparty / snmp++ / include / snmp_pp / eventlist.h
1 /*_############################################################################
2   _## 
3   _##  eventlist.h  
4   _##
5   _##  SNMP++v3.2.25
6   _##  -----------------------------------------------
7   _##  Copyright (c) 2001-2010 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   _##  Stuttgart, Germany, Thu Sep  2 00:07:47 CEST 2010 
27   _##  
28   _##########################################################################*/
29 /*===================================================================
30
31   Copyright (c) 1999
32   Hewlett-Packard Company
33
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.
44
45       E V E N T L I S T . H
46
47       CEventList  CLASS DEFINITION
48
49       COPYRIGHT HEWLETT PACKARD COMPANY 1999
50
51       INFORMATION NETWORKS DIVISION
52
53       NETWORK MANAGEMENT SECTION
54
55       DESIGN + AUTHOR:         Tom Murray
56
57       DESCRIPTION:
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 $
62
63 #ifndef _EVENTLIST
64 #define _EVENTLIST
65
66 //----[ includes ]-----------------------------------------------------
67 #include <limits.h>
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.
73 #ifdef WIN32
74 #include <time.h>
75 #else
76 #if !(defined CPU && CPU == PPC603)
77 #include <sys/time.h>  // time stuff and fd_set
78 #endif
79 #include <float.h>
80 #endif
81
82 #include "snmp_pp/config_snmp_pp.h"
83 #include "snmp_pp/reentrant.h"
84
85 #ifdef SNMP_PP_NAMESPACE
86 namespace Snmp_pp {
87 #endif
88
89 #define MAX_UINT32 MAXLONG
90
91 class msec;
92 class Pdu;
93
94 //----[ CEvents class ]------------------------------------------------
95 class DLLOPT CEvents: public SnmpSynchronized {
96   public:
97
98   // allow destruction of derived classes
99   virtual ~CEvents() {};
100
101   // find the next timeout
102   virtual int GetNextTimeout(msec &sendTime) = 0;
103
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;
109 #else
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;
117 #endif
118   // return number of outstanding messages
119   virtual int GetCount() = 0;
120
121   // process any timeout events
122   virtual int DoRetries(const msec &sendtime) = 0;
123
124   // check to see if there is a termination condition
125   virtual int Done() = 0;
126 };
127
128
129 class DLLOPT CEventList: public SnmpSynchronized {
130   public:
131     CEventList() : m_head(0, 0, 0), m_msgCount(0), m_done(0) {};
132     ~CEventList();
133
134   // add an event source to the list
135   CEvents *AddEntry(CEvents *events);
136
137   // tell main_loop to exit after one pass
138   void SetDone() REENTRANT({ m_done += 1; });
139
140   // see if main loop should terminate
141   int GetDone()  { return m_done; };
142
143   // find the time of the next event that will timeout
144   int GetNextTimeout(msec &sendTime);
145
146 #ifdef HAVE_POLL_SYSCALL
147   int GetFdCount();
148   bool GetFdArray(struct pollfd *readfds, int &remaining);
149   int HandleEvents(const struct pollfd *readfds, const int fds);
150 #else
151  // set up paramters for select
152   void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
153                  fd_set &exceptfds);
154
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);
160 #endif
161
162   // return number of outstanding messages
163   int GetCount() { return m_msgCount; };
164
165
166   // process any timeout events
167   int DoRetries(const msec &sendtime);
168
169   // check to see if there is a termination condition
170   int Done();
171
172   private:
173
174    class DLLOPT CEventListElt
175    {
176     public:
177      CEventListElt(CEvents *events,
178                    CEventListElt *next,
179                    CEventListElt *previous);
180
181      ~CEventListElt();
182      CEventListElt *GetNext() { return m_Next; }
183      CEvents *GetEvents() { return m_events; }
184
185     private:
186
187      CEvents *m_events;
188      class CEventListElt *m_Next;
189      class CEventListElt *m_previous;
190    };
191
192     CEventListElt m_head;
193     int m_msgCount;
194     int m_done;
195 };
196
197 #ifdef SNMP_PP_NAMESPACE
198 } // end of namespace Snmp_pp
199 #endif 
200
201 #endif