summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-09-06 18:27:02 +0400
committerKozlov Dmitry <dima@server>2010-09-06 18:27:02 +0400
commit45243dd2f2be49cd91be1dc28932e6c9040db6a1 (patch)
tree652896ecd889d58d4a3c9d3232c85ff831b31699 /accel-pptpd/triton
parentaf5a96e2d04056b065a36ecbd140a16d0685c7e6 (diff)
downloadaccel-ppp-45243dd2f2be49cd91be1dc28932e6c9040db6a1.tar.gz
accel-ppp-45243dd2f2be49cd91be1dc28932e6c9040db6a1.zip
working on radius module
Diffstat (limited to 'accel-pptpd/triton')
-rw-r--r--accel-pptpd/triton/CMakeLists.txt1
-rw-r--r--accel-pptpd/triton/event.c103
-rw-r--r--accel-pptpd/triton/triton.h4
-rw-r--r--accel-pptpd/triton/triton_p.h9
4 files changed, 116 insertions, 1 deletions
diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt
index fd6b5182..41339d97 100644
--- a/accel-pptpd/triton/CMakeLists.txt
+++ b/accel-pptpd/triton/CMakeLists.txt
@@ -7,6 +7,7 @@ SET(sources_c
loader.c
log.c
mempool.c
+ event.c
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEFINITIONS("-DUSE_SPINLOCK")
diff --git a/accel-pptpd/triton/event.c b/accel-pptpd/triton/event.c
new file mode 100644
index 00000000..17483ec7
--- /dev/null
+++ b/accel-pptpd/triton/event.c
@@ -0,0 +1,103 @@
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "triton_p.h"
+
+static int max_events = 1024;
+static struct _triton_event_t **events;
+
+struct event_handler_t
+{
+ struct list_head entry;
+ triton_event_func func;
+};
+
+int event_init(void)
+{
+ events = malloc(max_events * sizeof(void *));
+ if (!events) {
+ fprintf(stderr,"event:cann't allocate memory\n");
+ return -1;
+ }
+
+ memset(events, 0, max_events * sizeof(void *));
+
+ return 0;
+}
+
+int triton_event_register_handler(int ev_id, triton_event_func func)
+{
+ struct _triton_event_t *ev;
+ struct event_handler_t *h;
+
+ if (ev_id >= max_events)
+ return -1;
+
+ ev = events[ev_id];
+ if (!ev) {
+ ev = malloc(sizeof(*ev));
+ if (!ev) {
+ triton_log_error("event: out of memory\n");
+ return -1;
+ }
+ INIT_LIST_HEAD(&ev->handlers);
+ events[ev_id] = ev;
+ }
+
+ h = malloc(sizeof(*h));
+ if (!h) {
+ triton_log_error("event: out of memory\n");
+ return -1;
+ }
+
+ h->func = func;
+ list_add_tail(&h->entry, &ev->handlers);
+
+ return 0;
+}
+
+/*int triton_event_unregister_handler(int ev_id, triton_event_func func)
+{
+ struct _triton_event_t *ev;
+ struct event_handler_t *h;
+
+ if (ev_id >= max_events)
+ return -1;
+
+ ev = events[ev_id];
+ if (!ev) {
+ return -1;
+ }
+
+ list_for_each_entry(h, &ev->handlers, entry) {
+ if (h->func == func) {
+ if (ev->in_progress)
+ h->func = NULL;
+ else {
+ list_del(&h->entry);
+ free(h);
+ }
+ return 0;
+ }
+ }
+
+ return -1;
+}*/
+
+void triton_event_fire(int ev_id, void *arg)
+{
+ struct _triton_event_t *ev;
+ struct event_handler_t *h;
+
+ if (ev_id >= max_events)
+ return;
+
+ ev = events[ev_id];
+ if (!ev)
+ return;
+
+ list_for_each_entry(h, &ev->handlers, entry)
+ h->func(arg);
+}
+
diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h
index 1009d67a..d130d86e 100644
--- a/accel-pptpd/triton/triton.h
+++ b/accel-pptpd/triton/triton.h
@@ -55,6 +55,10 @@ int triton_timer_add(struct triton_ctx_t *ctx, struct triton_timer_t*,int abs_ti
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);
diff --git a/accel-pptpd/triton/triton_p.h b/accel-pptpd/triton/triton_p.h
index 0f7e7160..c31efd6e 100644
--- a/accel-pptpd/triton/triton_p.h
+++ b/accel-pptpd/triton/triton_p.h
@@ -57,6 +57,11 @@ struct _triton_timer_t
struct triton_timer_t *ud;
};
+struct _triton_event_t
+{
+ struct list_head handlers;
+};
+
typedef void * mempool_t;
mempool_t *mempool_create(int size);
void *mempool_alloc(mempool_t*);
@@ -64,9 +69,11 @@ void mempool_free(void*);
int log_init(void);
int md_init();
+int timer_init();
+int event_init();
+
void md_run();
void md_terminate();
-int timer_init();
void timer_run();
void timer_terminate();
struct triton_ctx_t *default_ctx;