Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

msgqueue.h

Go to the documentation of this file.
00001 /*_############################################################################
00002   _## 
00003   _##  msgqueue.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       M S G Q U E U E . H
00046 
00047       CSNMPMessageQueue 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       OPERATING SYSTEMS:
00063         DOS/WINDOWS 3.1
00064         BSD UNIX
00065 
00066       DESCRIPTION:
00067         Queue for holing SNMP event sources (outstanding snmp messages)
00068 
00069       COMPILER DIRECTIVES:
00070         UNIX - For UNIX build
00071 
00072 =====================================================================*/
00073 // $Id: msgqueue.h,v 1.7 2004/03/03 23:11:21 katz Exp $
00074 
00075 #ifndef _MSGQUEUE
00076 #define _MSGQUEUE
00077 
00078 //----[ includes ]-----------------------------------------------------
00079 #include <sys/types.h>          // NOTE:  due to 10.10 bug, order is important
00080                                 //   in that all routines must include types.h
00081                                 //   and time.h in same order otherwise you
00082                                 //   will get conflicting definitions of
00083                                 //   "fd_set" resulting in link time errors.
00084 // CK Ng    added #ifdef WIN32
00085 #ifdef WIN32
00086 #include <winsock.h>
00087 #else
00088 #include <sys/time.h>   // time stuff and fd_set
00089 #endif
00090 
00091 //----[ snmp++ includes ]----------------------------------------------
00092 #include "snmp_pp/address.h"   // class def for addresses
00093 #include "snmp_pp/target.h"    // class def for targets
00094 #include "snmp_pp/pdu.h"
00095 #include "snmp_pp/msec.h"
00096 #include "snmp_pp/uxsnmp.h"      // class def for snmp
00097 #include "snmp_pp/eventlist.h"
00098 
00099 #ifdef SNMP_PP_NAMESPACE
00100 namespace Snmp_pp {
00101 #endif
00102 
00103 //----[ defines ]------------------------------------------------------
00104 
00105 
00106 
00107 //----[ CSNMPMessage class ]-------------------------------------------
00108 
00109 
00110   /*-----------------------------------------------------------*/
00111   /* CSNMPMessage                                              */
00112   /*   a description of a single MIB access operation.         */
00113   /*-----------------------------------------------------------*/
00114 class DLLOPT CSNMPMessage
00115 {
00116  public:
00117   CSNMPMessage(unsigned long id,
00118                Snmp * snmp,
00119                int socket,
00120                const SnmpTarget &target,
00121                Pdu &pdu,
00122                unsigned char * rawPdu,
00123                size_t rawPduLen,
00124                const Address & address,
00125                snmp_callback callBack,
00126                void * callData);
00127   virtual ~CSNMPMessage();
00128   unsigned long GetId() const { return m_uniqueId; };
00129   void ResetId(const unsigned long newId) { m_uniqueId = newId; };
00130   void SetSendTime();
00131   void GetSendTime(msec &sendTime) const { sendTime = m_sendTime; };
00132   int GetSocket() const { return m_socket; };
00133   int SetPdu(const int reason, const Pdu &pdu, const UdpAddress &fromaddress);
00134   int GetPdu(int &reason, Pdu &pdu)
00135                                  { pdu = m_pdu; reason = m_reason; return 0; };
00136   int GetReceived() const { return m_received; };
00137   int ResendMessage();
00138   int Callback(const int reason);
00139 
00140  protected:
00141 
00142   unsigned long   m_uniqueId;
00143   msec            m_sendTime;
00144   Snmp *          m_snmp;
00145   int             m_socket;
00146   SnmpTarget *    m_target;
00147   Pdu             m_pdu;
00148   unsigned char * m_rawPdu;
00149   size_t          m_rawPduLen;
00150   Address *       m_address;
00151   snmp_callback   m_callBack;
00152   void *          m_callData;
00153   int             m_reason;
00154   int             m_received;
00155 };
00156 
00157   /*-----------------------------------------------------------*/
00158   /* CSNMPMessageQueue                                         */
00159   /*   class describing a collection of outstanding SNMP msgs. */
00160   /*-----------------------------------------------------------*/
00161 class DLLOPT CSNMPMessageQueue: public CEvents
00162 {
00163  public:
00164     CSNMPMessageQueue(EventListHolder *holder, Snmp *session);
00165     virtual ~CSNMPMessageQueue();
00166     CSNMPMessage *AddEntry(unsigned long id,Snmp * snmp, int socket,
00167                            const SnmpTarget &target, Pdu &pdu, unsigned char * rawPdu,
00168                            size_t rawPduLen, const Address & address,
00169                            snmp_callback callBack, void * callData);
00170     CSNMPMessage *GetEntry(const unsigned long uniqueId);
00171     int DeleteEntry(const unsigned long uniqueId);
00172     void DeleteSocketEntry(const int socket);
00173   // find the next msg that will timeout
00174     CSNMPMessage *GetNextTimeoutEntry();
00175   // find the next timeout
00176     int GetNextTimeout(msec &sendTime);
00177   // set up parameters for select
00178     void GetFdSets(int &maxfds, fd_set &readfds, fd_set &writefds,
00179                   fd_set &exceptfds);
00180   // return number of outstanding messages
00181     int GetCount() { return m_msgCount; };
00182 
00183   // tell the queue we are looking for an id
00184     void PushId(const unsigned long id);
00185     unsigned long PeekId();
00186     int HandleEvents(const int maxfds,
00187                      const fd_set &readfds,
00188                      const fd_set &writefds,
00189                      const fd_set &exceptfds);
00190     int DoRetries(const msec &sendtime);
00191 
00192     int Done();
00193     int Done(unsigned long);
00194 
00195  protected:
00196 
00197     /*---------------------------------------------------------*/
00198     /* CSNMPMessageQueueElt                                    */
00199     /*   a container for a single item on a linked lists of    */
00200     /*  CSNMPMessages.                                         */
00201     /*---------------------------------------------------------*/
00202     class DLLOPT CSNMPMessageQueueElt
00203     {
00204      public:
00205       CSNMPMessageQueueElt(CSNMPMessage *message,
00206                            CSNMPMessageQueueElt *next,
00207                            CSNMPMessageQueueElt *previous);
00208 
00209       ~CSNMPMessageQueueElt();
00210       CSNMPMessageQueueElt *GetNext() { return m_next; };
00211       CSNMPMessage *GetMessage() { return m_message; };
00212       CSNMPMessage *TestId(const unsigned long uniqueId);
00213 
00214      private:
00215 
00216       CSNMPMessage *m_message;
00217       class CSNMPMessageQueueElt *m_next;
00218       class CSNMPMessageQueueElt *m_previous;
00219     };
00220 
00221     CSNMPMessageQueueElt m_head;
00222     int m_msgCount;
00223     unsigned long *m_idStack;
00224     int m_stackTop;
00225     int m_stackSize;
00226     EventListHolder *my_holder;
00227     Snmp *m_snmpSession;
00228 };
00229 
00230 #ifdef SNMP_PP_NAMESPACE
00231 }; // end of namespace Snmp_pp
00232 #endif 
00233 
00234 #endif

Generated on Tue Jan 4 22:42:13 2005 for SNMP++ by doxygen 1.3.2