LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Private Member Functions
LogCabin::Event::Timer Class Reference

A Timer is called by the Event::Loop when time has elapsed. More...

#include <Timer.h>

Inheritance diagram for LogCabin::Event::Timer:
LogCabin::Event::File LogCabin::Event::Loop::NullTimer LogCabin::RPC::anonymous_namespace{ClientSession.cc}::TimerNotifier LogCabin::RPC::ClientSession::Timer

List of all members.

Classes

class  Monitor
 Registers a Timer handler to be monitored by the Event::Loop. More...

Public Member Functions

 Timer ()
 Construct a timer but do not schedule it to trigger.
virtual ~Timer ()
 Destructor.
virtual void handleTimerEvent ()=0
 This method is overridden by a subclass and invoked when the timer expires.
void schedule (uint64_t nanoseconds)
 Start the timer.
void scheduleAbsolute (Core::Time::SteadyClock::time_point timeout)
 Start the timer for an absolute point in time.
void deschedule ()
 Stop the timer from calling handleTimerEvent().

Private Member Functions

bool isScheduled () const
 Returns true if the timer has been scheduled and has not yet fired.
void handleFileEvent (uint32_t events)
 Generic event handler for files.
 Timer (const Timer &)
Timeroperator= (const Timer &)

Detailed Description

A Timer is called by the Event::Loop when time has elapsed.

The client should inherit from this and implement the trigger method for when the timer expires.

Timers can be added and scheduled from any thread, but they will always fire on the thread running the Event::Loop.

Definition at line 37 of file Timer.h.


Constructor & Destructor Documentation

Construct a timer but do not schedule it to trigger.

After this is constructed, you'll want to create an Event::Timer::Monitor for it and also schedule() it, in either order.

Definition at line 57 of file Timer.cc.

Destructor.

Definition at line 62 of file Timer.cc.

LogCabin::Event::Timer::Timer ( const Timer ) [private]

Member Function Documentation

virtual void LogCabin::Event::Timer::handleTimerEvent ( ) [pure virtual]

This method is overridden by a subclass and invoked when the timer expires.

This method will be invoked by the main event loop on whatever thread is running the Event::Loop.

Implemented in LogCabin::RPC::ClientSession::Timer, LogCabin::Event::Loop::NullTimer, and LogCabin::RPC::anonymous_namespace{ClientSession.cc}::TimerNotifier.

void LogCabin::Event::Timer::schedule ( uint64_t  nanoseconds)

Start the timer.

Parameters:
nanosecondsThe timer will trigger once this number of nanoseconds have elapsed. If the timer was already scheduled, the old time is forgotten.

Definition at line 67 of file Timer.cc.

Start the timer for an absolute point in time.

If the timeout is in the past, the timer will trigger immediately once the event loop runs.

Parameters:
timeoutThe timer will trigger once this timeout has past. If the timer was already scheduled, the old time is forgotten.

Definition at line 88 of file Timer.cc.

Stop the timer from calling handleTimerEvent().

This will cancel the current timer, if any, so that handleTimerEvent() is not called until the next time it is scheduled.

This method behaves in a friendly way when called concurrently with the timer firing:

Definition at line 115 of file Timer.cc.

bool LogCabin::Event::Timer::isScheduled ( ) const [private]

Returns true if the timer has been scheduled and has not yet fired.

Warning:
This is prone to races; it's primarily useful for unit tests. It also improperly returns false after scheduleAbsolute() is called with a time that has expired. It's marked as private so it can't be accessed from normal (non-test) code. TODO(ongaro): remove entirely or add additional state to this class to make this work correctly?
Returns:
True if the timer has been scheduled and will eventually call handleTimerEvent(). False if the timer is currently running handleTimerEvent() or if it is not scheduled to call handleTimerEvent() in the future.

Definition at line 125 of file Timer.cc.

void LogCabin::Event::Timer::handleFileEvent ( uint32_t  events) [private, virtual]

Generic event handler for files.

Calls handleTimerEvent().

Implements LogCabin::Event::File.

Definition at line 138 of file Timer.cc.

Timer& LogCabin::Event::Timer::operator= ( const Timer ) [private]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines