The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Timer Class Reference

Timer class for one-second resolution timers Timer provides a facility which allows module developers to create one-shot timers. More...

#include <timer.h>

Inheritance diagram for Timer:

Inheritance graph
[legend]
Collaboration diagram for Timer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Timer (long secs_from_now, time_t now, bool repeating=false)
 Default constructor, initializes the triggering time.
virtual ~Timer ()
 Default destructor, does nothing.
virtual time_t GetTimer ()
 Retrieve the current triggering time.
virtual void SetTimer (time_t t)
 Sets the trigger timeout to a new value.
virtual void Tick (time_t TIME)=0
 Called when the timer ticks.
bool GetRepeat ()
 Returns true if this timer is set to repeat.
long GetSecs ()
 Returns the interval (number of seconds between ticks) of this timer object.
void CancelRepeat ()
 Cancels the repeat state of a repeating timer.

Private Attributes

time_t trigger
 The triggering time.
long secs
 Number of seconds between triggers.
bool repeat
 True if this is a repeating timer.

Detailed Description

Timer class for one-second resolution timers Timer provides a facility which allows module developers to create one-shot timers.

The timer can be made to trigger at any time up to a one-second resolution. To use Timer, inherit a class from Timer, then insert your inherited class into the queue using Server::AddTimer(). The Tick() method of your object (which you should override) will be called at the given time.

Definition at line 29 of file timer.h.


Constructor & Destructor Documentation

Timer::Timer long  secs_from_now,
time_t  now,
bool  repeating = false
[inline]
 

Default constructor, initializes the triggering time.

Parameters:
secs_from_now The number of seconds from now to trigger the timer
now The time now
repeating Repeat this timer every secs_from_now seconds if set to true

Definition at line 47 of file timer.h.

virtual Timer::~Timer  )  [inline, virtual]
 

Default destructor, does nothing.

Definition at line 56 of file timer.h.


Member Function Documentation

void Timer::CancelRepeat  )  [inline]
 

Cancels the repeat state of a repeating timer.

If you call this method, then the next time your timer ticks, it will be removed immediately after. You should use this method call to remove a recurring timer if you wish to do so within the timer's Tick event, as calling TimerManager::DelTimer() from within the Timer::Tick() method is dangerous and may cause a segmentation fault. Calling CancelRepeat() is safe in this case.

Definition at line 103 of file timer.h.

bool Timer::GetRepeat  )  [inline]
 

Returns true if this timer is set to repeat.

Definition at line 80 of file timer.h.

Referenced by TimerManager::TickTimers().

long Timer::GetSecs  )  [inline]
 

Returns the interval (number of seconds between ticks) of this timer object.

Definition at line 88 of file timer.h.

Referenced by TimerManager::TickTimers().

virtual time_t Timer::GetTimer  )  [inline, virtual]
 

Retrieve the current triggering time.

Definition at line 60 of file timer.h.

Referenced by TimerManager::TimerComparison().

virtual void Timer::SetTimer time_t  t  )  [inline, virtual]
 

Sets the trigger timeout to a new value.

Definition at line 67 of file timer.h.

Referenced by TimerManager::TickTimers().

virtual void Timer::Tick time_t  TIME  )  [pure virtual]
 

Called when the timer ticks.

You should override this method with some useful code to handle the tick event.

Implemented in CacheTimer, RequestTimeout, ReconnectTimer, CacheRefreshTimer, HandshakeTimer, WhoWasMaintainTimer, and SocketTimeout.

Referenced by TimerManager::TickTimers().


Member Data Documentation

bool Timer::repeat [private]
 

True if this is a repeating timer.

Definition at line 40 of file timer.h.

long Timer::secs [private]
 

Number of seconds between triggers.

Definition at line 37 of file timer.h.

time_t Timer::trigger [private]
 

The triggering time.

Definition at line 34 of file timer.h.


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