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
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:
- Use of sleep etc ...
This class uses the POSIX ITIMER_REAL.
Therefore make sure you don't use the timer for something else while you have the timer active, e.g. sleep function uses itimer!!!- invoking member functions
The this pointer is not defined in invoking member functions. Therefore if a public member function is to be invoked, you must pass it as an argument argv[i] into a static member function which in turn unpacks the pointer and invokes the member function- memory allocation model
If arguments are to be passed into the function, then add_action assumes ownership of the char **argv. Therefore the caller must use new to create them and NOT call delete.MODIFICATIONS :
Timer( long iTsec = TSEC_UPDATE_DEF, long iTusec_update = TUSEC_UPDATE_DEF, BOOL periodic = false)
~Timer()
static void TheAction(int signum)
The ActionType is a typedef to typedef void (*ActionType)(int, char **)
void execute_actions()
void start()
void stop()
long add_action( ActionType pAction, long argc = 0, char **argv = NULL )
long remove_action( ActionType pAction )
void dump()
long how_many_times()
double get_time_interval()
double how_much_time_left()
BOOL is_periodic()
void set_periodic(BOOL mPeriodic)
BOOL is_active()
BOOL is_valid()
static Timer* Myself
BOOL bValid
long iSec_action
long iUsec_action
long nTimes_fired
BOOL bPeriodic
BOOL bActive
long nActions
ActionType actions[MAX_ACTIONS]
long argc[MAX_ACTIONS]
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de