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

msec.h

Go to the documentation of this file.
00001 /*_############################################################################
00002   _## 
00003   _##  msec.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   Copyright (c) 1999
00031   Hewlett-Packard Company
00032 
00033   ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
00034   Permission to use, copy, modify, distribute and/or sell this software
00035   and/or its documentation is hereby granted without fee. User agrees
00036   to display the above copyright notice and this license notice in all
00037   copies of the software and any documentation of the software. User
00038   agrees to assume all liability for the use of the software; Hewlett-Packard
00039   makes no representations about the suitability of this software for any
00040   purpose. It is provided "AS-IS without warranty of any kind,either express
00041   or implied. User hereby grants a royalty-free license to any and all
00042   derivatives based upon this software code base.
00043 */
00044 // $Id: msec.h,v 1.5 2004/03/03 23:11:21 katz Exp $
00045 
00046 #ifndef _MSEC_H_
00047 #define _MSEC_H_
00048 
00049 //----[ includes ]-----------------------------------------------------
00050 #include <sys/types.h> /* NOTE: due to 10.10 bug, order is important
00051                         * in that all routines must include types.h
00052                         * and time.h in same order otherwise you will
00053                         * get conflicting definitions of "fd_set"
00054                         * resulting in link time errors.
00055                         */
00056 // CK Ng    added #ifdef WIN32
00057 #ifdef WIN32
00058 #include <winsock.h>
00059 #else
00060 #include <sys/time.h>
00061 #include <sys/param.h>
00062 #endif
00063 
00064 #include <time.h>
00065 
00066 #include "snmp_pp/smi.h"
00067 
00068 #ifdef SNMP_PP_NAMESPACE
00069 namespace Snmp_pp {
00070 #endif
00071 
00072 //----[ defines ]------------------------------------------------------
00073 #define MSECOUTBUF 20
00074 
00075 //----[ msec class ]---------------------------------------------------
00076 /**
00077  * Time handling...
00078  */
00079 class DLLOPT msec
00080 {
00081  public:
00082   /**
00083    * Constructor, sets the time to the current system time.
00084    */
00085   msec() { refresh(); };
00086 
00087   /**
00088    * Constructor using another msec object
00089    *
00090    * @param in_msec - Time for this object
00091    */
00092   msec(const msec &in_msec) : m_time(in_msec.m_time) {};
00093 
00094   /**
00095    * Constructor using seconds and milli sconds.
00096    *
00097    * @param sec    - Seconds
00098    * @param milsec - Milli seconds
00099    */
00100   msec(const int sec, const int milsec)
00101     { m_time.tv_sec  = sec; m_time.tv_usec = milsec; };
00102 
00103   DLLOPT friend int operator==(const msec &t1, const msec &t2);
00104   DLLOPT friend int operator!=(const msec &t1, const msec &t2);
00105   DLLOPT friend int operator<(const msec &t1, const msec &t2);
00106   DLLOPT friend int operator>(const msec &t1, const msec &t2);
00107   DLLOPT friend int operator<=(const msec &t1, const msec &t2)
00108     { return((t1 < t2) || (t1 == t2)); };
00109   DLLOPT friend int operator>=(const msec &t1, const msec &t2)
00110     { return((t1 > t2) || (t1 == t2)); };
00111 
00112   msec &operator-=(const long millisec);
00113   msec &operator-=(const timeval &t1);
00114   msec &operator+=(const long millisec);
00115   msec &operator+=(const timeval &t1);
00116   msec &operator=(const msec &t)    { m_time = t.m_time; return *this; };
00117   msec &operator=(const timeval &t1);
00118 
00119   /**
00120    * Use as an unsigned long.
00121    *
00122    * @return Time in milli seconds
00123    */
00124   operator unsigned long() const
00125     { return ((m_time.tv_sec * 1000) + m_time.tv_usec); };
00126 
00127   /**
00128    * Set the time to the current system time.
00129    */
00130   void refresh();
00131 
00132   /**
00133    * Set the object out into the future as far as possible.
00134    */
00135   void SetInfinite()  { m_time.tv_sec = (time_t) -1; m_time.tv_usec = 0; };
00136 
00137   /**
00138    * Check if the time is infinite.
00139    *
00140    * @return True, if the time is infinite.
00141    */
00142   int IsInfinite() const
00143     { return ((m_time.tv_sec == (time_t) -1) && (m_time.tv_usec == 0)); };
00144 
00145   /**
00146    * Get the difference between this and the given time.
00147    * If future is before this objects time, "timeout" will be set to zero.
00148    *
00149    * @param future  - Time to compare to
00150    * @param timeout - Will be filled with the difference
00151    */
00152   void GetDelta(const msec &future, timeval &timeout) const;
00153 
00154   /**
00155    * Get the difference between this object and the current system time.
00156    * If the system time is before this objects time,
00157    * "timeout" will be set to zero.
00158    *
00159    * @param timeout - Will be filled with the difference
00160    */
00161   void GetDeltaFromNow(timeval &timeout) const
00162     { msec now; now.GetDelta(*this, timeout); };
00163 
00164   /**
00165    * Return the time as printable string.
00166    */
00167   const char *get_printable() const;
00168 
00169 private:
00170   timeval m_time;
00171   /*mutable*/ char m_output_buffer[MSECOUTBUF];
00172 };
00173 
00174 #ifdef SNMP_PP_NAMESPACE
00175 }; // end of namespace Snmp_pp
00176 #endif 
00177 
00178 #endif // _MSEC_H_

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