class Timer

Very simple timer class that allows to create one instance of the timer at a time that can handles once-only tasks in the future or reoccuring (== periodic) tasks

Public Classes

enum timer_par
enum for class specific constants

Public Methods

long add_action( ActionType pAction, long argc = 0, char **argv = NULL )
adds a new function to the list of functions to be executed by the timer
void dump()
prints info to cout about the timer
void execute_actions()
member function that executes the actions
double get_time_interval()
returns the total time interval of the timer (from start to fire)
long how_many_times()
returns how many times the timer has been called
double how_much_time_left()
returns the number of seconds until the timer fires
BOOL is_active()
returns true if the timer is active (started)
BOOL is_periodic()
returns true if the timer is periodic
BOOL is_valid()
returns true if the timer is ok
long remove_action( ActionType pAction )
removes a formerly added action
void set_periodic(BOOL mPeriodic)
allows to toggle back and forth between periodic and once only timer
void start()
starts the timer
void stop()
stops the timer
static void TheAction(int signum)
TheAction to be executed
Timer( long iTsec = TSEC_UPDATE_DEF, long iTusec_update = TUSEC_UPDATE_DEF, BOOL periodic = false)
Constructor - note the default values
~Timer()
dtor

Public

enum timer_par
enum for class specific constants

Private Fields

ActionType actions[MAX_ACTIONS]
pointer to functions (== actions) to be executed
long argc[MAX_ACTIONS]
number of arguments for calling action
char** argv[MAX_ACTIONS]
arguments as char* for actions
BOOL bActive
true if the timer is active
BOOL bPeriodic
true if the timer is periodic
BOOL bValid
flag - true if the timer is ok
long iSec_action
Number of seconds until it fires (from start)
long iUsec_action
Number of microseconds until it fires (from start)
static Timer* Myself
there is only one instance of the system clock !
long nActions
number of actions
long nTimes_fired
How many times the timer has fired (==1 for non-periodic timers)

Documentation

Very simple timer class that allows to create one instance of the timer at a time that can handles once-only tasks in the future or reoccuring (== periodic) tasks.

If a second instance is created the old one is invalidated. If the timer is declared periodic, then it will reoccur until it is turned off. Every time the timer is fired a series of functions are executed. The list of functions can be modified at any given time, i.e. more can be added or existing ones removed.

Protection is in place that the (periodic) timer cannot be called while it is executing its actions.

Comments:

MODIFICATIONS :

enum timer_par
enum for class specific constants

Timer( long iTsec = TSEC_UPDATE_DEF, long iTusec_update = TUSEC_UPDATE_DEF, BOOL periodic = false)
Constructor - note the default values

~Timer()
dtor

static void TheAction(int signum)
TheAction to be executed. This is a static function, which in turns call all the functions that have been declared to be performed at the periodic interval. The reason that this is a static function is that it is called from a signal.
The ActionType is a typedef to typedef void (*ActionType)(int, char **)

void execute_actions()
member function that executes the actions

void start()
starts the timer

void stop()
stops the timer

long add_action( ActionType pAction, long argc = 0, char **argv = NULL )
adds a new function to the list of functions to be executed by the timer. The Function pAction is invoked with the arguments argc and char** argv

long remove_action( ActionType pAction )
removes a formerly added action

void dump()
prints info to cout about the timer

long how_many_times()
returns how many times the timer has been called

double get_time_interval()
returns the total time interval of the timer (from start to fire)

double how_much_time_left()
returns the number of seconds until the timer fires

BOOL is_periodic()
returns true if the timer is periodic

void set_periodic(BOOL mPeriodic)
allows to toggle back and forth between periodic and once only timer

BOOL is_active()
returns true if the timer is active (started)

BOOL is_valid()
returns true if the timer is ok. Note: we have only one ITIMER_REAL. Therefore we disable the existing time (and set bValid to false) when we create a new timer

static Timer* Myself
there is only one instance of the system clock !

BOOL bValid
flag - true if the timer is ok

long iSec_action
Number of seconds until it fires (from start)

long iUsec_action
Number of microseconds until it fires (from start)

long nTimes_fired
How many times the timer has fired (==1 for non-periodic timers)

BOOL bPeriodic
true if the timer is periodic

BOOL bActive
true if the timer is active

long nActions
number of actions

ActionType actions[MAX_ACTIONS]
pointer to functions (== actions) to be executed

long argc[MAX_ACTIONS]
number of arguments for calling action

char** argv[MAX_ACTIONS]
arguments as char* for actions


This class has no child classes.
Author:
C.Witzig
Date: Jan 28, 98
Version:
Last update Jan 28, 98

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de