SNMP++  3.6.3
userdefined.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## userdefined.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 
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  U S E R D E F I N E D . H
44 
45  CUDEventQueue CLASS DEFINITION
46 
47  COPYRIGHT HEWLETT PACKARD COMPANY 1999
48 
49  INFORMATION NETWORKS DIVISION
50 
51  NETWORK MANAGEMENT SECTION
52 
53 
54  DESIGN + AUTHOR: Tom Murray
55 
56  LANGUAGE: ANSI C++
57 
58  DESCRIPTION:
59  Queue for holding callback associated with user defined
60  input sources
61 
62 =====================================================================*/
63 
64 #ifndef _SNMP_USERDEFINED_H_
65 #define _SNMP_USERDEFINED_H_
66 
67 //----[ includes ]-----------------------------------------------------
68 #include <libsnmp.h>
69 #ifdef WIN32
70 #include <winsock.h>
71 #else
72 #include <sys/types.h>
73 #if !(defined CPU && CPU == PPC603)
74 #include <sys/time.h> // time stuff and fd_set
75 #endif
76 #endif
77 
78 //----[ snmp++ includes ]----------------------------------------------
79 #include "snmp_pp/eventlist.h"
80 #include "snmp_pp/snmperrs.h"
81 
82 #ifdef SNMP_PP_NAMESPACE
83 namespace Snmp_pp {
84 #endif
85 
86 class msec;
88 
89 //----[ defines ]------------------------------------------------------
90 
91 // Modeled after XtInputMask
92 typedef unsigned long UdInputMask;
93 #define UdInputNoneMask 0L
94 #define UdInputReadMask (1L<<0)
95 #define UdInputWriteMask (1L<<1)
96 #define UdInputExceptMask (1L<<2)
97 
98 typedef unsigned long UdId;
99 
100 /* User-defined callback*/
101 typedef void (*ud_callback)(void * callData, int source, UdId id);
102 
103 
104 //----[ CUDEvent class ]-----------------------------------------------
105 
106 
108 {
109  public:
110  CUDEvent (const UdId uniqueId, const int fd,
111  const UdInputMask mask, const ud_callback callBack,
112  const void * callData);
113  ~CUDEvent() {};
114  UdId GetId() const { return m_uniqueId; };
115  int GetFd() const { return m_fd; };
116  UdInputMask GetMask() const { return m_mask; };
117 
118  int Callback();
119 
120  protected:
122  int m_fd;
125  void * m_callData;
126 };
127 
128  /*-----------------------------------------------------------*/
129  /* CUDEventQueue */
130  /* class describing a collection of outstanding SNMP msgs. */
131  /*-----------------------------------------------------------*/
133 {
134  public:
136  : m_head(0, 0, 0), m_msgCount(0), m_id(1), my_holder(holder) {};
137  ~CUDEventQueue();
138  UdId AddEntry(const int fd, const UdInputMask mask,
139  const ud_callback callBack, const void * callData);
140  CUDEvent *GetEntry(const UdId uniqueId);
141  void DeleteEntry(const UdId uniqueId);
142 
143  UdId MakeId();
144 
145  // find the next timeout
146  int GetNextTimeout(msec &/*sendTime*/)
147  { return SNMP_CLASS_INVALID_OPERATION; }; // We never have a timeout
148 
149  // set up parameters for select
150  void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
151  fd_set &exceptfds);
152  // return number of user-defined event handlers
153  int GetCount() { return m_msgCount; };
154 
155  int HandleEvents(const int maxfds, const fd_set &readfds,
156  const fd_set &writefds, const fd_set &exceptfds);
157 
158  int DoRetries(const msec &/*sendtime*/)
159  { return SNMP_CLASS_SUCCESS; }; // no timeouts, so just return;
160 
161  int Done() { return 0; }; // we are never done
162 
163  protected:
164 
165  /*-----------------------------------------------------------*/
166  /* CUDEventQueueElt */
167  /* a container for a single item on a linked lists of */
168  /* CUDEvents. */
169  /*-----------------------------------------------------------*/
171  {
172  public:
173  CUDEventQueueElt(CUDEvent *udevent,
174  CUDEventQueueElt *next,
175  CUDEventQueueElt *previous);
176 
177  ~CUDEventQueueElt();
178  CUDEventQueueElt *GetNext() { return m_Next; }
179  CUDEvent *GetUDEvent() { return m_udevent ; }
180  CUDEvent *TestId(const UdId uniqueId);
181 
182  private:
183 
187  };
188 
193 };
194 
195 #ifdef SNMP_PP_NAMESPACE
196 } // end of namespace Snmp_pp
197 #endif
198 
199 #endif // _SNMP_USERDEFINED_H_
ud_callback m_callBack
Definition: userdefined.h:124
CUDEventQueueElt m_head
Definition: userdefined.h:189
unsigned long UdId
Definition: userdefined.h:98
class CUDEventQueueElt * m_previous
Definition: userdefined.h:186
int GetNextTimeout(msec &)
Definition: userdefined.h:146
int GetFd() const
Definition: userdefined.h:115
int DoRetries(const msec &)
Definition: userdefined.h:158
Time handling...
Definition: msec.h:70
UdInputMask m_mask
Definition: userdefined.h:123
#define SNMP_CLASS_INVALID_OPERATION
snmp operation not allowed for specified target
Definition: snmperrs.h:120
#define DLLOPT
CUDEventQueue(EventListHolder *holder)
Definition: userdefined.h:135
UdId m_uniqueId
Definition: userdefined.h:121
void(* ud_callback)(void *callData, int source, UdId id)
Definition: userdefined.h:101
EventListHolder * my_holder
Definition: userdefined.h:192
void * m_callData
Definition: userdefined.h:125
unsigned long UdInputMask
Definition: userdefined.h:87
CUDEventQueueElt * GetNext()
Definition: userdefined.h:178
class CUDEventQueueElt * m_Next
Definition: userdefined.h:185
#define SNMP_CLASS_SUCCESS
success
Definition: snmperrs.h:101
UdInputMask GetMask() const
Definition: userdefined.h:116
UdId GetId() const
Definition: userdefined.h:114