libassa
3.5.1
assa
TimerCountdown.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// TimerCountdown.h
4
//------------------------------------------------------------------------------
5
// Copyright (c) 1999 by Vladislav Grinchenko
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//------------------------------------------------------------------------------
12
// Created: 08/25/1999
13
//------------------------------------------------------------------------------
14
#ifndef TIMER_COUNTDOWN_H
15
#define TIMER_COUNTDOWN_H
16
17
#include "
assa/TimeVal.h
"
18
19
namespace
ASSA
{
20
28
class
TimerCountdown
29
{
30
public
:
33
TimerCountdown
(
TimeVal
* wait_time_);
34
37
~TimerCountdown
();
38
39
private
:
41
TimeVal
*
m_maxWaitTime
;
42
44
TimeVal
m_start
;
45
};
46
47
//------------------------------------------------------------------------------
48
// inlines
49
//------------------------------------------------------------------------------
50
51
inline
52
TimerCountdown::
53
TimerCountdown
(
TimeVal
* wt_)
54
: m_maxWaitTime (wt_), m_start (
TimeVal
::gettimeofday ())
55
{
56
}
57
58
inline
59
TimerCountdown::
60
~TimerCountdown
()
61
{
62
if
(
m_maxWaitTime
== NULL)
63
return
;
64
65
TimeVal
elapsed (
TimeVal::gettimeofday
());
66
elapsed -=
m_start
;
67
68
if
( *
m_maxWaitTime
> elapsed )
69
*
m_maxWaitTime
-= elapsed;
70
else
71
*
m_maxWaitTime
=
TimeVal::zeroTime
();
72
}
73
74
}
// end namespace ASSA
75
76
#endif
/* TIMER_COUNTDOWN_H */
TimeVal.h
ASSA::TimeVal
Definition:
TimeVal.h:30
ASSA::TimerCountdown
Definition:
TimerCountdown.h:28
ASSA::TimeVal::gettimeofday
static TimeVal gettimeofday()
Shields off underlying OS differences in getting current time.
Definition:
TimeVal.cpp:44
ASSA::TimerCountdown::~TimerCountdown
~TimerCountdown()
Destructor.
Definition:
TimerCountdown.h:60
ASSA::TimerCountdown::TimerCountdown
TimerCountdown(TimeVal *wait_time_)
Constructor.
Definition:
TimerCountdown.h:53
ASSA::TimeVal::zeroTime
static TimeVal zeroTime()
Static that returns zero timeval: {0,0}.
Definition:
TimeVal.h:157
ASSA::TimerCountdown::m_start
TimeVal m_start
Time when countdown started.
Definition:
TimerCountdown.h:44
ASSA
Definition:
Acceptor.h:40
ASSA::TimerCountdown::m_maxWaitTime
TimeVal * m_maxWaitTime
Maximum time to wait.
Definition:
TimerCountdown.h:41
Generated by
1.8.17