diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-09-28 04:21:56 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-09-28 04:21:56 -0400 |
commit | 88eb3cee8d9669d2287a73ca28b4cfdf1829c181 (patch) | |
tree | bef297f5c2524d78aec0c63f75a5c78f65ff32ee | |
parent | af7ae8196bdb7fa2f4319b10c316f60323a43b8d (diff) | |
download | gpsd-88eb3cee8d9669d2287a73ca28b4cfdf1829c181.tar.gz |
Runtime dispatch to methods is working in the client library.
-rw-r--r-- | libgps.h | 13 | ||||
-rw-r--r-- | libgps_core.c | 70 | ||||
-rw-r--r-- | libgps_dbus.c | 2 |
3 files changed, 64 insertions, 21 deletions
@@ -11,7 +11,18 @@ * 'export_type' and must be of this time. It's how we do runtime * dispatch to the different transports. */ -enum export_t {sockets, shm, dbus}; +enum export_t { +#ifdef SOCKET_EXPORT_ENABLE + sockets, +#endif /* SOCKET_EXPORT_ENABLE */ +#ifdef SHM_EXPORT_ENABLE + shm, +#endif /* SHM_EXPORT_ENABLE */ +#ifdef DBUS_EXPORT_ENABLE + dbus, +#endif /* DBUS_EXPORT_ENABLE */ +}; + extern int gps_sock_open(/*@null@*/const char *, /*@null@*/const char *, /*@out@*/struct gps_data_t *); diff --git a/libgps_core.c b/libgps_core.c index fee8985e..d7797ea7 100644 --- a/libgps_core.c +++ b/libgps_core.c @@ -19,7 +19,7 @@ #include "gps_json.h" /* - * All privdata structures have export as a first member, + * 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. */ @@ -109,20 +109,23 @@ 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 - if ((intptr_t)(gpsdata->gps_fd) == -1) { + case shm: gps_shm_close(gpsdata); status = 0; - } + break; #endif /* SHM_EXPORT_ENABLE */ - #ifdef SOCKET_EXPORT_ENABLE - if (status == -1) { + case sockets: status = gps_sock_close(gpsdata); - } + break; #endif /* SOCKET_EXPORT_ENABLE */ + default: + status = 0; + } - return status; + return status; } int gps_read(struct gps_data_t *gpsdata) @@ -133,17 +136,20 @@ 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 - if ((intptr_t)(gpsdata->gps_fd) == -1) { + case shm: status = gps_shm_read(gpsdata); - } + break; #endif /* SHM_EXPORT_ENABLE */ - #ifdef SOCKET_EXPORT_ENABLE - if (status == -1) { + case sockets: status = gps_sock_read(gpsdata); - } + break; #endif /* SOCKET_EXPORT_ENABLE */ + default: + status = 0; + } /*@ +usedef +compdef +uniondef @*/ libgps_debug_trace((DEBUG_CALLS, "gps_read() -> %d (%s)\n", @@ -165,10 +171,16 @@ 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 - status = gps_sock_send(gpsdata, buf); + case sockets: + status = gps_sock_send(gpsdata, buf); + break; #endif /* SOCKET_EXPORT_ENABLE */ - + default: + status = -1; + break; + } return status; } @@ -178,9 +190,16 @@ int gps_stream(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, { int status = -1; + switch (PRIVATE(gpsdata)->export_type) { #ifdef SOCKET_EXPORT_ENABLE - status = gps_sock_stream(gpsdata, flags, d); + case sockets: + status = gps_sock_stream(gpsdata, flags, d); + break; #endif /* SOCKET_EXPORT_ENABLE */ + default: + status = -1; + break; + } return status; } @@ -190,9 +209,16 @@ const char /*@observer@*/ *gps_data(const struct gps_data_t *gpsdata CONDITIONAL { const char *bufp = NULL; + switch (PRIVATE(gpsdata)->export_type) { #ifdef SOCKET_EXPORT_ENABLE - bufp = gps_sock_data(gpsdata); + case sockets: + bufp = gps_sock_data(gpsdata); + break; #endif /* SOCKET_EXPORT_ENABLE */ + default: + bufp = NULL; + break; + } return bufp; } @@ -200,12 +226,18 @@ const char /*@observer@*/ *gps_data(const struct gps_data_t *gpsdata CONDITIONAL bool gps_waiting(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, int timeout CONDITIONALLY_UNUSED) /* is there input waiting from the GPS? */ { - /* this is bogus, but I can't think of a better solution yet */ - bool waiting = true; + bool waiting; + switch (PRIVATE(gpsdata)->export_type) { #ifdef SOCKET_EXPORT_ENABLE - waiting = gps_sock_waiting(gpsdata, timeout); + case sockets: + waiting = gps_sock_waiting(gpsdata, timeout); + break; #endif /* SOCKET_EXPORT_ENABLE */ + default: + waiting = true; + break; + } return waiting; } diff --git a/libgps_dbus.c b/libgps_dbus.c index 0cbb74a1..dc18551a 100644 --- a/libgps_dbus.c +++ b/libgps_dbus.c @@ -13,8 +13,8 @@ #endif /* S_SPLINT_S */ #include "gps.h" -#include "libgps.h" #include "gpsd_config.h" +#include "libgps.h" #if defined(DBUS_EXPORT_ENABLE) && !defined(S_SPLINT_S) |