From f69edaae7bbb22601e8b213a342ebd3ba4df780a Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 26 Aug 2014 14:15:52 -0400 Subject: Eliminate reverse linkage of gpsd_write. All regression tests pass. --- gpsctl.c | 8 -------- gpsd.c | 8 -------- gpsd.h-tail | 2 ++ gpsdecode.c | 8 -------- gpsmon.c | 3 ++- libgpsd_core.c | 9 +++++++++ test_geoid.c | 8 -------- test_packet.c | 8 -------- 8 files changed, 13 insertions(+), 41 deletions(-) diff --git a/gpsctl.c b/gpsctl.c index 910d5004..4cd7fb33 100644 --- a/gpsctl.c +++ b/gpsctl.c @@ -30,14 +30,6 @@ static unsigned int timeout = 0; /* no timeout */ static struct gps_context_t context; static bool hunting = true; -ssize_t gpsd_write(struct gps_device_t *session, - const char *buf, - const size_t len) -/* pass low-level data to devices straight through */ -{ - return gpsd_serial_write(session, buf, len); -} - /* * Set this as high or higher than the maximum number of subtype * probes in drivers.c. diff --git a/gpsd.c b/gpsd.c index ced2c608..787bdc82 100644 --- a/gpsd.c +++ b/gpsd.c @@ -165,14 +165,6 @@ static void onsig(int sig) signalled = (sig_atomic_t) sig; } -ssize_t gpsd_write(struct gps_device_t *session, - const char *buf, - const size_t len) -/* pass low-level data to devices straight through */ -{ - return gpsd_serial_write(session, buf, len); -} - void gpsd_report(const int debuglevel, const int errlevel, const char *fmt, ...) { diff --git a/gpsd.h-tail b/gpsd.h-tail index 503bbbef..00c9a9b9 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -268,6 +268,8 @@ struct gps_context_t { * and we don't want them reordered either */ /*@reldef@*/volatile char *shmexport; #endif + ssize_t (*serial_write)(struct gps_device_t *, + const char *buf, const size_t len); }; /* state for resolving interleaved Type 24 packets */ diff --git a/gpsdecode.c b/gpsdecode.c index b65e1f46..67ac16da 100644 --- a/gpsdecode.c +++ b/gpsdecode.c @@ -27,14 +27,6 @@ static unsigned int typelist[32]; * **************************************************************************/ -ssize_t gpsd_write(struct gps_device_t *session, - const char *buf, - const size_t len) -/* pass low-level data to devices straight through */ -{ - return gpsd_serial_write(session, buf, len); -} - void gpsd_report(const int debuglevel, const int errlevel, const char *fmt, ...) { diff --git a/gpsmon.c b/gpsmon.c index 37d6b1aa..cfcaa8e2 100644 --- a/gpsmon.c +++ b/gpsmon.c @@ -639,7 +639,7 @@ void gpsd_report(const int debuglevel, const int errlevel, const char *fmt, ...) } } -ssize_t gpsd_write(struct gps_device_t *session, +static ssize_t gpsmon_serial_write(struct gps_device_t *session, const char *buf, const size_t len) /* pass low-level data to devices, echoing it to the log window */ @@ -1099,6 +1099,7 @@ int main(int argc, char **argv) (void)putenv("TZ=UTC"); // for ctime() /*@ +observertrans @*/ gps_context_init(&context); // initialize the report mutex + context.serial_write = gpsmon_serial_write; while ((option = getopt(argc, argv, "aD:LVhl:nt:?")) != -1) { switch (option) { case 'a': diff --git a/libgpsd_core.c b/libgpsd_core.c index f11e4831..5af50977 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -35,6 +35,14 @@ #include "driver_nmea2000.h" #endif /* defined(NMEA2000_ENABLE) */ +ssize_t gpsd_write(struct gps_device_t *session, + const char *buf, + const size_t len) +/* pass low-level data to devices straight through */ +{ + return session->context->serial_write(session, buf, len); +} + #if defined(PPS_ENABLE) static pthread_mutex_t report_mutex; @@ -248,6 +256,7 @@ void gps_context_init(struct gps_context_t *context) #ifdef SHM_EXPORT_ENABLE .shmexport = NULL, #endif /* SHM_EXPORT_ENABLE */ + .serial_write = gpsd_serial_write, }; /*@ +initallelements +nullassign +nullderef @*/ /* *INDENT-ON* */ diff --git a/test_geoid.c b/test_geoid.c index 2392b1a8..19e926ba 100644 --- a/test_geoid.c +++ b/test_geoid.c @@ -10,14 +10,6 @@ #include "gpsd.h" -ssize_t gpsd_write(struct gps_device_t *session, - const char *buf, - const size_t len) -/* pass low-level data to devices straight through */ -{ - return gpsd_serial_write(session, buf, len); -} - void gpsd_report(const int debuglevel, const int errlevel, const char *fmt, ...) { diff --git a/test_packet.c b/test_packet.c index 2228ddbf..13c3e7bc 100644 --- a/test_packet.c +++ b/test_packet.c @@ -17,14 +17,6 @@ static int verbose = 0; -ssize_t gpsd_write(struct gps_device_t *session, - const char *buf, - const size_t len) -/* pass low-level data to devices straight through */ -{ - return gpsd_serial_write(session, buf, len); -} - void gpsd_report(int debuglevel, int errlevel, const char *fmt, ...) /* assemble command in printf(3) style, use stderr or syslog */ { -- cgit v1.2.1