From 13519fc5b89dedb5707ab820c513428b368e1ec1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 27 Sep 2011 22:10:40 -0400 Subject: Get back to a state where the shm export works. --- clockwatcher.c | 24 +++++++++++++++++++----- gps.h | 9 ++------- gpxlogger.c | 31 ++++++++++++++++++++++--------- libgps_core.c | 26 -------------------------- libgps_dbus.c | 4 ++-- libgps_shm.c | 25 ------------------------- libgps_sock.c | 12 ++++++------ 7 files changed, 51 insertions(+), 80 deletions(-) diff --git a/clockwatcher.c b/clockwatcher.c index 85d890c8..e1191972 100644 --- a/clockwatcher.c +++ b/clockwatcher.c @@ -43,11 +43,9 @@ static time_t timeout; static int debug; #endif /* CLIENTDEBUG_ENABLE */ -static int conditionally_log_fix(struct gps_data_t *gpsdata UNUSED, - bool fix UNUSED) +static void conditionally_log_fix(struct gps_data_t *gpsdata UNUSED) { /* time logging goes here */ - return 0; } static void quit_handler(int signum) @@ -99,7 +97,16 @@ static int socket_mainloop(void) if (source.device != NULL) flags |= WATCH_DEVICE; (void)gps_stream(&gpsdata, flags, source.device); - gps_sock_mainloop(&gpsdata, 5000000, conditionally_log_fix); + + for (;;) { + if (!gps_waiting(&gpsdata, 5000000)) { + (void)fprintf(stderr, "%s: error while waiting\n", progname); + break; + } else { + (void)gps_read(&gpsdata); + conditionally_log_fix(&gpsdata); + } + } (void)gps_close(&gpsdata); return 0; } @@ -124,7 +131,14 @@ static int shm_mainloop(void) return 1; } - gps_shm_mainloop(&gpsdata, 0, conditionally_log_fix); + for (;;) { + status = gps_read(&gpsdata); + + if (status == -1) + break; + if (status > 0) + conditionally_log_fix(&gpsdata); + } (void)gps_close(&gpsdata); return 0; } diff --git a/gps.h b/gps.h index 4441660e..7905be74 100644 --- a/gps.h +++ b/gps.h @@ -1727,8 +1727,6 @@ extern int gps_read(/*@out@*/struct gps_data_t *); extern int gps_unpack(char *, struct gps_data_t *); extern bool gps_waiting(const struct gps_data_t *, int); extern int gps_stream(struct gps_data_t *, unsigned int, /*@null@*/void *); -extern int gps_mainloop(struct gps_data_t *, int timeout, - int (*)(struct gps_data_t *, bool)); extern const char /*@observer@*/ *gps_data(const struct gps_data_t *); extern const char /*@observer@*/ *gps_errstr(const int); @@ -1741,18 +1739,15 @@ 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, - int (*)(struct gps_data_t *, bool)); + 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_shm_mainloop(struct gps_data_t *, int timeout, - int (*)(struct gps_data_t *, bool)); extern int gps_dbus_open(struct gps_data_t *); -extern bool gps_shm_waiting(const struct gps_data_t *, int); extern int gps_dbus_mainloop(struct gps_data_t *, int timeout, - int (*)(struct gps_data_t *, bool)); + void (*)(struct gps_data_t *)); /* dependencies on struct gpsdata_t end hrere */ diff --git a/gpxlogger.c b/gpxlogger.c index 46a2fe93..18c128a8 100644 --- a/gpxlogger.c +++ b/gpxlogger.c @@ -126,7 +126,7 @@ static void print_fix(struct gps_data_t *gpsdata, double time) (void)fflush(logfile); } -static int conditionally_log_fix(struct gps_data_t *gpsdata, bool fix UNUSED) +static void conditionally_log_fix(struct gps_data_t *gpsdata) { static double int_time, old_int_time; static double old_lat, old_lon; @@ -134,14 +134,14 @@ static int conditionally_log_fix(struct gps_data_t *gpsdata, bool fix UNUSED) int_time = gpsdata->fix.time; if ((int_time == old_int_time) || gpsdata->fix.mode < MODE_2D) - return 0; + return; /* may not be worth logging if we've moved only a very short distance */ if (minmove>0 && !first && earth_distance( gpsdata->fix.latitude, gpsdata->fix.longitude, old_lat, old_lon) < minmove) - return 0; + return; /* * Make new track if the jump in time is above @@ -170,8 +170,6 @@ static int conditionally_log_fix(struct gps_data_t *gpsdata, bool fix UNUSED) old_lon = gpsdata->fix.longitude; } print_fix(gpsdata, int_time); - - return 0; } static void quit_handler(int signum) @@ -228,9 +226,17 @@ static int socket_mainloop(void) (void)gps_stream(&gpsdata, flags, source.device); print_gpx_header(); - gps_sock_mainloop(&gpsdata, 5000000, conditionally_log_fix); + for (;;) { + if (!gps_waiting(&gpsdata, 5000000)) { + (void)fprintf(stderr, "%s: error while waiting\n", progname); + break; + } else { + (void)gps_read(&gpsdata); + conditionally_log_fix(&gpsdata); + } + } print_gpx_footer(); - (void)gps_sock_close(&gpsdata); + (void)gps_close(&gpsdata); return 0; } /*@+mustfreefresh +compdestroy@*/ @@ -255,9 +261,16 @@ static int shm_mainloop(void) } print_gpx_header(); - gps_shm_mainloop(&gpsdata, 0, conditionally_log_fix); + for (;;) { + status = gps_read(&gpsdata); + + if (status == -1) + break; + if (status > 0) + conditionally_log_fix(&gpsdata); + } print_gpx_footer(); - (void)gps_shm_close(&gpsdata); + (void)gps_close(&gpsdata); return 0; } diff --git a/libgps_core.c b/libgps_core.c index 273b3fe2..6ea9f976 100644 --- a/libgps_core.c +++ b/libgps_core.c @@ -173,32 +173,6 @@ int gps_stream(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, return status; } -int gps_mainloop(struct gps_data_t *gpsdata, int timeout, - int (*hook)(struct gps_data_t *gpsdata, bool)) -/* run a socket main loop with a specified handler */ -{ - int status; - - libgps_debug_trace((DEBUG_CALLS, "gps_mainloop() begins\n")); - - /*@ -usedef -compdef -uniondef @*/ -#ifdef SHM_EXPORT_ENABLE - if ((intptr_t)(gpsdata->gps_fd) == -1) { - status = gps_shm_mainloop(gpsdata, timeout, hook); - } -#endif /* SHM_EXPORT_ENABLE */ - -#ifdef SOCKET_EXPORT_ENABLE - if (status == -1) { - status = gps_sock_mainloop(gpsdata, timeout, hook); - } -#endif /* SOCKET_EXPORT_ENABLE */ - /*@ +usedef +compdef +uniondef @*/ - - libgps_debug_trace((DEBUG_CALLS, "gps_mainloop() -> %d\n")); - return status; -} - const char /*@observer@*/ *gps_data(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED) /* return the contents of the client data buffer */ { diff --git a/libgps_dbus.c b/libgps_dbus.c index f2348d6c..56ded895 100644 --- a/libgps_dbus.c +++ b/libgps_dbus.c @@ -128,8 +128,8 @@ int gps_dbus_open(struct gps_data_t *gpsdata) } int gps_dbus_mainloop(struct gps_data_t *gpsdata, - int timeout UNUSED, - int (*hook)(struct gps_data_t *, bool)) + int timeout UNUSED, + void (*hook)(struct gps_data_t *)) /* run a DBUS main loop with a specified handler */ { GMainLoop *mainloop; diff --git a/libgps_shm.c b/libgps_shm.c index 065fd6f0..c14ef4ea 100644 --- a/libgps_shm.c +++ b/libgps_shm.c @@ -51,14 +51,6 @@ int gps_shm_open(/*@out@*/struct gps_data_t *gpsdata) return 0; } -bool gps_shm_waiting(const struct gps_data_t *gpsdata UNUSED, - int timeout UNUSED) -/* is there input waiting from the GPS? */ -{ - /* someday, actually check a timestamp */ - return true; -} - int gps_shm_read(struct gps_data_t *gpsdata) /* read an update from the shared-memory segment */ { @@ -117,23 +109,6 @@ void gps_shm_close(struct gps_data_t *gpsdata) (void)shmdt((const void *)gpsdata->privdata); } - -int gps_shm_mainloop(struct gps_data_t *gpsdata, int timeout, - int (*hook)(struct gps_data_t *gpsdata, bool fix)) -/* run a shm main loop with a specified handler */ -{ - for (;;) { - if (!gps_shm_waiting(gpsdata, timeout)) { - if ((*hook)(gpsdata, false) != 0) - break; - } else { - if (gps_shm_read(gpsdata) == -1 && (*hook)(gpsdata, true) != 0) - break; - } - } - return 0; -} - #endif /* SHM_EXPORT_ENABLE */ /* end */ diff --git a/libgps_sock.c b/libgps_sock.c index f9551940..ae4d45c3 100644 --- a/libgps_sock.c +++ b/libgps_sock.c @@ -566,18 +566,18 @@ int gps_sock_stream(struct gps_data_t *gpsdata, unsigned int flags, } int gps_sock_mainloop(struct gps_data_t *gpsdata, int timeout, - int (*hook)(struct gps_data_t *gpsdata, bool)) + void (*hook)(struct gps_data_t *gpsdata)) /* run a socket main loop with a specified handler */ { for (;;) { - if (!gps_sock_waiting(gpsdata, timeout)) { - if ((*hook)(gpsdata, false) != 0) - break; + if (!gps_waiting(gpsdata, timeout)) { + return -1; } else { - if (gps_sock_read(gpsdata) == -1 || (*hook)(gpsdata, true) != 0) - break; + (void)gps_read(gpsdata); + (*hook)(gpsdata); } } + (void)gps_close(gpsdata); return 0; } -- cgit v1.2.1