libassa  3.5.1
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 
29 {
30 public:
33  TimerCountdown (TimeVal* wait_time_);
34 
37  ~TimerCountdown ();
38 
39 private:
42 
45 };
46 
47 //------------------------------------------------------------------------------
48 // inlines
49 //------------------------------------------------------------------------------
50 
51 inline
54  : m_maxWaitTime (wt_), m_start (TimeVal::gettimeofday ())
55 {
56 }
57 
58 inline
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
72 }
73 
74 } // end namespace ASSA
75 
76 #endif /* TIMER_COUNTDOWN_H */
Class TimeVal is a wrapper around UNIX timeval structure.
static TimeVal zeroTime()
Static that returns zero timeval: {0,0}.
Definition: TimeVal.h:157
static TimeVal gettimeofday()
Shields off underlying OS differences in getting current time.
Definition: TimeVal.cpp:44
TimeVal m_start
Time when countdown started.
TimerCountdown(TimeVal *wait_time_)
Constructor.
~TimerCountdown()
Destructor.
TimeVal * m_maxWaitTime
Maximum time to wait.
Definition: Acceptor.h:40