1 /*_############################################################################
6 _## -----------------------------------------------
7 _## Copyright (c) 2001-2010 Jochen Katz, Frank Fock
9 _## This software is based on SNMP++2.6 from Hewlett Packard:
11 _## Copyright (c) 1996
12 _## Hewlett-Packard Company
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.
26 _## Stuttgart, Germany, Thu Sep 2 00:07:47 CEST 2010
28 _##########################################################################*/
31 Hewlett-Packard Company
33 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
34 Permission to use, copy, modify, distribute and/or sell this software
35 and/or its documentation is hereby granted without fee. User agrees
36 to display the above copyright notice and this license notice in all
37 copies of the software and any documentation of the software. User
38 agrees to assume all liability for the use of the software; Hewlett-Packard
39 makes no representations about the suitability of this software for any
40 purpose. It is provided "AS-IS without warranty of any kind,either express
41 or implied. User hereby grants a royalty-free license to any and all
42 derivatives based upon this software code base.
44 // $Id: msec.h 307 2007-09-14 20:01:45Z katz $
49 //----[ includes ]-----------------------------------------------------
50 #include <sys/types.h> /* NOTE: due to 10.10 bug, order is important
51 * in that all routines must include types.h
52 * and time.h in same order otherwise you will
53 * get conflicting definitions of "fd_set"
54 * resulting in link time errors.
57 #elif defined (CPU) && CPU == PPC603
58 #include <sys/times.h>
61 #include <sys/param.h>
66 #include "snmp_pp/config_snmp_pp.h"
67 #include "snmp_pp/smi.h"
68 #include "snmp_pp/reentrant.h"
70 #ifdef SNMP_PP_NAMESPACE
74 //----[ defines ]------------------------------------------------------
77 //----[ msec class ]---------------------------------------------------
85 * Constructor, sets the time to the current system time.
87 msec() { refresh(); };
90 * Constructor using another msec object
92 * @param in_msec - Time for this object
94 msec(const msec &in_msec) : m_time(in_msec.m_time), m_changed(true) {};
97 * Constructor using seconds and milli sconds.
99 * @param sec - Seconds
100 * @param milsec - Milli seconds
102 msec(const int sec, const int milsec) : m_changed(true)
103 { m_time.tv_sec = sec; m_time.tv_usec = milsec; };
105 DLLOPT friend int operator==(const msec &t1, const msec &t2);
106 DLLOPT friend int operator!=(const msec &t1, const msec &t2);
107 DLLOPT friend int operator<(const msec &t1, const msec &t2);
108 DLLOPT friend int operator>(const msec &t1, const msec &t2);
109 DLLOPT friend int operator<=(const msec &t1, const msec &t2)
110 { return((t1 < t2) || (t1 == t2)); };
111 DLLOPT friend int operator>=(const msec &t1, const msec &t2)
112 { return((t1 > t2) || (t1 == t2)); };
114 msec &operator-=(const long millisec);
115 msec &operator-=(const timeval &t1);
116 msec &operator+=(const long millisec);
117 msec &operator+=(const timeval &t1);
118 msec &operator=(const msec &t)
119 { m_time = t.m_time; m_changed = true; return *this; };
120 msec &operator=(const timeval &t1);
123 * Use as an unsigned long.
125 * @return Time in milli seconds
127 operator unsigned long() const
128 { return ((m_time.tv_sec * 1000) + m_time.tv_usec); };
131 * Set the time to the current system time.
136 * Set the object out into the future as far as possible.
139 { m_time.tv_sec = (time_t) -1; m_time.tv_usec = 0; m_changed = true; };
142 * Check if the time is infinite.
144 * @return True, if the time is infinite.
146 int IsInfinite() const
147 { return ((m_time.tv_sec == (time_t) -1) && (m_time.tv_usec == 0)); };
150 * Get the difference between this and the given time.
151 * If future is before this objects time, "timeout" will be set to zero.
153 * @param future - Time to compare to
154 * @param timeout - Will be filled with the difference
156 void GetDelta(const msec &future, timeval &timeout) const;
159 * Get the difference between this object and the current system time.
160 * If the system time is before this objects time,
161 * "timeout" will be set to zero.
163 * @param timeout - Will be filled with the difference
165 void GetDeltaFromNow(timeval &timeout) const
166 { msec now; now.GetDelta(*this, timeout); };
169 * Return the time as printable string.
171 const char *get_printable() const;
175 SNMP_PP_MUTABLE char m_output_buffer[MSECOUTBUF];
176 SNMP_PP_MUTABLE bool m_changed;
178 #if !defined HAVE_LOCALTIME_R && !defined HAVE_REENTRANT_LOCALTIME
180 static SnmpSynchronized m_localtime_mutex;
185 #ifdef SNMP_PP_NAMESPACE
186 } // end of namespace Snmp_pp