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
91
92
93
94
95
96
97
98
99
100
101
|
#ifndef TRITON_H
#define TRITON_H
#include <sys/time.h>
#include <pthread.h>
#include <sys/epoll.h>
#include <triton.h>
struct triton_thread_t
{
struct list_head entry;
pthread_t thread;
int terminate:1;
struct triton_ctx_t *ctx;
};
struct triton_ctx_t
{
struct list_head entry;
struct list_head entry2;
spinlock_t lock;
struct list_head handlers;
struct list_head timers;
triton_thread_t *thread;
struct list_head pending_handlers;
struct list_head pending_timers;
int queued:1;
int close:1;
};
struct triton_md_handler_t
{
//triton part
//==========
struct list_head entry;
struct list_head entry2;
struct triton_ctx_t *ctx;
struct epoll_event epoll_event;
uint32_t trig_epoll_event;
int pending:1;
//=========
//user part
//=========
int fd;
int (*read)(struct triton_md_handler_t *);
int (*write)(struct triton_md_handler_t *);
void (*close)(struct triton_md_handler_t *);
//=========
};
struct triton_timer_t
{
struct list_head entry;
int active;
int pending:1;
struct timeval expire_tv;
int period;
int (*expire)(struct triton_timer_t *);
};
#define MD_MODE_READ 1
#define MD_MODE_WRITE 2
void triton_md_register_handler(struct triton_md_handler_t *h);
void triton_md_unregister_handler(struct triton_md_handler_t *h);
void triton_md_enable_handler(struct triton_md_handler_t *h, int mode);
void triton_md_disable_handler(struct triton_md_handler_t *h,int mode);
void triton_md_set_timeout(struct triton_md_handler_t *h, int msec);
void triton_timer_add(struct triton_timer_t*);
void triton_timer_del(struct triton_timer_t*);
typedef void (*triton_ss_func)(void);
void triton_timer_single_shot1(int twait,triton_ss_func,int argc,...);
void triton_timer_single_shot2(struct timeval *shot_tv,triton_ss_func,int argc,...);
void triton_timer_single_shot3(int tv_sec,int tv_usec,triton_ss_func,int argc,...);
int triton_get_int_option(const char *str);
const char* triton_get_str_option(const char *str);
double triton_get_double_option(const char *str);
void triton_terminate(void);
void triton_process_events(void);
#define TRITON_OK 0
#define TRITON_ERR_NOCOMP -1
#define TRITON_ERR_NOSUPP -2
#define TRITON_ERR_NOINTF -3
#define TRITON_ERR_EXISTS -4
#define TRITON_ERR_NOCHAN -5
#define TRITON_ERR_NOMSG -6
#define TRITON_ERR_BUSY -5
int triton_init(const char *conf_file);
int triton_run(int (*post_init)(void*),void *arg);
#endif
|