/*
 * voipTimer.h
 *
 * Copyright (C) 2005, Ranch Networks, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 *
 * Author : Srivatsa Chivukula <srivatsa@ranchnetworks.com>
 *
 */

#ifndef _VOIP_TIMER_H
#define _VOIP_TIMER_H

#ifdef POSIX
#include <pthread.h>
#endif

#include "voipTask.h"

#define TIMER_TASK_NAME 	"time"
#define MIN_CLOCK_TIC		100

typedef enum
{
    TIMER_NIL_REASON=0,
    TIMER_EXPIRED,
    TIMER_CANCELLED
} timerCleanupReason_t;

typedef unsigned long timer_id_t;
typedef int (*TIMER_HANDLER)(void* context_p, unsigned int size);
typedef int (*TIMER_CLEANUP)( timerCleanupReason_t, void*, unsigned long);

typedef struct _sysTimer_t
{  
    unsigned int   initialInterval;
    unsigned int   repeatInterval;
    void          *context;
    unsigned int   contextSize;
    TIMER_HANDLER  handler;   
    TIMER_CLEANUP  cleanup;
} sysTimer_t;

#ifdef __cplusplus
extern "C" {
#endif

extern int sysInstallTimerManager( int unit, timer_task_context_t *tp );
extern int sysUninstallTimerManager( timer_task_context_t *tp );

extern timer_id_t sysSetTimer( timer_task_context_t *tp, sysTimer_t *t);
extern int voipGetTimer( timer_id_t, unsigned long *owner_p, sysTimer_t *t );

/* This does not free the context. If the timer has already fired then
 * it will return SYS_ETIMEOUT to indicate failure. The user has to try
 * canellation again.
 */
extern int sysCancelTimer( timer_task_context_t *tp, timer_id_t handle );

extern int sysGetRemainingTime( timer_task_context_t *tp, timer_id_t handle, int unit );

#ifdef __cplusplus
}
#endif

#endif // _VOIP_TIMER_H
