aboutsummaryrefslogtreecommitdiffstats
path: root/package/libtapi/src/events.c
diff options
context:
space:
mode:
authorJohn Crispin <john@openwrt.org>2010-11-03 19:12:34 +0000
committerJohn Crispin <john@openwrt.org>2010-11-03 19:12:34 +0000
commita8b2a07f375edefec242de9f20d4aefafa927517 (patch)
treed15f5bb696bfa9dfd9555788d411e0ba59b99a65 /package/libtapi/src/events.c
parent72ae8452cda47d6e18e664097a4adbc0eee3fc7b (diff)
downloadupstream-a8b2a07f375edefec242de9f20d4aefafa927517.tar.gz
upstream-a8b2a07f375edefec242de9f20d4aefafa927517.tar.bz2
upstream-a8b2a07f375edefec242de9f20d4aefafa927517.zip
* adds a rewrite of the tapi drivers + sip app. this is the result of lars' gsoc 2010 project, Thanks !
SVN-Revision: 23840
Diffstat (limited to 'package/libtapi/src/events.c')
-rw-r--r--package/libtapi/src/events.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/package/libtapi/src/events.c b/package/libtapi/src/events.c
new file mode 100644
index 0000000000..36e9b62a01
--- /dev/null
+++ b/package/libtapi/src/events.c
@@ -0,0 +1,58 @@
+#include <stdbool.h>
+#include <sys/epoll.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <stdio.h>
+
+#include "events.h"
+
+struct event_callback *event_callbacks;
+
+static int event_epoll_fd = -1;
+
+int event_register(int fd, int events, struct event_callback *cb)
+{
+ struct epoll_event ev;
+
+ if (event_epoll_fd == -1)
+ event_epoll_fd = epoll_create(1);
+
+ ev.events = events;
+ ev.data.ptr = cb;
+
+ cb->fd = fd;
+
+ return epoll_ctl(event_epoll_fd, EPOLL_CTL_ADD, fd, &ev);
+}
+
+int event_unregister(int fd)
+{
+ return epoll_ctl(event_epoll_fd, EPOLL_CTL_DEL, fd, NULL);
+}
+
+int tapi_mainloop(void)
+{
+ struct epoll_event ev[10];
+ struct event_callback *cb;
+ int ret;
+ bool keep;
+ int i;
+
+ if (event_epoll_fd == -1)
+ event_epoll_fd = epoll_create(1);
+
+ while(true) {
+ ret = epoll_wait(event_epoll_fd, ev, 10, -1);
+ for(i = 0; i < ret; ++i) {
+ cb = ev[i].data.ptr;
+ keep = cb->callback(ev[i].events, cb->data);
+ if (!keep)
+ event_unregister(cb->fd);
+ }
+ if (ret < 0)
+ printf("epoll: %d\n", errno);
+ }
+
+ return 0;
+}