acl/lib_acl/include/event/acl_timer.h

116 lines
3.0 KiB
C
Raw Normal View History

#ifndef ACL_TIMER_INCLUDE_H
2014-11-19 00:25:21 +08:00
#define ACL_TIMER_INCLUDE_H
2017-06-02 14:47:24 +08:00
#include "../stdlib/acl_define.h"
2014-11-19 00:25:21 +08:00
#include <time.h>
2017-06-02 14:47:24 +08:00
#include "../stdlib/acl_iterator.h"
#include "../stdlib/acl_ring.h"
2014-11-19 00:25:21 +08:00
#ifdef __cplusplus
extern "C" {
#endif
/**
* <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
typedef struct ACL_TIMER_INFO {
/* public */
void *obj; /**< <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>ָ<EFBFBD><D6B8> */
acl_int64 when; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><>) */
2014-11-19 00:25:21 +08:00
/* private */
ACL_RING entry; /**< <20>ڲ<EFBFBD><DAB2>õĶ<C3B5>ʱ<EFBFBD><CAB1> */
2014-11-19 00:25:21 +08:00
} ACL_TIMER_INFO;
/* <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ */
2014-11-19 00:25:21 +08:00
typedef struct ACL_TIMER ACL_TIMER;
struct ACL_TIMER {
acl_int64 (*request)(ACL_TIMER *timer, void *obj, acl_int64 delay);
acl_int64 (*cancel)(ACL_TIMER *timer, void *obj);
void* (*popup)(ACL_TIMER* timer);
ACL_RING timer_header;
acl_int64 present;
acl_int64 time_left;
/* for acl_iterator */
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD> */
2014-11-19 00:25:21 +08:00
const void *(*iter_head)(ACL_ITER*, struct ACL_TIMER*);
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
2014-11-19 00:25:21 +08:00
const void *(*iter_next)(ACL_ITER*, struct ACL_TIMER*);
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD> */
2014-11-19 00:25:21 +08:00
const void *(*iter_tail)(ACL_ITER*, struct ACL_TIMER*);
/* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
2014-11-19 00:25:21 +08:00
const void *(*iter_prev)(ACL_ITER*, struct ACL_TIMER*);
/* <20><><EFBFBD><EFBFBD><EFBFBD>뵱ǰ<EBB5B1><C7B0><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ACL_TIMER_INFO <20><><EFBFBD><EFBFBD> */
2014-11-19 00:25:21 +08:00
const ACL_TIMER_INFO *(*iter_info)(ACL_ITER*, struct ACL_TIMER*);
};
/**
* <EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param timer {ACL_TIMER*}<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param obj {void*}<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param delay {acl_int64}<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(΢<EFBFBD>)
* @return {acl_int64} <EFBFBD>µĶ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(΢<EFBFBD>)
2014-11-19 00:25:21 +08:00
*/
ACL_API acl_int64 acl_timer_request(ACL_TIMER* timer, void *obj, acl_int64 delay);
/**
* ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param timer {ACL_TIMER*}<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param obj {void*}<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {acl_int64}<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>񱻴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(΢<EFBFBD>)
2014-11-19 00:25:21 +08:00
*/
ACL_API acl_int64 acl_timer_cancel(ACL_TIMER* timer, void *obj);
/**
* <EFBFBD>Ӷ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ȡ<EFBFBD><EFBFBD>ʱ<EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param timer {ACL_TIMER*}<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {void*}<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
ACL_API void *acl_timer_popup(ACL_TIMER* timer);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>񱻴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param timer {ACL_TIMER*}<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {acl_int64} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>λΪ΢<EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
ACL_API acl_int64 acl_timer_left(ACL_TIMER* timer);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param timer {ACL_TIMER*}<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param action {void (*)(ACL_TIMER_INFO*, void*)} <EFBFBD>û<EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param arg {void*} action <EFBFBD>еĵڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
ACL_API void acl_timer_walk(ACL_TIMER *timer, void (*action)(ACL_TIMER_INFO *, void *), void *arg);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
* @return {ACL_TIMER*}
*/
ACL_API ACL_TIMER *acl_timer_new(void);
/**
* <EFBFBD>ͷŶ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
* @param timer {ACL_TIMER*}
* @param free_fn {void (*)(void*)} <EFBFBD>ͷŶ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD>ͷź<EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
ACL_API void acl_timer_free(ACL_TIMER* timer, void (*free_fn)(void*));
/**
* <EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
* @param timer {ACL_TIMER*}
* @return {int} >= 0
*/
ACL_API int acl_timer_size(ACL_TIMER *timer);
#ifdef __cplusplus
}
#endif
#endif