diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-09-27 15:49:40 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-09-27 15:49:40 -0400 |
commit | e7ad4f5d8ccb1203b6590c763444755c58a1d759 (patch) | |
tree | abe00dad0624148a28228fba247a54b9567384a4 /libgps_shm.c | |
parent | c7d7030b8881be73bbbe1492ef4ddd6892d81a2f (diff) | |
download | gpsd-e7ad4f5d8ccb1203b6590c763444755c58a1d759.tar.gz |
Converge the library APIs for different transports more closely.
Diffstat (limited to 'libgps_shm.c')
-rw-r--r-- | libgps_shm.c | 26 |
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 */ |