summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton/triton.h
blob: 4b4d9c41e2b922e3556a407f2fb0a39254cf97f6 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef TRITON_H
#define TRITON_H

#include <sys/time.h>
#include <stdint.h>

#include "list.h"

struct triton_context_t
{
	const void *tpd; // triton private data, don't touch
	void (*close)(struct triton_context_t*);
	void (*free)(struct triton_context_t*);
	void (*before_switch)(struct triton_context_t *ctx, void *arg);
};

struct triton_md_handler_t
{
	const void *tpd; // triton private data, don't touch!
	int fd;
	int (*read)(struct triton_md_handler_t *);
	int (*write)(struct triton_md_handler_t *);
};

struct triton_timer_t
{
	const void *tpd; // triton private data, don't touch!
	struct timeval expire_tv;
	int period;
	void (*expire)(struct triton_timer_t *);
};

struct triton_sigchld_handler_t
{
	void *tpd;
	int pid;
	void (*handler)(struct triton_sigchld_handler_t *h, int status);
};

struct conf_option_t
{
	struct list_head entry;
	char *name;
	char *val;
};

struct conf_sect_t
{
	const char *name;	
	struct list_head items;
};

struct triton_stat_t
{
	uint32_t mempool_allocated;
	uint32_t mempool_available;
	uint32_t thread_count;
	uint32_t thread_active;
	uint32_t context_count;
	uint32_t context_sleeping;
	uint32_t context_pending;
	uint32_t md_handler_count;
	uint32_t md_handler_pending;
	uint32_t timer_count;
	uint32_t timer_pending;
};

extern struct triton_stat_t triton_stat;
int triton_context_register(struct triton_context_t *, void *arg);
void triton_context_unregister(struct triton_context_t *);
void triton_context_schedule(struct triton_context_t *);
int triton_context_wakeup(struct triton_context_t *);
int triton_context_call(struct triton_context_t *, void (*func)(void *), void *arg);

#define MD_MODE_READ 1
#define MD_MODE_WRITE 2

#define MD_TRIG_EDGE 0
#define MD_TRIG_LEVEL 1

void triton_md_register_handler(struct triton_context_t *, struct triton_md_handler_t *);
void triton_md_unregister_handler(struct triton_md_handler_t *h);
int triton_md_enable_handler(struct triton_md_handler_t *h, int mode);
int triton_md_disable_handler(struct triton_md_handler_t *h,int mode);
void triton_md_set_trig(struct triton_md_handler_t *h, int mode);

int triton_timer_add(struct triton_context_t *ctx, struct triton_timer_t*,int abs_time);
int triton_timer_mod(struct triton_timer_t *,int abs_time);
void triton_timer_del(struct triton_timer_t *);

typedef void (*triton_event_func)(void *);
int triton_event_register_handler(int ev_id, triton_event_func func);
void triton_event_fire(int ev_id, void *arg);

struct conf_sect_t *conf_get_section(const char *name);
char *conf_get_opt(const char *sect, const char *name);

#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_load_modules(const char *md_sect);
void triton_run(void);
void triton_terminate(void);


#define __init __attribute__((constructor))
#define __export __attribute__((visibility("default")))

#undef offsetof
#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

#define container_of(ptr, type, member) ({			\
	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
	(type *)( (char *)__mptr - offsetof(type,member) );})

#endif