Class Timer

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class Timer

Summary
Public Properties
Public Methods
typedef void(TimerCB)
Timer(useAlarmSignals, serviceDuringSignal)
bool setupAt(triggerTime, cbfn, data, triggerLabel)
bool setupPeriodic(seconds, cbfn, data, triggerLabel)
bool cancel(triggerLabel)
int secondsTillService(t, secondsTillEndOfTime) const
int secondsTillService(triggerLabel, t, secondsTillEndOfTime) const
int service(t)
HashArray getState() const
TimerEntry()
Private Properties

#include <Timer.h >

Summary

Class to manage multiple timers, whether one-shot or periodic.

Unlike the Unix timer, this class provides app-provided callback data when each timer trigters.

This class is useful when you have multiple timed activities that need to happen at various times. When the time comes, the callback function is called.

It's also useful for event-driven programming where execution hangs off a select() statement.

Note: Only use one instance of this class. It claims the alarm() signal. If you use multiple instances, only the last instance invoked will be handled.

Public Properties

string label

TimerCB cbfn

void* cbdata

time_t triggerTime

int reloadSeconds


Public Methods

typedef void(TimerCB)

*TimerCB TimerCB


Timer(useAlarmSignals, serviceDuringSignal)

bool useAlarmSignals

Default value: true

bool serviceDuringSignal

Default value: true


Use Unix signaling to handle timer triggers unless instantiated with false

bool setupAt(triggerTime, cbfn, data, triggerLabel)

time_t triggerTime

specific time when to call the callback function

TimerCB cbfn

callback function, e.g. void mycb(void * data)

void* data

callack data

const string& triggerLabel

label for managing this callback (app choice)


Setup a one-time timer event.

Return value: true upon success, false upon failure

bool setupPeriodic(seconds, cbfn, data, triggerLabel)

int seconds

number of seconds in the future to run the callback function

TimerCB cbfn

callback function, e.g. void mycb(void * data)

void* data

callack data

const string& triggerLabel

label for managing this callback (app choice)


Setup a time to trigger every so many seconds

Return value: true upon success, false upon failure

bool cancel(triggerLabel)

const string& triggerLabel

label for the timer to cancel


Cancel a timer that was setup

Return value: true upon success, false upon failure

int secondsTillService(t, secondsTillEndOfTime) const

time_t t

time to use to find next event

Default value: 0

int secondsTillEndOfTime

Default value: TimerEndOfTime


Countdown to next timer event (handy for select() call timeout)

If a time is provided, that is used as the current time

Return value: number of seconds till next event

int secondsTillService(triggerLabel, t, secondsTillEndOfTime) const

const string& triggerLabel

label for the timer to check

time_t t

time to use to find next event

Default value: 0

int secondsTillEndOfTime

Default value: TimerEndOfTime


Countdown in seconds until the provided trigger label.

Return value: number of seconds till next event

int service(t)

time_t t

time to use to find next event

Default value: 0


Process any current or past due timer triggers

If a time is provided, that is used as the current time

Return value: number of events processed

HashArray getState() const

Get the timer state of all configured timers - key: timer label; value: seconds till trigger

Return value: key/value pairs of timer labels and seconds until they fire

TimerEntry()

Private Properties

class TimerEntry label