]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/include/snmp_pp/notifyqueue.h
Fix build on osx.
[ssmd.git] / 3rdparty / snmp++ / include / snmp_pp / notifyqueue.h
1 /*_############################################################################
2   _## 
3   _##  notifyqueue.h  
4   _##
5   _##  SNMP++v3.2.25
6   _##  -----------------------------------------------
7   _##  Copyright (c) 2001-2010 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 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. 
25   _##  
26   _##  Stuttgart, Germany, Thu Sep  2 00:07:47 CEST 2010 
27   _##  
28   _##########################################################################*/
29 /*===================================================================
30
31   Copyright (c) 1999
32   Hewlett-Packard Company
33
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.
44
45       N O T I F Y Q U E U E. H
46
47       CNotifyEventQueue CLASS DEFINITION
48
49       COPYRIGHT HEWLETT PACKARD COMPANY 1999
50
51       INFORMATION NETWORKS DIVISION
52
53       NETWORK MANAGEMENT SECTION
54
55       DESIGN + AUTHOR:        Tom Murray
56
57       DESCRIPTION:
58         Queue for holding sessions waiting for notifiactions
59
60 =====================================================================*/
61 // $Id: notifyqueue.h 1550 2009-06-26 19:59:30Z katz $
62
63 #ifndef _NOTIFYQUEUE
64 #define _NOTIFYQUEUE
65
66 //----[ includes ]-----------------------------------------------------
67 #include <sys/types.h>          // NOTE: due to 10.10 bug, order is important
68                                 //   in that all routines must include types.h
69                                 //   and time.h in same order otherwise you
70                                 //   will get conflicting definitions of
71                                 //   "fd_set" resulting in link time errors.
72 #ifndef WIN32
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
80 #include "snmp_pp/config_snmp_pp.h"
81 #include "snmp_pp/oid.h"
82 #include "snmp_pp/target.h"
83 #include "snmp_pp/eventlist.h"
84
85 #ifdef SNMP_PP_NAMESPACE
86 namespace Snmp_pp {
87 #endif
88
89 class Snmp; // instead of snmp_pp.h
90 class msec;
91 class EventListHolder;
92
93 //----[ defines ]------------------------------------------------------
94
95 //----[ CNotifyEvent class ]-------------------------------------------
96
97 /*----------------------------------------------------------------*/
98 /* CNotifyEvent                                                   */
99 /*   a description of a sessions waiting for async notifiactions. */
100 /*----------------------------------------------------------------*/
101 class DLLOPT CNotifyEvent
102 {
103  public:
104
105   CNotifyEvent(Snmp* snmp,
106                const OidCollection &trapids,
107                const TargetCollection &targets);
108   ~CNotifyEvent();
109   Snmp * GetId() { return m_snmp; };
110   int notify_filter(const Oid &trapid, SnmpTarget &target) const;
111   int Callback(SnmpTarget &target, Pdu &pdu, SnmpSocket fd, int status);
112   void get_filter(OidCollection &o, TargetCollection &t)
113     { o = *notify_ids; t = *notify_targets; };
114
115  protected:
116   Snmp              *m_snmp;
117   TargetCollection  *notify_targets;
118   OidCollection     *notify_ids;
119 };
120
121   /*-----------------------------------------------------------*/
122   /* CNotifyEventQueue                                         */
123   /*   class describing a collection of outstanding SNMP msgs. */
124   /*-----------------------------------------------------------*/
125 class DLLOPT CNotifyEventQueue: public CEvents
126 {
127   public:
128     CNotifyEventQueue(EventListHolder *holder, Snmp *session);
129     ~CNotifyEventQueue();
130     int AddEntry(Snmp * snmp,
131                  const OidCollection &trapids,
132                  const TargetCollection &targets);
133     CNotifyEvent * GetEntry(Snmp * snmp);
134     void DeleteEntry(Snmp * snmp);
135
136     // find the next timeout
137     int GetNextTimeout(msec &/*timeout*/) { return 1; }; // we have no timeouts
138     // set up parameters for select
139 #ifdef HAVE_POLL_SYSCALL
140     int GetFdCount();
141     bool GetFdArray(struct pollfd *readfds, int &remaining);
142     int HandleEvents(const struct pollfd *readfds, const int fds);
143 #else
144     void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
145                    fd_set &exceptfds);
146     int HandleEvents(const int maxfds,
147                      const fd_set &readfds,
148                      const fd_set &writefds,
149                      const fd_set &exceptfds);
150 #endif
151     // return number of outstanding messages
152     int GetCount() { return m_msgCount; };
153
154     int DoRetries(const msec &/*sendtime*/) { return 0; }; // nothing to retry
155
156     int Done() { return 0; }; // we are never done
157     void set_listen_port(int port) { m_listen_port = port; };
158     int get_listen_port() { return m_listen_port; };
159     SnmpSocket get_notify_fd() const;
160
161   protected:
162
163     /*-----------------------------------------------------------*/
164     /* CNotifyEventQueueElt                                      */
165     /*   a container for a single item on a linked lists of      */
166     /*  CNotifyEvents.                                           */
167     /*-----------------------------------------------------------*/
168     class DLLOPT CNotifyEventQueueElt
169     {
170      public:
171       CNotifyEventQueueElt(CNotifyEvent *notifyevent,
172                            CNotifyEventQueueElt *next,
173                            CNotifyEventQueueElt *previous);
174
175       ~CNotifyEventQueueElt();
176       CNotifyEventQueueElt *GetNext() { return m_Next; };
177       CNotifyEvent *GetNotifyEvent() { return m_notifyevent; };
178       CNotifyEvent *TestId(Snmp *snmp);
179
180     private:
181
182       CNotifyEvent *m_notifyevent;
183       class CNotifyEventQueueElt *m_Next;
184       class CNotifyEventQueueElt *m_previous;
185     };
186
187     void cleanup();
188
189     CNotifyEventQueueElt m_head;
190     int                  m_msgCount;
191     SnmpSocket           m_notify_fd;
192     int                  m_listen_port;
193     EventListHolder *my_holder;
194     Snmp *m_snmpSession;
195     UdpAddress m_notify_addr;
196 };
197
198 #ifdef SNMP_PP_NAMESPACE
199 } // end of namespace Snmp_pp
200 #endif 
201
202 #endif // NOTIFYQUEUE