SNMP++  3.6.3
eventlistholder.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## eventlistholder.h
4  _##
5  _## SNMP++ v3.4
6  _## -----------------------------------------------
7  _## Copyright (c) 2001-2021 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, Frank Fock, and Jochen Katz make no representations
21  _## about the 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 #ifndef _SNMP_EVENTLISTHOLDER_H_
29 #define _SNMP_EVENTLISTHOLDER_H_
30 
31 //----[ includes ]-----------------------------------------------------
32 #include <libsnmp.h>
33 #include "snmp_pp/config_snmp_pp.h"
34 #include "snmp_pp/snmperrs.h"
35 #include "snmp_pp/eventlist.h"
36 #include "snmp_pp/reentrant.h"
37 #include "snmp_pp/usertimeout.h"
38 #include "snmp_pp/userdefined.h"
39 
40 #ifdef SNMP_PP_NAMESPACE
41 namespace Snmp_pp {
42 #endif
43 
44 class CSNMPMessageQueue;
45 class CNotifyEventQueue;
46 class CUDEventQueue;
47 class CUTEventQueue;
48 class Pdu;
49 class Snmp;
50 
52 {
53  public:
54  EventListHolder(Snmp *snmp_session);
56 
57  CSNMPMessageQueue *&snmpEventList() { return m_snmpMessageQueue; };
58  CNotifyEventQueue *&notifyEventList() { return m_notifyEventQueue; };
59 #ifdef _USER_DEFINED_EVENTS
60  CUDEventQueue *&udEventList() { return m_udEventQueue; };
61 #endif
62 #ifdef _USER_DEFINED_TIMEOUTS
63  CUTEventQueue *&utEventList() { return m_utEventQueue; };
64 #endif
65 
66  unsigned long SNMPGetNextTimeout();
67 
68 #ifdef HAVE_POLL_SYSCALL
69  int GetFdCount();
70  bool GetFdArray(struct pollfd *readfds, int &remaining);
71 #endif
72  void SNMPGetFdSets(int & maxfds,
73  fd_set & readfds,
74  fd_set & writefds,
75  fd_set & exceptfds);
76 
77  //---------[ Main Loop ]------------------------------------------
78  /**
79  * Infinite loop which blocks when there is nothing to do and handles
80  * any events.
81  *
82  * @note If no messages are outstanding, select() is called with the
83  * given timeout, so any async messages that are sent out later
84  * are not processed until this select call returns.
85  */
86  void SNMPMainLoop(const int max_block_milliseconds = 0 /* = infinite */);
87 
88  //---------[ Exit Main Loop ]---------------------------------------
89  // Force the SNMP Main Loop to terminate immediately
90  void SNMPExitMainLoop();
91 
92  /**
93  * Block until an event shows up - then handle the event(s).
94  *
95  * @note If no messages are outstanding, select() is called with the
96  * given timeout, so any async messages that are sent out later
97  * are not processed until this select call returns.
98  */
99  int SNMPProcessEvents(const int max_block_milliseconds = 0 /* = infinite */);
100 
101  //---------[ Process Pending Events ]-------------------------------
102  // Pull all available events out of their sockets - do not block
103  int SNMPProcessPendingEvents();
104 
105  //---------[ Block For Response ]-----------------------------------
106  // Wait for the completion of an outstanding SNMP event (msg).
107  // Handle any other events as they occur.
108  int SNMPBlockForResponse(const unsigned long req_id,
109  Pdu & pdu);
110 
111  //--------[ usertimeout ]---------------------------------------------------
112 #ifdef _USER_DEFINED_TIMEOUTS
113  UtId SNMPAddTimeOut(const unsigned long interval,
114  const ut_callback callBack,
115  const void * callData);
116  void SNMPRemoveTimeOut(const UtId utId) { m_utEventQueue->DeleteEntry(utId);};
117 #endif
118 
119  //--------[ userdefined ]---------------------------------------------------
120 #ifdef _USER_DEFINED_EVENTS
121  UdId SNMPAddInput(const int source,
122  const UdInputMask condition,
123  const ud_callback callBack,
124  const void * callData);
125  void SNMPRemoveInput(const UdId udId) { m_udEventQueue->DeleteEntry(udId); };
126 #endif
127 
128 
129  private:
130 
131  CSNMPMessageQueue *m_snmpMessageQueue; // contains all outstanding messages
132  CNotifyEventQueue *m_notifyEventQueue; // contains all sessions waiting for notifications
133 #ifdef _USER_DEFINED_EVENTS
134  CUDEventQueue *m_udEventQueue; // contains all user-defined events
135 #endif
136 #ifdef _USER_DEFINED_TMEOUTS
137  CUTEventQueue *m_utEventQueue; // contains all user-defined timeouts
138 #endif
139  CEventList m_eventList; // contains all expected events
140 
142 };
143 
144 #ifdef SNMP_PP_NAMESPACE
145 } // end of namespace Snmp_pp
146 #endif
147 
148 #endif // _SNMP_EVENTLISTHOLDER_H_
unsigned long UdId
Definition: userdefined.h:98
unsigned long UtId
Definition: usertimeout.h:85
void(* ut_callback)(void *callData, UtId id)
Definition: usertimeout.h:88
CSNMPMessageQueue *& snmpEventList()
SNMP class definition.
Definition: uxsnmp.h:107
#define DLLOPT
void(* ud_callback)(void *callData, int source, UdId id)
Definition: userdefined.h:101
CNotifyEventQueue *& notifyEventList()
SnmpSynchronized pevents_mutex
CNotifyEventQueue * m_notifyEventQueue
CSNMPMessageQueue * m_snmpMessageQueue
CEventList m_eventList
unsigned long UdInputMask
Definition: userdefined.h:87
Pdu class...
Definition: pdu.h:82