00001 /*_############################################################################ 00002 _## 00003 _## usertimeout.h 00004 _## 00005 _## SNMP++v3.2.15 00006 _## ----------------------------------------------- 00007 _## Copyright (c) 2001-2004 Jochen Katz, Frank Fock 00008 _## 00009 _## This software is based on SNMP++2.6 from Hewlett Packard: 00010 _## 00011 _## Copyright (c) 1996 00012 _## Hewlett-Packard Company 00013 _## 00014 _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. 00015 _## Permission to use, copy, modify, distribute and/or sell this software 00016 _## and/or its documentation is hereby granted without fee. User agrees 00017 _## to display the above copyright notice and this license notice in all 00018 _## copies of the software and any documentation of the software. User 00019 _## agrees to assume all liability for the use of the software; 00020 _## Hewlett-Packard and Jochen Katz make no representations about the 00021 _## suitability of this software for any purpose. It is provided 00022 _## "AS-IS" without warranty of any kind, either express or implied. User 00023 _## hereby grants a royalty-free license to any and all derivatives based 00024 _## upon this software code base. 00025 _## 00026 _## Stuttgart, Germany, Tue Jan 4 21:42:42 CET 2005 00027 _## 00028 _##########################################################################*/ 00029 /*=================================================================== 00030 00031 Copyright (c) 1999 00032 Hewlett-Packard Company 00033 00034 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS. 00035 Permission to use, copy, modify, distribute and/or sell this software 00036 and/or its documentation is hereby granted without fee. User agrees 00037 to display the above copyright notice and this license notice in all 00038 copies of the software and any documentation of the software. User 00039 agrees to assume all liability for the use of the software; Hewlett-Packard 00040 makes no representations about the suitability of this software for any 00041 purpose. It is provided "AS-IS without warranty of any kind,either express 00042 or implied. User hereby grants a royalty-free license to any and all 00043 derivatives based upon this software code base. 00044 00045 U S E R T I M E O U T . H 00046 00047 CUTEventQueue CLASS DEFINITION 00048 00049 COPYRIGHT HEWLETT PACKARD COMPANY 1999 00050 00051 INFORMATION NETWORKS DIVISION 00052 00053 NETWORK MANAGEMENT SECTION 00054 00055 00056 DESIGN + AUTHOR: 00057 Tom Murray 00058 00059 LANGUAGE: 00060 ANSI C++ 00061 00062 DESCRIPTION: 00063 Queue for holding callback associated with user defined 00064 timeouts 00065 00066 =====================================================================*/ 00067 // $Id: usertimeout.h,v 1.6 2004/03/03 23:11:21 katz Exp $ 00068 00069 #ifndef _USERTIMEOUT 00070 #define _USERTIMEOUT 00071 00072 //----[ includes ]----------------------------------------------------- 00073 #ifndef WIN32 00074 #include <sys/types.h> // NOTE: due to 10.10 bug, order is important 00075 // in that all routines must include types.h 00076 // and time.h in same order otherwise you 00077 // will get conflicting definitions of 00078 // "fd_set" resulting in link time errors. 00079 #include <sys/time.h> // time stuff and fd_set 00080 #endif 00081 00082 //----[ snmp++ includes ]---------------------------------------------- 00083 #include "snmp_pp/msec.h" 00084 #include "snmp_pp/eventlist.h" 00085 00086 #ifdef SNMP_PP_NAMESPACE 00087 namespace Snmp_pp { 00088 #endif 00089 00090 //----[ defines ]------------------------------------------------------ 00091 00092 typedef unsigned long UtId; 00093 00094 /* User-defined callback */ 00095 typedef void (*ut_callback)(void * callData, UtId id); 00096 00097 class EventListHolder; 00098 00099 //----[ CUTEvent class ]------------------------------------------- 00100 00101 00102 /*-----------------------------------------------------------*/ 00103 /* CUTEvent */ 00104 /* a description of a single MIB access operation. */ 00105 /*-----------------------------------------------------------*/ 00106 class DLLOPT CUTEvent 00107 { 00108 public: 00109 CUTEvent(const UtId uniqueId, const msec &timeout, 00110 const ut_callback callBack, const void * callData); 00111 ~CUTEvent() {}; 00112 UtId GetId() { return m_uniqueId ; }; 00113 void GetTimeout(msec &timeout) { timeout = m_timeout; }; 00114 00115 int Callback(); 00116 00117 protected: 00118 UtId m_uniqueId; 00119 msec m_timeout; 00120 ut_callback m_callBack; 00121 void * m_callData; 00122 }; 00123 00124 00125 /*-----------------------------------------------------------*/ 00126 /* CUTEventQueue */ 00127 /* class describing a collection of outstanding SNMP msgs. */ 00128 /*-----------------------------------------------------------*/ 00129 class DLLOPT CUTEventQueue: public CEvents 00130 { 00131 public: 00132 CUTEventQueue(EventListHolder *holder) 00133 : m_head(0, 0, 0), m_msgCount(0), m_id(1), my_holder(holder) {}; 00134 ~CUTEventQueue(); 00135 UtId AddEntry(const msec &timeout, 00136 const ut_callback callBack, 00137 const void * callData); 00138 CUTEvent *GetEntry(const UtId uniqueId); 00139 void DeleteEntry(const UtId uniqueId); 00140 00141 UtId MakeId(); 00142 00143 // find the next msg that will timeout 00144 CUTEvent *GetNextTimeoutEntry(); 00145 00146 // find the next timeout 00147 int GetNextTimeout(msec &timeout); 00148 00149 // set up parameters for select 00150 void GetFdSets(int &/*maxfds*/, fd_set &/*readfds*/, fd_set &/*writefds*/, 00151 fd_set &/*exceptfds*/) {} // we never have any event sources 00152 00153 // return number of outstanding messages 00154 int GetCount() { return m_msgCount; }; 00155 00156 int HandleEvents(const int /*maxfds*/, 00157 const fd_set &/*readfds*/, 00158 const fd_set &/*writefds*/, 00159 const fd_set &/*exceptfds*/) 00160 { msec now; return DoRetries(now); }; 00161 00162 int DoRetries(const msec &sendtime); 00163 00164 int Done() { return 0; }; // we are never done 00165 00166 protected: 00167 00168 /*-----------------------------------------------------------*/ 00169 /* CUTEventQueueElt */ 00170 /* a container for a single item on a linked lists of */ 00171 /* CUTEvents. */ 00172 /*-----------------------------------------------------------*/ 00173 class DLLOPT CUTEventQueueElt 00174 { 00175 public: 00176 CUTEventQueueElt(CUTEvent *utevent, 00177 CUTEventQueueElt *next, 00178 CUTEventQueueElt *previous); 00179 00180 ~CUTEventQueueElt(); 00181 CUTEventQueueElt *GetNext() { return m_next; }; 00182 CUTEvent *GetUTEvent() { return m_utevent; }; 00183 CUTEvent *TestId(const UtId uniqueId); 00184 00185 private: 00186 CUTEvent *m_utevent; 00187 class CUTEventQueueElt *m_next; 00188 class CUTEventQueueElt *m_previous; 00189 }; 00190 00191 CUTEventQueueElt m_head; 00192 int m_msgCount; 00193 UtId m_id; 00194 EventListHolder *my_holder; 00195 }; 00196 00197 #ifdef SNMP_PP_NAMESPACE 00198 }; // end of namespace Snmp_pp 00199 #endif 00200 00201 #endif
1.3.2