summaryrefslogtreecommitdiff
path: root/include/MESA/sapp_timer.h
blob: 0842ef02c18ebec8faaa17df4a2b10e106061f97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef _SAPP_TIMER_H_
#define _SAPP_TIMER_H_ 1

#ifdef __cplusplus
extern "C" {
#endif

#include "sapp_limits.h"

#if 0


typedef enum{
	STO_EFFECTIVE_SCOPE, 	/* value type is int, refer to STO_EFFECTIVE_SCOPE_xxx */
	STO_PKT_PROCESS_THREAD_NUM, /* value type is int */
}sapp_timer_opt;

#endif

enum st_return_errno{
	ST_RET_SUCC = 0,
	ST_RET_ERROR = -1,
	ST_RET_CANT_OP_PLATFORM_TIMER = -2,
	ST_RET_INVALID_ARGS = -3, 
	ST_RET_NEED_MANDATORY_OPT = -4,
	ST_RET_DIFF_THREAD_CONTEXT = -5, 
};


typedef enum{
	STEO_EFFECTIVE_THREAD_ID, /* value type is int */
	STEO_TIMEOUT_VAL,		/* value type is struct timeval, refer to <linux/time.h> */
	STEO_CALLBACK_FUN,		/* value type is sapp_timer_cbfun_t*   */
	STEO_CALLBACK_FUN_ARG, 	/* value type is void*   */
	STEO_CALLBACK_COUNT,	/* value type is int */
}sapp_event_opt;

typedef void * sapp_timer_handle;
typedef void * sapp_timer_event;

/* 
    NOTE: 
    This timer is active in sapp packet process threads context, 
    similar to the entry function of plugins, is multithread.
*/
sapp_timer_handle sapp_get_platform_timer(int tid);

/* 
    NOTE: 
    This timer is created by sapp, 
    plugins only add timer event in sapp initialization phase,
    in addition, the accuracy maybe decline if too many timer event add to one timer.
    plugins also call sapp_standalone_timer_new() to create a private timer for it own use.
*/
sapp_timer_handle sapp_get_platform_standalone_timer(void);


/* NOTE: this timer is active in a standalone thread context, is single thread. */
sapp_timer_handle sapp_standalone_timer_new(void);


/*
	NOTE:
		In sapp platform packet process thread context, the pkt_process_thread_id is in region: [0, max_thread_num-1];
		In stand_alone thread context, the pkt_process_thread_id is -1;
*/
typedef void sapp_timer_cbfun_t(sapp_timer_handle h, sapp_timer_event ev, int pkt_process_thread_id, void *user_arg);

/*
	NOTE:
		If you want use sapp platform timer, must call sapp_get_platform_timer(), not sapp_timer_new().
		If you want a independent private timer, must call sapp_timer_new().
*/
sapp_timer_event sapp_timer_event_new(sapp_timer_handle h);

//int sapp_timer_set_opt(sapp_timer_handle h, sapp_timer_opt t_opt, void *t_value, int t_value_len);
int sapp_event_set_opt(sapp_timer_event ev, sapp_event_opt ev_opt, void *ev_value, int ev_value_len);


int sapp_timer_add(sapp_timer_handle h, sapp_timer_event ev);
int sapp_timer_del(sapp_timer_handle h, sapp_timer_event ev);
int sapp_timer_start(sapp_timer_handle h);
int sapp_timer_destroy(sapp_timer_handle h);

#ifdef __cplusplus
}
#endif


#endif