diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-09-30 06:21:19 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-09-30 06:21:19 -0400 |
commit | 82cd8cd019dec313938cba222871d32dbe5d449b (patch) | |
tree | 78145fc02ad49f37235dc8b1c5d3fa8695859d11 | |
parent | c8014317e6dd0d98dcd4616f039c11317c2d3fe5 (diff) | |
download | gpsd-82cd8cd019dec313938cba222871d32dbe5d449b.tar.gz |
Re-do runtime dispatch in the client library.
-rw-r--r-- | gpxlogger.c | 1 | ||||
-rw-r--r-- | libgps_core.c | 103 | ||||
-rw-r--r-- | libgps_dbus.c | 7 | ||||
-rw-r--r-- | libgps_shm.c | 2 | ||||
-rw-r--r-- | libgps_sock.c | 4 |
5 files changed, 33 insertions, 84 deletions
diff --git a/gpxlogger.c b/gpxlogger.c index d0688ece..cf0f5cf0 100644 --- a/gpxlogger.c +++ b/gpxlogger.c @@ -261,6 +261,7 @@ int main(int argc, char **argv) break; case 'l': export_list(stderr); + exit(0); break; case 'm': minmove = (double )atoi(optarg); diff --git a/libgps_core.c b/libgps_core.c index 47d82bc0..e6c85824 100644 --- a/libgps_core.c +++ b/libgps_core.c @@ -18,17 +18,6 @@ #include "libgps.h" #include "gps_json.h" -/* - * All privdata structures have export_type as a first member, - * and can have others that the individual method libraries - * know about but this one doesn't. - */ -struct privdata_t -{ - enum export_t export_type; -}; -#define PRIVATE(gpsdata) ((struct privdata_t *)gpsdata->privdata) - #ifdef LIBGPS_DEBUG int libgps_debuglevel = 0; @@ -118,23 +107,20 @@ int gps_close(struct gps_data_t *gpsdata) libgps_debug_trace((DEBUG_CALLS, "gps_close()\n")); - switch (PRIVATE(gpsdata)->export_type) { #ifdef SHM_EXPORT_ENABLE - case shm: + if ((intptr_t)(gpsdata->gps_fd) == -1) { gps_shm_close(gpsdata); status = 0; - break; + } #endif /* SHM_EXPORT_ENABLE */ + #ifdef SOCKET_EXPORT_ENABLE - case sockets: + if (status == -1) { status = gps_sock_close(gpsdata); - break; -#endif /* SOCKET_EXPORT_ENABLE */ - default: - status = 0; } +#endif /* SOCKET_EXPORT_ENABLE */ - return status; + return status; } int gps_read(struct gps_data_t *gpsdata) @@ -145,25 +131,22 @@ int gps_read(struct gps_data_t *gpsdata) libgps_debug_trace((DEBUG_CALLS, "gps_read() begins\n")); /*@ -usedef -compdef -uniondef @*/ - switch (PRIVATE(gpsdata)->export_type) { #ifdef SHM_EXPORT_ENABLE - case shm: + if ((intptr_t)(gpsdata->gps_fd) == -1) { status = gps_shm_read(gpsdata); - break; + } #endif /* SHM_EXPORT_ENABLE */ + #ifdef SOCKET_EXPORT_ENABLE - case sockets: + if (status == -1) { status = gps_sock_read(gpsdata); - break; -#endif /* SOCKET_EXPORT_ENABLE */ - default: - status = 0; } +#endif /* SOCKET_EXPORT_ENABLE */ + /*@ +usedef +compdef +uniondef @*/ libgps_debug_trace((DEBUG_CALLS, "gps_read() -> %d (%s)\n", status, gps_maskdump(gpsdata->set))); - /*@ +usedef +compdef +uniondef @*/ return status; } @@ -180,74 +163,47 @@ int gps_send(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, const char *fmt CO if (buf[strlen(buf) - 1] != '\n') (void)strlcat(buf, "\n", BUFSIZ); - switch (PRIVATE(gpsdata)->export_type) { #ifdef SOCKET_EXPORT_ENABLE - case sockets: - status = gps_sock_send(gpsdata, buf); - break; + status = gps_sock_send(gpsdata, buf); #endif /* SOCKET_EXPORT_ENABLE */ - default: - status = -1; - break; - } + return status; } + int gps_stream(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, unsigned int flags CONDITIONALLY_UNUSED, /*@null@*/ void *d CONDITIONALLY_UNUSED) { int status = -1; - switch (PRIVATE(gpsdata)->export_type) { #ifdef SOCKET_EXPORT_ENABLE - case sockets: - status = gps_sock_stream(gpsdata, flags, d); - break; + status = gps_sock_stream(gpsdata, flags, d); #endif /* SOCKET_EXPORT_ENABLE */ - default: - status = -1; - break; - } return status; } -/*@-observertrans -dependenttrans@*/ -const char /*@null observer@*/ *gps_data(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED) +const char /*@observer@*/ *gps_data(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED) /* return the contents of the client data buffer */ { const char *bufp = NULL; - switch (PRIVATE(gpsdata)->export_type) { #ifdef SOCKET_EXPORT_ENABLE - case sockets: - bufp = gps_sock_data(gpsdata); - break; + bufp = gps_sock_data(gpsdata); #endif /* SOCKET_EXPORT_ENABLE */ - default: - bufp = NULL; - break; - } return bufp; } -/*@+observertrans +dependenttrans@*/ bool gps_waiting(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, int timeout CONDITIONALLY_UNUSED) /* is there input waiting from the GPS? */ { - bool waiting; + /* this is bogus, but I can't think of a better solution yet */ + bool waiting = true; - switch (PRIVATE(gpsdata)->export_type) { #ifdef SOCKET_EXPORT_ENABLE - case sockets: - waiting = gps_sock_waiting(gpsdata, timeout); - break; + waiting = gps_sock_waiting(gpsdata, timeout); #endif /* SOCKET_EXPORT_ENABLE */ - default: - waiting = true; - break; - } return waiting; } @@ -260,23 +216,18 @@ int gps_mainloop(struct gps_data_t *gpsdata, int timeout, libgps_debug_trace((DEBUG_CALLS, "gps_mainloop() begins\n")); /*@ -usedef -compdef -uniondef @*/ - switch (PRIVATE(gpsdata)->export_type) { #ifdef SHM_EXPORT_ENABLE - case shm: + if ((intptr_t)(gpsdata->gps_fd) == -1) status = gps_shm_mainloop(gpsdata, timeout, hook); - break; #endif /* SHM_EXPORT_ENABLE */ -#ifdef SOCKET_EXPORT_ENABLE - case sockets: - status = gps_sock_mainloop(gpsdata, timeout, hook); - break; -#endif /* SOCKET_EXPORT_ENABLE */ #ifdef DBUS_EXPORT_ENABLE - case dbus: + if ((intptr_t)(gpsdata->gps_fd) == -2) status = gps_dbus_mainloop(gpsdata, timeout, hook); - break; #endif /* DBUS_EXPORT_ENABLE */ - } +#ifdef SOCKET_EXPORT_ENABLE + if ((intptr_t)(gpsdata->gps_fd) >= 0) + status = gps_sock_mainloop(gpsdata, timeout, hook); +#endif /* SOCKET_EXPORT_ENABLE */ /*@ +usedef +compdef +uniondef @*/ libgps_debug_trace((DEBUG_CALLS, "gps_mainloop() -> %d (%s)\n", diff --git a/libgps_dbus.c b/libgps_dbus.c index dc18551a..c35afad1 100644 --- a/libgps_dbus.c +++ b/libgps_dbus.c @@ -20,7 +20,6 @@ struct privdata_t { - enum export_t export_type; void (*handler)(struct gps_data_t *); }; #define PRIVATE(gpsdata) ((struct privdata_t *)(gpsdata)->privdata) @@ -125,7 +124,11 @@ int gps_dbus_open(struct gps_data_t *gpsdata) return 5; } - PRIVATE(gpsdata)->export_type = dbus; +#ifndef USE_QT + gpsdata->gps_fd = -2; +#else + gpsdata->gps_fd = (void *)(intptr_t)-2; +#endif /* USE_QT */ share_gpsdata = gpsdata; return 0; } diff --git a/libgps_shm.c b/libgps_shm.c index 39782910..7704730a 100644 --- a/libgps_shm.c +++ b/libgps_shm.c @@ -30,7 +30,6 @@ PERMISSIONS /*@-matchfields@*/ struct privdata_t { - enum export_t export_type; void *shmseg; }; /*@+matchfields@*/ @@ -64,7 +63,6 @@ int gps_shm_open(/*@out@*/struct gps_data_t *gpsdata) #else gpsdata->gps_fd = (void *)(intptr_t)-1; #endif /* USE_QT */ - PRIVATE(gpsdata)->export_type = shm; return 0; } diff --git a/libgps_sock.c b/libgps_sock.c index e4543908..eee2b926 100644 --- a/libgps_sock.c +++ b/libgps_sock.c @@ -39,10 +39,8 @@ extern char *strtok_r(char *, const char *, char **); #endif /* S_SPLINT_S */ -/*@-matchfields@*/ struct privdata_t { - enum export_t export_type; bool newstyle; /* data buffered from the last read */ ssize_t waiting; @@ -51,7 +49,6 @@ struct privdata_t int waitcount; #endif /* LIBGPS_DEBUG */ }; -/*@+matchfields@*/ #define PRIVATE(gpsdata) ((struct privdata_t *)gpsdata->privdata) /*@-branchstate@*/ @@ -88,7 +85,6 @@ int gps_sock_open(/*@null@*/const char *host, /*@null@*/const char *port, gpsdata->privdata = (void *)malloc(sizeof(struct privdata_t)); if (gpsdata->privdata == NULL) return -1; - PRIVATE(gpsdata)->export_type = sockets; PRIVATE(gpsdata)->newstyle = false; PRIVATE(gpsdata)->waiting = 0; |