summaryrefslogtreecommitdiff
path: root/libgpsd_core.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-03-08 07:32:37 -0400
committerEric S. Raymond <esr@thyrsus.com>2015-03-08 07:32:37 -0400
commit8b6c5dc9b114b18f2af6ec8865ed77b55b48269e (patch)
tree244ad8d3b0c8f8333f912098ddb8d0883843f33f /libgpsd_core.c
parent4157fc2c007f962d0e898e88b0fd3a89cea348ee (diff)
downloadgpsd-8b6c5dc9b114b18f2af6ec8865ed77b55b48269e.tar.gz
Decouple (mostly) the PPS thread-monitor from the session structure.
This is the big step towards ntplib. A couple of minor issues remain to be ironed out, the most significant of which is what to do about the timestamp_t type. This changes some field offsets of private fields in struct gps_device_t. Probably does not require a version bump as access to them is all through the libgpsd API. All regression tests pass. PPS observed live in gpsmon direct mode.
Diffstat (limited to 'libgpsd_core.c')
-rw-r--r--libgpsd_core.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/libgpsd_core.c b/libgpsd_core.c
index 778a0920..0dbaf6b7 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -389,9 +389,42 @@ void gpsd_deactivate(struct gps_device_t *session)
session->gpsdata.online = (timestamp_t)0;
}
+static void ppsthread_log(volatile struct pps_thread_t *pps_thread,
+ int loglevel, const char *fmt, ...)
+/* shim function to decouple PPS monitor code from the session structure */
+{
+ struct gps_device_t *device = (struct gps_device_t *)pps_thread->context;
+ char buf[BUFSIZ];
+ va_list ap;
+
+ switch (loglevel) {
+ case THREAD_ERROR:
+ loglevel = LOG_ERROR;
+ break;
+ case THREAD_WARN:
+ loglevel = LOG_WARN;
+ break;
+ case THREAD_INF:
+ loglevel = LOG_INF;
+ break;
+ case THREAD_PROG:
+ loglevel = LOG_PROG;
+ break;
+ case THREAD_RAW:
+ loglevel = LOG_RAW;
+ break;
+ }
+
+ buf[0] = '\0';
+ va_start(ap, fmt);
+ gpsd_vlog(&device->context->errout, loglevel, buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+}
+
+
/*@-usereleased -compdef@*/
void gpsd_clear(struct gps_device_t *session)
-/* clear a device's storage for use */
+/* device has been opened - clear its storage for use */
{
session->gpsdata.online = timestamp();
lexer_init(&session->lexer);
@@ -407,8 +440,13 @@ void gpsd_clear(struct gps_device_t *session)
/* clear the private data union */
memset( (void *)&session->driver, '\0', sizeof(session->driver));
#ifdef PPS_ENABLE
- /* clear the context structure for the PPS thread monitor */
+ /* set up the context structure for the PPS thread monitor */
memset((void *)&session->pps_thread, 0, sizeof(session->pps_thread));
+ session->pps_thread.devicefd = session->gpsdata.gps_fd;
+ session->pps_thread.devicename = session->gpsdata.dev.path;
+ session->pps_thread.pps_hook = NULL;
+ session->pps_thread.log_hook = ppsthread_log;
+ session->pps_thread.context = (void *)session;
#endif /* PPS_ENABLE */
session->opentime = timestamp();
@@ -1650,7 +1688,8 @@ void ntp_latch(struct gps_device_t *device, struct timedelta_t /*@out@*/*td)
#ifdef PPS_ENABLE
/* thread-safe update */
/*@-compdef@*/
- pps_thread_stash_fixtime(device, device->newdata.time, td->clock);
+ pps_thread_stash_fixtime(&device->pps_thread,
+ device->newdata.time, td->clock);
/*@+compdef@*/
#endif /* PPS_ENABLE */
}