summaryrefslogtreecommitdiff
path: root/src/util/event.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/event.c')
-rw-r--r--src/util/event.c33
1 files changed, 33 insertions, 0 deletions
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 <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <common/linux_list.h>
#include <libgsmd/libgsmd.h>
#include <libgsmd/event.h>
#include <libgsmd/sms.h>
+#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;
+}
personal git repositories of Harald Welte. Your mileage may vary