/usr/include/assa-3.5/assa/Timer.h is in libassa-3.5-5-dev 3.5.1-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | // -*- c++ -*-
//------------------------------------------------------------------------------
// Timer.h
//------------------------------------------------------------------------------
// Copyright (c) 1999,2005 by Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------------
// Create: 09/27/1999
//------------------------------------------------------------------------------
#ifndef TIMER_H
#define TIMER_H
#if !defined(WIN32)
# include <sys/select.h>
#endif
#include <sys/time.h>
#include "EventHandler.h"
#include "assa/TimeVal.h"
namespace ASSA {
class TimerQueue; // forward declaration
/** @file Timer.h
*
* Timer class represents tuple that is stored in TimerQueue.
*/
class Timer
{
public:
/// Default constructor
Timer ();
/** Constructor used by the TimerQueue.
@param eh_ EventHandler to call upon timeout
@param tm_ Time of the day to expire the timer.
@param delta_ Absolute timeout value.
@param name_ Timer name
*/
Timer (const EventHandler* eh_,
const TimeVal& tm_,
const TimeVal& delta_,
const std::string& name_);
/// Copy constructor
Timer (const Timer& t_);
/// Destructor: do-nothing
~Timer ();
/// Assignment operator
Timer& operator= (const Timer& t_);
/// Less-that by time
bool operator< (const Timer& t_) const;
/// Equal by time
bool operator== (const Timer& t_) const;
/// Get EventHandler pointer
EventHandler* getHandler () const { return m_eh; }
/// Get Expiration Time
const TimeVal& getExpirationTime () const { return m_timer; }
/// Get Delta time
const TimeVal& getDeltaTime () const { return m_delta; }
/// Reschedule expiration time with Delta value
void rescheduleExpirationTime ();
/// Dump contents to logfile
void dump (void);
/** Set Timer ID. ID allows Reactor and application-level
code describe intelligently the kind of the Timer this is.
*/
void set_id (const std::string& id_) { m_id = id_; }
/** Retrieve Timer ID.
*/
std::string get_id () const { return m_id; }
private:
/// Pointer to EventHandler
EventHandler* m_eh;
/// When the timer should be triggered
TimeVal m_timer;
/// Absolute value used when Reactor needs to reschedule the timer
TimeVal m_delta;
/// Timer's ID
std::string m_id;
};
//------------------------------------------------------------------------------
// Timer class inlines
//------------------------------------------------------------------------------
inline
Timer::
Timer ()
: m_eh (NULL), m_id ("<unknown>")
{
trace("Timer::Timer");
}
inline
Timer::
Timer (const EventHandler* eh_, const TimeVal& tm_,
const TimeVal& delta_, const std::string& name_)
: m_eh ((EventHandler*) eh_), m_timer (tm_), m_delta (delta_), m_id (name_)
{
trace("Timer::Timer(EH*, TV&)");
}
inline
Timer::
Timer (const Timer& t_)
: m_eh (t_.m_eh), m_timer (t_.m_timer),
m_delta (t_.m_delta), m_id (t_.m_id)
{
trace("Timer::Timer(Timer&)");
}
inline
Timer::
~Timer ()
{
trace("Timer::~Timer");
}
inline Timer&
Timer::
operator=(const Timer& t_)
{
m_eh = t_.m_eh;
m_timer = t_.m_timer;
m_delta = t_.m_delta;
m_id = t_.m_id;
return *this;
}
inline bool
Timer::
operator<(const Timer& t_) const
{
return m_timer < t_.m_timer;
}
inline bool
Timer::
operator==(const Timer& t_) const
{
return m_timer == t_.m_timer;
}
inline void
Timer::
rescheduleExpirationTime ()
{
TimeVal now (TimeVal::gettimeofday ());
m_timer = now + m_delta;
}
inline void
Timer::
dump (void)
{
DL((REACT,"Timer %s (EH=%s) expires at %s (delta=%s)\n",
get_id ().c_str (),
m_eh->get_id ().c_str (),
m_timer.fmtString ().c_str(),
m_delta.fmt_mm_ss_mls ().c_str()));
}
/**
* TimerCompare class compares two Timers base on their expiration timestamp.
*/
struct TimerCompare
{
bool operator() (const Timer* t1_, const Timer* t2_) const
{
return (*t1_ < *t2_);
}
};
} // end namespace ASSA
#endif /* TIMER_H */
|