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.
45 E V E N T L I S T . C P P
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 char event_list_version[]="@(#) SNMP++ $Id: eventlist.cpp 1542 2009-05-29 11:38:48Z katz $";
63 //----[ snmp++ includes ]----------------------------------------------
65 #include "snmp_pp/config_snmp_pp.h"
66 #include "snmp_pp/v3.h"
67 #include "snmp_pp/eventlist.h" // queue for holding all event sources
68 #include "snmp_pp/msgqueue.h" // queue for holding snmp event sources
69 #include "snmp_pp/notifyqueue.h" // queue for holding trap callbacks
70 #include "snmp_pp/snmperrs.h"
72 #ifdef SNMP_PP_NAMESPACE
76 //----[ CSNMPMessageQueueElt class ]--------------------------------------
78 CEventList::CEventListElt::CEventListElt(CEvents *events,
80 CEventListElt *previous):
81 m_events(events), m_Next(next), m_previous(previous)
83 /* Finish insertion into doubly linked list */
84 if (m_Next) m_Next->m_previous = this;
85 if (m_previous) m_previous->m_Next = this;
88 CEventList::CEventListElt::~CEventListElt()
90 /* Do deletion form doubly linked list */
91 if (m_Next) m_Next->m_previous = m_previous;
92 if (m_previous) m_previous->m_Next = m_Next;
93 if (m_events) delete m_events;
97 //----[ CEventList class ]--------------------------------------
100 CEventList::~CEventList()
102 CEventListElt *leftOver;
104 /* walk the list deleting any elements still on the queue */
106 while ((leftOver = m_head.GetNext()))
111 CEvents * CEventList::AddEntry(CEvents *events) REENTRANT ({
112 /*---------------------------------------------------------*/
113 /* Insert entry at head of list, done automagically by the */
114 /* constructor function, so don't use the return value. */
115 /*---------------------------------------------------------*/
116 (void) new CEventListElt(events, m_head.GetNext(), &m_head);
122 int CEventList::GetNextTimeout(msec &sendTime) REENTRANT ({
124 CEventListElt *msgEltPtr = m_head.GetNext();
125 msec tmpTime(sendTime);
127 sendTime.SetInfinite(); // set sendtime out into future
129 if (msgEltPtr->GetEvents()->GetCount() &&
130 !msgEltPtr->GetEvents()->GetNextTimeout(tmpTime)) {
131 if (sendTime > tmpTime)
135 msgEltPtr = msgEltPtr->GetNext();
140 #ifdef HAVE_POLL_SYSCALL
142 int CEventList::GetFdCount()
144 SnmpSynchronize _synchronize(*this); // instead of REENTRANT()
146 CEventListElt *msgEltPtr = m_head.GetNext();
150 count += msgEltPtr->GetEvents()->GetFdCount();
151 msgEltPtr = msgEltPtr->GetNext();
156 bool CEventList::GetFdArray(struct pollfd *readfds, int &remaining)
158 SnmpSynchronize _synchronize(*this); // instead of REENTRANT()
159 CEventListElt *msgEltPtr = m_head.GetNext();
163 int old_remaining = remaining;
164 if (msgEltPtr->GetEvents()->GetFdArray(readfds, remaining) == false)
166 readfds += (old_remaining - remaining);
167 msgEltPtr = msgEltPtr->GetNext();
172 int CEventList::HandleEvents(const struct pollfd *readfds, const int fds)
175 CEventListElt *msgEltPtr = m_head.GetNext();
176 int status = SNMP_CLASS_SUCCESS;
179 if (msgEltPtr->GetEvents()->GetCount())
182 status = msgEltPtr->GetEvents()->HandleEvents(readfds, fds);
185 msgEltPtr = msgEltPtr->GetNext();
193 void CEventList::GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
194 fd_set &exceptfds) REENTRANT ({
196 CEventListElt *msgEltPtr = m_head.GetNext();
203 if (msgEltPtr->GetEvents()->GetCount()) {
204 msgEltPtr->GetEvents()->GetFdSets(maxfds, readfds, writefds, exceptfds);
206 msgEltPtr = msgEltPtr->GetNext();
210 int CEventList::HandleEvents(const int maxfds,
211 const fd_set &readfds,
212 const fd_set &writefds,
213 const fd_set &exceptfds)
216 CEventListElt *msgEltPtr = m_head.GetNext();
217 int status = SNMP_CLASS_SUCCESS;
219 if (msgEltPtr->GetEvents()->GetCount()) {
221 status = msgEltPtr->GetEvents()->HandleEvents(maxfds, readfds, writefds,
225 msgEltPtr = msgEltPtr->GetNext();
231 #endif // HAVE_POLL_SYSCALL
233 int CEventList::DoRetries(const msec &sendtime) REENTRANT ({
235 CEventListElt *msgEltPtr = m_head.GetNext();
236 int status = SNMP_CLASS_SUCCESS;
238 if (msgEltPtr->GetEvents()->GetCount()) {
239 status = msgEltPtr->GetEvents()->DoRetries(sendtime);
241 msgEltPtr = msgEltPtr->GetNext();
246 int CEventList::Done() REENTRANT ({
248 CEventListElt *msgEltPtr = m_head.GetNext();
249 int status = SNMP_CLASS_SUCCESS;
257 if (msgEltPtr->GetEvents()->GetCount()) {
258 status = msgEltPtr->GetEvents()->Done();
262 msgEltPtr = msgEltPtr->GetNext();
267 #ifdef SNMP_PP_NAMESPACE
268 }; // end of namespace Snmp_pp