From 8a9ecd462b818ece811450f8912c44f50deaa733 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 19 Sep 2013 19:41:00 +0200 Subject: hacks to make the event log --- src/util/event.c | 33 +++++++++++++++++++++++++++++++++ src/util/event.h | 1 + src/util/libgsmd-tool.c | 3 +++ 3 files changed, 37 insertions(+) (limited to 'src/util') diff --git a/src/util/event.c b/src/util/event.c index ae5ca7b..e19fe28 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -22,12 +22,15 @@ #include #include +#include #include #include #include #include +#define STDIN_BUF_SIZE 1024 + static int incall_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { printf("EVENT: Incoming call type = %u\n", aux->u.call.type); @@ -288,3 +291,33 @@ int event_init(struct lgsm_handle *lh) return rc; } +int event_main(struct lgsm_handle *lgsmh) +{ + int rc; + char buf[STDIN_BUF_SIZE+1]; + fd_set readset; + int gsm_fd = lgsm_fd(lgsmh); + + FD_ZERO(&readset); + + while (1) { + FD_SET(gsm_fd, &readset); + + rc = select(gsm_fd+1, &readset, NULL, NULL, NULL); + if (rc <= 0) + break; + if (FD_ISSET(gsm_fd, &readset)) { + /* we've received something on the gsmd socket, pass it + * on to the library */ + rc = read(gsm_fd, buf, sizeof(buf)); + if (rc <= 0) { + printf("ERROR reading from gsm_fd\n"); + break; + } + rc = lgsm_handle_packet(lgsmh, buf, rc); + if (rc < 0) + printf("ERROR processing packet: %d(%s)\n", rc, strerror(-rc)); + } + } + return 0; +} diff --git a/src/util/event.h b/src/util/event.h index 6901a2d..5caaaba 100644 --- a/src/util/event.h +++ b/src/util/event.h @@ -1,2 +1,3 @@ extern int event_init(struct lgsm_handle *lh); +extern int event_main(struct lgsm_handle *lh); diff --git a/src/util/libgsmd-tool.c b/src/util/libgsmd-tool.c index 5fb1eca..2d34c3a 100644 --- a/src/util/libgsmd-tool.c +++ b/src/util/libgsmd-tool.c @@ -156,6 +156,9 @@ int main(int argc, char **argv) case MODE_SHELL: shell_main(lgsmh, shellwait); break; + case MODE_EVENTLOG: + event_main(lgsmh); + break; } exit(0); -- cgit v1.2.3