diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-01-01 17:39:08 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-01-01 17:39:08 -0500 |
commit | 1ba509fc6ab7827994707c15922f66001918c357 (patch) | |
tree | 6e49b169b7b1c80c2044ccfadbc9fc7e34e1f49c /libgps_core.c | |
parent | 2a87c67bc3bac822a62138bd5d6ace1554eed3be (diff) | |
download | gpsd-1ba509fc6ab7827994707c15922f66001918c357.tar.gz |
Quite down the JSON parser a bit.
Diffstat (limited to 'libgps_core.c')
-rw-r--r-- | libgps_core.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/libgps_core.c b/libgps_core.c index b50ac834..3d38ab85 100644 --- a/libgps_core.c +++ b/libgps_core.c @@ -47,6 +47,8 @@ struct privdata_t #define PRIVATE(gpsdata) ((struct privdata_t *)gpsdata->privdata) #ifdef LIBGPS_DEBUG +#define DEBUG_CALLS 1 /* shallowest debug level */ +#define DEBUG_JSON 5 /* minimum level for verbose JSON debugging */ static int debuglevel = 0; static int waitcount = 0; static FILE *debugfp; @@ -57,7 +59,7 @@ void gps_enable_debug(int level, FILE * fp) debuglevel = level; debugfp = fp; #ifdef CLIENTDEBUG_ENABLE - json_enable_debug(level - 2, fp); + json_enable_debug(level - DEBUG_JSON, fp); #endif } @@ -95,17 +97,17 @@ int gps_open(/*@null@*/const char *host, /*@null@*/const char *port, if (!port) port = DEFAULT_GPSD_PORT; - libgps_debug_trace((1, "gps_open(%s, %s)\n", host, port)); + libgps_debug_trace((DEBUG_CALLS, "gps_open(%s, %s)\n", host, port)); #ifndef USE_QT if ((gpsdata->gps_fd = netlib_connectsock(AF_UNSPEC, host, port, "tcp")) < 0) { errno = gpsdata->gps_fd; - libgps_debug_trace((2, "netlib_connectsock() returns error %d\n", errno)); + libgps_debug_trace((DEBUG_CALLS, "netlib_connectsock() returns error %d\n", errno)); return -1; } else - libgps_debug_trace((2, "netlib_connectsock() returns socket on fd %d\n", + libgps_debug_trace((DEBUG_CALLS, "netlib_connectsock() returns socket on fd %d\n", gpsdata->gps_fd)); #else QTcpSocket *sock = new QTcpSocket(); @@ -138,7 +140,7 @@ int gps_open(/*@null@*/const char *host, /*@null@*/const char *port, int gps_close(struct gps_data_t *gpsdata) /* close a gpsd connection */ { - libgps_debug_trace((1, "gps_close()\n")); + libgps_debug_trace((DEBUG_CALLS, "gps_close()\n")); #ifndef USE_QT free(PRIVATE(gpsdata)); (void)close(gpsdata->gps_fd); @@ -256,13 +258,13 @@ int gps_unpack(char *buf, struct gps_data_t *gpsdata) * return an error status, it must be < 0. */ { - libgps_debug_trace((1, "gps_unpack(%s)\n", buf)); + libgps_debug_trace((DEBUG_CALLS, "gps_unpack(%s)\n", buf)); /* detect and process a JSON response */ if (buf[0] == '{') { const char *jp = buf, **next = &jp; while (next != NULL && *next != NULL && next[0][0] != '\0') { - libgps_debug_trace((1, + libgps_debug_trace((DEBUG_CALLS, "gps_unpack() segment parse '%s'\n", *next)); if (libgps_json_unpack(*next, gpsdata, next) == -1) break; @@ -498,7 +500,7 @@ int gps_unpack(char *buf, struct gps_data_t *gpsdata) gpsdata->raw_hook(gpsdata, buf, strlen(buf)); } #ifndef USE_QT - libgps_debug_trace((1, "final flags: (0x%04x) %s\n", gpsdata->set, + libgps_debug_trace((DEBUG_CALLS, "final flags: (0x%04x) %s\n", gpsdata->set, gps_maskdump(gpsdata->set))); #endif return 0; @@ -514,7 +516,7 @@ bool gps_waiting(struct gps_data_t * gpsdata) fd_set rfds; struct timeval tv; - libgps_debug_trace((1, "gps_waiting(): %d\n", waitcount++)); + libgps_debug_trace((DEBUG_CALLS, "gps_waiting(): %d\n", waitcount++)); if (gpsdata->waiting > 0) return true; @@ -668,7 +670,7 @@ int gps_stream(struct gps_data_t *gpsdata, unsigned int flags, buf[strlen(buf) - 1] = '\0'; (void)strlcat(buf, "};", sizeof(buf)); } - libgps_debug_trace((1, "gps_stream() disable command: %s\n", buf)); + libgps_debug_trace((DEBUG_CALLS, "gps_stream() disable command: %s\n", buf)); return gps_send(gpsdata, buf); } else { /* if ((flags & WATCH_ENABLE) != 0) */ @@ -697,7 +699,7 @@ int gps_stream(struct gps_data_t *gpsdata, unsigned int flags, buf[strlen(buf) - 1] = '\0'; (void)strlcat(buf, "};", sizeof(buf)); } - libgps_debug_trace((1, "gps_stream() enable command: %s\n", buf)); + libgps_debug_trace((DEBUG_CALLS, "gps_stream() enable command: %s\n", buf)); return gps_send(gpsdata, buf); } } |