/*
* timers-c.h      : Timer Management Include File
* authors         : John Heidemann
*
* Copyright (C) 2000-2001 by the Unversity of Southern California
* $Id: timers-c.h,v 1.1 2002/04/30 17:44:37 johnh Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
*/


#ifndef _TIMERS_C_H_
#define _TIMERS_C_H_

/*
 * To make a new timer,
 * pass a function pointer (cb) and optional context (p)
 * to Timers_AddTimer.
 *
 * When the timer expires cb will be called with the timer 
 * handle and context as arguments.
 *
 * If you need to pass parameters to your timer,
 * pass them through the context.
 * (Note that C++ is MUCH cleaner about this...
 * you can do it type-safely via subclassing.)
 *
 * The return value of your callback indicates what should happen
 * to the timer:
 *
 * return = 0   re-add timer again to queue with same timeout as last time
 *        > 0   re-add timer to queue with new timeout given by return value
 *        < 0   discard timer (do not re-add it to the queue)
 */
typedef int (*TimerCallback_t)(int hdl, void *p);

int Timers_AddTimer(int timeout, TimerCallback_t cb, void *p);
int Timers_RemoveTimer(int handle);

/*
 * Your main app needs an event loop where it calls
 * Timers_NextTimerTime to figure out when the next timer is,
 * and then calls Timers_ExecuteNextTimer when it
 * wants to run one.
 * See test-app-c.c for an example.
 */
void Timers_NextTimerTime(struct timeval *tv);
void Timers_ExecuteNextTimer();

#endif // _TIMERS_H_


