diff options
-rw-r--r-- | clockwatcher.c | 3 | ||||
-rw-r--r-- | gps.h | 13 | ||||
-rw-r--r-- | gpxlogger.c | 5 | ||||
-rw-r--r-- | libgps_dbus.c | 16 | ||||
-rw-r--r-- | libgps_sock.c | 16 |
5 files changed, 33 insertions, 20 deletions
diff --git a/clockwatcher.c b/clockwatcher.c index 56e07fd3..e1191972 100644 --- a/clockwatcher.c +++ b/clockwatcher.c @@ -68,8 +68,7 @@ static int dbus_mainloop(void) { int s; if ((s = gps_dbus_open(&gpsdata)) == 0) { - gps_dbus_stream(&gpsdata, 0, conditionally_log_fix); - gps_dbus_mainloop(); + gps_dbus_mainloop(&gpsdata, 0, conditionally_log_fix); } return s; } @@ -1732,19 +1732,22 @@ extern const char /*@observer@*/ *gps_errstr(const int); extern int gps_sock_open(/*@null@*/const char *, /*@null@*/const char *, /*@out@*/struct gps_data_t *); -extern int gps_sock_read(/*@out@*/struct gps_data_t *); extern int gps_sock_close(struct gps_data_t *); extern int gps_sock_send(struct gps_data_t *, const char *); -extern int gps_shm_open(/*@out@*/struct gps_data_t *); -extern int gps_shm_read(struct gps_data_t *); +extern int gps_sock_read(/*@out@*/struct gps_data_t *); extern bool gps_sock_waiting(const struct gps_data_t *, int); extern int gps_sock_stream(struct gps_data_t *, unsigned int, /*@null@*/void *); extern const char /*@observer@*/ *gps_sock_data(const struct gps_data_t *); +extern int gps_sock_mainloop(struct gps_data_t *, int timeout, + void (*)(struct gps_data_t *)); + +extern int gps_shm_open(/*@out@*/struct gps_data_t *); extern void gps_shm_close(struct gps_data_t *); +extern int gps_shm_read(struct gps_data_t *); extern int gps_dbus_open(struct gps_data_t *); -extern int gps_dbus_stream(struct gps_data_t *, unsigned int, /*@null@*/void *); -extern void gps_dbus_mainloop(void); +extern int gps_dbus_mainloop(struct gps_data_t *, int timeout, + void (*)(struct gps_data_t *)); /* dependencies on struct gpsdata_t end hrere */ diff --git a/gpxlogger.c b/gpxlogger.c index 60ce409c..18c128a8 100644 --- a/gpxlogger.c +++ b/gpxlogger.c @@ -193,10 +193,9 @@ static int dbus_mainloop(void) { int s; - print_gpx_header(); if ((s = gps_dbus_open(&gpsdata)) == 0) { - gps_dbus_stream(&gpsdata, 0, conditionally_log_fix); - gps_dbus_mainloop(); + print_gpx_header(); + gps_dbus_mainloop(&gpsdata, 0, conditionally_log_fix); } return 0; } diff --git a/libgps_dbus.c b/libgps_dbus.c index 5e124f32..56ded895 100644 --- a/libgps_dbus.c +++ b/libgps_dbus.c @@ -127,23 +127,19 @@ int gps_dbus_open(struct gps_data_t *gpsdata) return 0; } -int gps_dbus_stream(struct gps_data_t *unused UNUSED, - unsigned int flags UNUSED, - /*@null@*/ void *handler) -{ - /* must refer to the static context here */ - PRIVATE(share_gpsdata)->handler = (void (*)(struct gps_data_t *))handler; - return 0; -} - -void gps_dbus_mainloop(void) +int gps_dbus_mainloop(struct gps_data_t *gpsdata, + int timeout UNUSED, + void (*hook)(struct gps_data_t *)) /* run a DBUS main loop with a specified handler */ { GMainLoop *mainloop; + share_gpsdata = gpsdata; + PRIVATE(share_gpsdata)->handler = (void (*)(struct gps_data_t *))hook; mainloop = g_main_loop_new(NULL, FALSE); dbus_connection_setup_with_g_main(connection, NULL); g_main_loop_run(mainloop); + return 0; } #endif /* defined(DBUS_EXPORT_ENABLE) && !defined(S_SPLINT_S) */ diff --git a/libgps_sock.c b/libgps_sock.c index 5a5b425c..ae4d45c3 100644 --- a/libgps_sock.c +++ b/libgps_sock.c @@ -565,6 +565,22 @@ int gps_sock_stream(struct gps_data_t *gpsdata, unsigned int flags, } } +int gps_sock_mainloop(struct gps_data_t *gpsdata, int timeout, + void (*hook)(struct gps_data_t *gpsdata)) +/* run a socket main loop with a specified handler */ +{ + for (;;) { + if (!gps_waiting(gpsdata, timeout)) { + return -1; + } else { + (void)gps_read(gpsdata); + (*hook)(gpsdata); + } + } + (void)gps_close(gpsdata); + return 0; +} + #endif /* SOCKET_EXPORT_ENABLE */ /* end */ |