#ifndef __MY_TIMER_H__
#define __MY_TIMER_H__

#include <syslog.h>
#include "ipc_session.h"
#include "mqtt_session.h"
#include "lnxall_list.h"
#include "dy_utils/dy_ds.h"
#include "dy_utils/dy_common.h"
#include "dy_utils/kv_array.h"
#include "dy_utils/dy_ipc.h"
#include "dy_utils/dy_can.h"
#include "dy_utils/modbus_utils.h"
#include "dy_utils/period_service.h"
#include "modbus/modbus.h"
#include "dy_utils/bitmap.h"

#include "my_public.h"

#define TIMER_MAX_NUM 1000
#define TIMER_MAX_PARA_LEN 256
#define SECOND_CONT 1

typedef int (*timeFunc)(void *var, void *param, USHORT len);

typedef enum timer_state_s
{
    E_UNUSE,
    E_USE
} TIMER_STATE_E;

typedef enum timer_type_s
{
    E_TIMER_ONCE,
    E_TIMER_LOOP
} TIMER_TYPE_E;

typedef struct timer_info_s
{
    LIST_STRUCT list;
    CHAR param[TIMER_MAX_PARA_LEN];
    USHORT paralen;
    time_t tm;
    BYTE startflag;
    BYTE use;
    BYTE timerType;
    USHORT delay;
    USHORT index;
    timeFunc func;
} TIMER_INFO_T;

typedef struct timer_mng_list_s{
    LIST_STRUCT  useList;
    LIST_STRUCT  unuselist;
    pthread_rwlock_t timer_lock;
    void *var;
}TIMER_MNG_LIST_T;

void mytimer_loop();
void mytimer_init(void *var);
int mytimer_create(timeFunc func, void *param, USHORT len, USHORT timedelay, TIMER_TYPE_E type);
int mytimer_start( USHORT timerId);
int mytimer_stop( USHORT timerId);
int mytimer_delete(USHORT timerId);
int mytimer_update(USHORT timerId, USHORT timedelay);

#endif