blocxx
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BLOCXX_NAMESPACE::TimeoutTimer Class Reference

A TimeoutTimer is used by an algorithm to determine when a timeout has expired. More...

#include <TimeoutTimer.hpp>

Public Member Functions

 TimeoutTimer (const Timeout &x)
 
virtual ~TimeoutTimer ()
 
void start ()
 Meant to be called by timeout functions which loop. More...
 
void resetOnLoop ()
 Meant to be called by timeout functions which loop, and that want to reset the interval. More...
 
void loop ()
 Meant to be called by timeout functions which loop, but don't want to reset the interval. More...
 
bool expired () const
 Indicates whether the last loop time has exceeded the timeout. More...
 
bool infinite () const
 Indicates whether the timeout will never expire. More...
 
Timeout asTimeout () const
 
Timeout asRelativeTimeout () const
 
Timeout asRelativeTimeout (double maxSeconds) const
 
Timeout asAbsoluteTimeout () const
 Converts the timer to an absolute timeout. More...
 
int asIntMs () const
 
int asIntMs (double maxSeconds) const
 

Private Member Functions

double calcSeconds () const
 
double calcSeconds (double maxSeconds) const
 
virtual DateTime getCurrentTime () const
 

Private Attributes

Timeout m_timeout
 
DateTime m_start
 
DateTime m_loopTime
 

Detailed Description

A TimeoutTimer is used by an algorithm to determine when a timeout has expired.

It is used like this:

TimeoutTimer timer(theTimeout); while (... && !timer.expired()) { // wait for something to happen, maybe calling select() or something else. struct timeval tv; select(... , timer.asTimeval(tv));

... // processing

if (something happened that might reset the interval) timer.resetOnLoop(); else timer.loop(); }

Definition at line 105 of file TimeoutTimer.hpp.

Constructor & Destructor Documentation

◆ TimeoutTimer()

BLOCXX_NAMESPACE::TimeoutTimer::TimeoutTimer ( const Timeout x)

Definition at line 78 of file TimeoutTimer.cpp.

◆ ~TimeoutTimer()

BLOCXX_NAMESPACE::TimeoutTimer::~TimeoutTimer ( )
virtual

Definition at line 85 of file TimeoutTimer.cpp.

Member Function Documentation

◆ asAbsoluteTimeout()

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asAbsoluteTimeout ( ) const

Converts the timer to an absolute timeout.

If the timer is infinite, the return will be an infinite relative timeout

Definition at line 283 of file TimeoutTimer.cpp.

References calcSeconds(), and infinite().

Referenced by BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::acquireWriteLock(), and BLOCXX_NAMESPACE::GenericRWLockImpl< IdT, CompareT >::GenericRWLockImpl().

◆ asIntMs() [1/2]

int BLOCXX_NAMESPACE::TimeoutTimer::asIntMs ( ) const

◆ asIntMs() [2/2]

int BLOCXX_NAMESPACE::TimeoutTimer::asIntMs ( double  maxSeconds) const

Definition at line 343 of file TimeoutTimer.cpp.

◆ asRelativeTimeout() [1/2]

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asRelativeTimeout ( ) const

Definition at line 271 of file TimeoutTimer.cpp.

Referenced by BLOCXX_NAMESPACE::Exec::processInputOutput().

◆ asRelativeTimeout() [2/2]

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asRelativeTimeout ( double  maxSeconds) const

Definition at line 277 of file TimeoutTimer.cpp.

◆ asTimeout()

Timeout BLOCXX_NAMESPACE::TimeoutTimer::asTimeout ( ) const

Definition at line 237 of file TimeoutTimer.cpp.

◆ calcSeconds() [1/2]

double BLOCXX_NAMESPACE::TimeoutTimer::calcSeconds ( ) const
private

Definition at line 243 of file TimeoutTimer.cpp.

Referenced by asAbsoluteTimeout().

◆ calcSeconds() [2/2]

double BLOCXX_NAMESPACE::TimeoutTimer::calcSeconds ( double  maxSeconds) const
private

Definition at line 263 of file TimeoutTimer.cpp.

◆ expired()

bool BLOCXX_NAMESPACE::TimeoutTimer::expired ( ) const

Indicates whether the last loop time has exceeded the timeout.

The current time is not used, but the time when resetOnLoop() or loop() was called.

Definition at line 143 of file TimeoutTimer.cpp.

Referenced by BLOCXX_NAMESPACE::Exec::processInputOutput().

◆ getCurrentTime()

DateTime BLOCXX_NAMESPACE::TimeoutTimer::getCurrentTime ( ) const
privatevirtual

Definition at line 397 of file TimeoutTimer.cpp.

◆ infinite()

bool BLOCXX_NAMESPACE::TimeoutTimer::infinite ( ) const

Indicates whether the timeout will never expire.

Definition at line 163 of file TimeoutTimer.cpp.

Referenced by asAbsoluteTimeout().

◆ loop()

void BLOCXX_NAMESPACE::TimeoutTimer::loop ( )

Meant to be called by timeout functions which loop, but don't want to reset the interval.

It should be called each time through the loop. Either resetOnLoop() or loop() should be called each time through the loop, but not both.

Definition at line 106 of file TimeoutTimer.cpp.

Referenced by BLOCXX_NAMESPACE::Exec::processInputOutput().

◆ resetOnLoop()

void BLOCXX_NAMESPACE::TimeoutTimer::resetOnLoop ( )

Meant to be called by timeout functions which loop, and that want to reset the interval.

It should be called each time through the loop. For a relative with reset timeout it will reset the interval. Either resetOnLoop() or loop() should be called each time through the loop, but not both.

Definition at line 96 of file TimeoutTimer.cpp.

Referenced by BLOCXX_NAMESPACE::Exec::processInputOutput().

◆ start()

void BLOCXX_NAMESPACE::TimeoutTimer::start ( )

Meant to be called by timeout functions which loop.

Normally, it should be called once, at the beginning of the function. The time this is called marks the beginning of a relative interval. For an absolute timeout, it does nothing. It is not necessary to call this function, only if the time the constructor ran isn't desireable to be used as the start time.

Definition at line 90 of file TimeoutTimer.cpp.

Member Data Documentation

◆ m_loopTime

DateTime BLOCXX_NAMESPACE::TimeoutTimer::m_loopTime
private

Definition at line 214 of file TimeoutTimer.hpp.

Referenced by asIntMs().

◆ m_start

DateTime BLOCXX_NAMESPACE::TimeoutTimer::m_start
private

Definition at line 213 of file TimeoutTimer.hpp.

◆ m_timeout

Timeout BLOCXX_NAMESPACE::TimeoutTimer::m_timeout
private

Definition at line 212 of file TimeoutTimer.hpp.

Referenced by asIntMs().


The documentation for this class was generated from the following files: