/* 
 * Timer Interface
 *
 * timer.h
 *
 * The public interface to timers, used by applications.
 *
 */

#ifndef _TIMER_H_
#define _TIMER_H_


/* timers when expired run a routine of this type */
typedef void *(*timer_handler_t)(void *context);


typedef struct {
	int id;
	timer_handler_t handler;
	void *context;
} timer_t;


/*
 * timer_set: sets a new timer
 * - timeout: number of seconds until the timer expires
 * - handler: function which will be called when timer expires
 * - context: context passed as handler argument
 *   returns: the timer id
 */
int timer_set(int timeout, timer_handler_t handler, void *context);


/*
 * timer_cancel: cancel a timer
 * - id: the the timer id
 *   returns: 0 if timer canceled, -1 if not
 */
int timer_cancel(int id);


/*
 * timer_next: gives the seconds until the next timer expires
 *   returns: number of seconds until the next timer expires, -1 if none
 */
int timer_next();


/*
 * timer_execute_next: executes the timer on the head of the queue
 */
void timer_execute_next();


#endif
