gandi_timer(3) - Linux man page

Name

GANDI's timer capability.

Synopsis

#include <gandi_core.h>

GANDIT_timer *GANDI_timer_attach(void *w);

void GANDI_timer_dettach(void *w);

bool GANDI_timer_driver();

Description

Without a timer most of GANDI's activity is to wait for a pressed key. Then control is given to the active widget. Afterwards the widget returns control, and the driver (see gandi_driver(3gandi)) waits for a pressed key again. The Timer changes this condition and allows the widget to recieve control while waiting for a pressed key (and only during this period, for GANDI does not use threads).

In order to realize this feature, every widget has the property timer (see gandi_gandiw(3gandi)). It may be NULL if the timer is not needed in the widget. To use, call GANDI_timer_attach to the widget and all the neccesary memory will be allocated.

timer is a pointer to a GANDIT_timer structure, whose defenition is:

typedef struct _GANDIT_timer {
        struct timeval *period;
        struct timeval *last;
        GANDIact_timer handler;
} GANDIT_timer;
For GANDIact_timer see gandi_acts(3gandi). For struct timeval see gettimeofday(2).

There is a period which defines a minimal pause between two closess calls of the function handler. The maximal pause depends on the machine and system loading, it is not limited. last is a system time, when the widget was last awaken. There exists routines to utilize these properties (see gandi_gandiw(3gandi)).

GANDIT_timer *GANDI_timer_attach(void *w);

Allocates memory to the widget's timer structure (see gandi_gandiw(3gandi)). Applies timerclear (see gettimeofday(2)) to period and last. handler is set to NULL.

Return value is a pointer to the structure just created. NULL signifies a fault.

void GANDI_timer_dettach(void *w);

Frees all memory, allocated for the widget's timer, which will be set to the NULL. Does nothing if the timer is NULL already. If the timer or timer->period or timer->last points to an unallocated memory, there will be an unpredictable application behavior. Therefore use these function either with caution or after GANDI_timer_attach only.

bool GANDI_timer_driver();

This function exists but there is no need to use it. GANDI_driver (see gandi_driver(3gandi)) calls it when neccesary.

Searches in the register (see gandi_register(3gandi)) for a widget which has one of:

> last less then the current system time or more then period;
> last greater then the current system time;
and runs the handler for it. Then it changes last to the time at which handler was called.

Return value is TRUE if at least one handler returned TRUE or one of the awaken widgets was killed by its handler.

Notes

struct timeval {
        long tv_sec;    //seconds
        long tv_usec;   //microseconds
};
tv_usec MUST be in the range [0..(1e6 - 1)]. The structure {0, 2e6} does not equal {2, 0} (the last is correct).

The timer capabilities are limited (from low) with one thousandth second. It is a strict sequence of the default wtimeout settings (see gandi_stndr(3gandi)). Unfortunately this time unit may be increased only.

See Also

gandi_acts(3gandi) gandi_core(3gandi) gandi_driver(3gandi) gandi_gandiw(3gandi) gandi_register(3gandi) gettimeofday(2)