X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Futil%2Ftimer.h;h=250e7e0bd33d16894dad86d347e3e8caff8c173d;hb=e7c43073246afe07cddf67d40d545f2bebcf62a1;hp=e938b2f2a89b196a156ed34596e75b96c9d0e103;hpb=b0088891ec08706a92184aff508c2baefe488b54;p=chaz%2Ftint2 diff --git a/src/util/timer.h b/src/util/timer.h index e938b2f..250e7e0 100644 --- a/src/util/timer.h +++ b/src/util/timer.h @@ -21,31 +21,43 @@ #include -extern GSList* timer_list; +extern GSList* timeout_list; +extern struct timeval next_timeout; -struct timer { - int id; - void (*_callback)(); -}; +typedef struct _timeout timeout; // timer functions -/** installs a timer with the first timeout 'value_sec' and then a periodic timeout with interval_sec - * '_callback' is the callback function when the timer reaches the timeout. - * If 'value_sec' == 0 then the timer is disabled (but not uninstalled) - * If 'interval_sec' == 0 the timer is a single shot timer, ie. no periodic timeout occur - * returns the 'id' of the timer, which is needed for uninstalling the timer **/ -int install_timer(int value_sec, int value_nsec, int interval_sec, int interval_nsec, void (*_callback)()); - -/** resets a timer to the new values. If 'id' does not exist nothing happens. - * If value_sec == 0 the timer is stopped **/ -void reset_timer(int id, int value_sec, int value_nsec, int interval_sec, int interval_nsec); - -/** uninstalls a timer with the given 'id'. If no timer is installed with this id nothing happens **/ -void uninstall_timer(int id); - -/** uninstalls all timer. Calls uninstall_timer for all available id's **/ -void uninstall_all_timer(); +/** + * Single shot timer (i.e. timer with interval_msec == 0) are deleted automatically as soon as they expire + * i.e. you do not need to stop them, however it is safe to call stop_timeout for these timers. + * Periodic timeouts are aligned to each other whenever possible, i.e. one interval_msec is an + * integral multiple of the other. +**/ + +/** default global data **/ +void default_timeout(); + +/** freed memory : stops all timeouts **/ +void cleanup_timeout(); + +/** installs a timeout with the first timeout of 'value_msec' and then a periodic timeout with + * 'interval_msec'. '_callback' is the callback function when the timer reaches the timeout. + * returns a pointer to the timeout, which is needed for stopping it again +**/ +timeout* add_timeout(int value_msec, int interval_msec, void (*_callback)(void*), void* arg); + +/** changes timeout 't'. If timeout 't' does not exist, nothing happens **/ +void change_timeout(timeout* t, int value_msec, int interval_msec, void (*_callback)(void*), void* arg); + +/** stops the timeout 't' **/ +void stop_timeout(timeout* t); + +/** update_next_timeout updates next_timeout to the value, when the next installed timeout will expire **/ +void update_next_timeout(); + +/** Callback of all expired timeouts **/ +void callback_timeout_expired(); #endif // TIMER_H