SNMP++  3.6.3
usertimeout.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## usertimeout.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 T I M E O U T . H
44 
45  CUTEventQueue 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  timeouts
61 
62 =====================================================================*/
63 
64 #ifndef _SNMP_USERTIMEOUT_H_
65 #define _SNMP_USERTIMEOUT_H_
66 
67 //----[ includes ]-----------------------------------------------------
68 #ifndef WIN32
69 #include <sys/types.h>
70 #if !(defined CPU && CPU == PPC603)
71 #include <sys/time.h> // time stuff and fd_set
72 #endif
73 #endif
74 
75 //----[ snmp++ includes ]----------------------------------------------
76 #include "snmp_pp/msec.h"
77 #include "snmp_pp/eventlist.h"
78 
79 #ifdef SNMP_PP_NAMESPACE
80 namespace Snmp_pp {
81 #endif
82 
83 //----[ defines ]------------------------------------------------------
84 
85 typedef unsigned long UtId;
86 
87 /* User-defined callback */
88 typedef void (*ut_callback)(void * callData, UtId id);
89 
90 class EventListHolder;
91 
92 //----[ CUTEvent class ]-------------------------------------------
93 
94 
95 /*-----------------------------------------------------------*/
96 /* CUTEvent */
97 /* a description of a single MIB access operation. */
98 /*-----------------------------------------------------------*/
100 {
101  public:
102  CUTEvent(const UtId uniqueId, const msec &timeout,
103  const ut_callback callBack, const void * callData);
104  ~CUTEvent() {};
105  UtId GetId() { return m_uniqueId ; };
106  void GetTimeout(msec &timeout) { timeout = m_timeout; };
107 
108  int Callback();
109 
110  protected:
114  void * m_callData;
115 };
116 
117 
118 /*-----------------------------------------------------------*/
119 /* CUTEventQueue */
120 /* class describing a collection of outstanding SNMP msgs. */
121 /*-----------------------------------------------------------*/
123 {
124  public:
126  : m_head(0, 0, 0), m_msgCount(0), m_id(1), my_holder(holder) {};
127  ~CUTEventQueue();
128  UtId AddEntry(const msec &timeout,
129  const ut_callback callBack,
130  const void * callData);
131  CUTEvent *GetEntry(const UtId uniqueId);
132  void DeleteEntry(const UtId uniqueId);
133 
134  UtId MakeId();
135 
136  // find the next msg that will timeout
137  CUTEvent *GetNextTimeoutEntry();
138 
139  // find the next timeout
140  int GetNextTimeout(msec &timeout);
141 
142  // set up parameters for select
143  void GetFdSets(int &/*maxfds*/, fd_set &/*readfds*/, fd_set &/*writefds*/,
144  fd_set &/*exceptfds*/) {} // we never have any event sources
145 
146  // return number of outstanding messages
147  int GetCount() { return m_msgCount; };
148 
149  int HandleEvents(const int /*maxfds*/,
150  const fd_set &/*readfds*/,
151  const fd_set &/*writefds*/,
152  const fd_set &/*exceptfds*/)
153  { msec now; return DoRetries(now); };
154 
155  int DoRetries(const msec &sendtime);
156 
157  int Done() { return 0; }; // we are never done
158 
159  protected:
160 
161  /*-----------------------------------------------------------*/
162  /* CUTEventQueueElt */
163  /* a container for a single item on a linked lists of */
164  /* CUTEvents. */
165  /*-----------------------------------------------------------*/
167  {
168  public:
169  CUTEventQueueElt(CUTEvent *utevent,
170  CUTEventQueueElt *next,
171  CUTEventQueueElt *previous);
172 
173  ~CUTEventQueueElt();
174  CUTEventQueueElt *GetNext() { return m_Next; };
175  CUTEvent *GetUTEvent() { return m_utevent; };
176  CUTEvent *TestId(const UtId uniqueId);
177 
178  private:
182  };
183 
188 };
189 
190 #ifdef SNMP_PP_NAMESPACE
191 } // end of namespace Snmp_pp
192 #endif
193 
194 #endif // _SNMP_USERTIMEOUT_H_
void * m_callData
Definition: usertimeout.h:114
msec m_timeout
Definition: usertimeout.h:112
CUTEventQueueElt m_head
Definition: usertimeout.h:184
class CUTEventQueueElt * m_Next
Definition: usertimeout.h:180
unsigned long UtId
Definition: usertimeout.h:85
UtId m_uniqueId
Definition: usertimeout.h:111
void(* ut_callback)(void *callData, UtId id)
Definition: usertimeout.h:88
Time handling...
Definition: msec.h:70
void GetTimeout(msec &timeout)
Definition: usertimeout.h:106
#define DLLOPT
void GetFdSets(int &, fd_set &, fd_set &, fd_set &)
Definition: usertimeout.h:143
CUTEventQueueElt * GetNext()
Definition: usertimeout.h:174
UtId GetId()
Definition: usertimeout.h:105
class CUTEventQueueElt * m_previous
Definition: usertimeout.h:181
EventListHolder * my_holder
Definition: usertimeout.h:187
ut_callback m_callBack
Definition: usertimeout.h:113
int HandleEvents(const int, const fd_set &, const fd_set &, const fd_set &)
Definition: usertimeout.h:149
CUTEventQueue(EventListHolder *holder)
Definition: usertimeout.h:125