summaryrefslogtreecommitdiff
path: root/libgps_shm.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-09-27 15:49:40 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-09-27 15:49:40 -0400
commite7ad4f5d8ccb1203b6590c763444755c58a1d759 (patch)
treeabe00dad0624148a28228fba247a54b9567384a4 /libgps_shm.c
parentc7d7030b8881be73bbbe1492ef4ddd6892d81a2f (diff)
downloadgpsd-e7ad4f5d8ccb1203b6590c763444755c58a1d759.tar.gz
Converge the library APIs for different transports more closely.
Diffstat (limited to 'libgps_shm.c')
-rw-r--r--libgps_shm.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/libgps_shm.c b/libgps_shm.c
index c14ef4ea..61690d1c 100644
--- a/libgps_shm.c
+++ b/libgps_shm.c
@@ -51,6 +51,14 @@ int gps_shm_open(/*@out@*/struct gps_data_t *gpsdata)
return 0;
}
+bool gps_shm_waiting(const struct gps_data_t *gpsdata UNUSED,
+ int timeout UNUSED)
+/* is there input waiting from the GPS? */
+{
+ /* someday, actually check a timestamp */
+ return true;
+}
+
int gps_shm_read(struct gps_data_t *gpsdata)
/* read an update from the shared-memory segment */
{
@@ -109,6 +117,24 @@ void gps_shm_close(struct gps_data_t *gpsdata)
(void)shmdt((const void *)gpsdata->privdata);
}
+
+int gps_shm_mainloop(struct gps_data_t *gpsdata, int timeout,
+ int (*hook)(struct gps_data_t *gpsdata, bool fix))
+/* run a shm main loop with a specified handler */
+{
+ for (;;) {
+ if (!gps_shm_waiting(gpsdata, timeout)) {
+ if ((*hook)(gpsdata, false) != 0)
+ break;
+ } else {
+ (void)gps_shm_read(gpsdata);
+ if ((*hook)(gpsdata, true) != 0)
+ break;
+ }
+ }
+ return 0;
+}
+
#endif /* SHM_EXPORT_ENABLE */
/* end */