diff options
-rw-r--r-- | gps.h | 4 | ||||
-rw-r--r-- | libgps.h | 6 | ||||
-rw-r--r-- | libgps_core.c | 47 |
3 files changed, 53 insertions, 4 deletions
@@ -1727,6 +1727,8 @@ extern int gps_read(/*@out@*/struct gps_data_t *); extern int gps_unpack(char *, struct gps_data_t *); extern bool gps_waiting(const struct gps_data_t *, int); extern int gps_stream(struct gps_data_t *, unsigned int, /*@null@*/void *); +extern int gps_mainloop(struct gps_data_t *, int, + void (*)(struct gps_data_t *)); extern const char /*@observer@*/ *gps_data(const struct gps_data_t *); extern const char /*@observer@*/ *gps_errstr(const int); @@ -1786,12 +1788,14 @@ extern double wgs84_separation(double, double); #define NL_NOCONNECT -6 /* can't connect to host/socket pair */ #define SHM_NOSHARED -7 /* shared-memory segment not available */ #define SHM_NOATTACH -8 /* shared-memory attach failed */ +#define DBUS_FAILURE -9 /* DBUS initialization failure */ #define DEFAULT_GPSD_PORT "2947" /* IANA assignment */ #define DEFAULT_RTCM_PORT "2101" /* IANA assignment */ /* special host values for non-socket exports */ #define GPSD_SHARED_MEMORY "shared memory" +#define GPSD_DBUS_EXPORT "DBUS export" /* * Platform-specific declarations @@ -32,9 +32,9 @@ extern int gps_sock_read(/*@out@*/struct gps_data_t *); extern bool gps_sock_waiting(const struct gps_data_t *, int); extern int gps_sock_stream(struct gps_data_t *, unsigned int, /*@null@*/void *); extern const char /*@observer@*/ *gps_sock_data(const struct gps_data_t *); -extern int gps_sock_mainloop(struct gps_data_t *, int timeout, +extern int gps_sock_mainloop(struct gps_data_t *, int, void (*)(struct gps_data_t *)); -extern int gps_shm_mainloop(struct gps_data_t *, int timeout, +extern int gps_shm_mainloop(struct gps_data_t *, int, void (*)(struct gps_data_t *)); extern int gps_shm_open(/*@out@*/struct gps_data_t *); @@ -42,7 +42,7 @@ extern void gps_shm_close(struct gps_data_t *); extern int gps_shm_read(struct gps_data_t *); extern int gps_dbus_open(struct gps_data_t *); -extern int gps_dbus_mainloop(struct gps_data_t *, int timeout, +extern int gps_dbus_mainloop(struct gps_data_t *, int, void (*)(struct gps_data_t *)); diff --git a/libgps_core.c b/libgps_core.c index d7797ea7..d20c411e 100644 --- a/libgps_core.c +++ b/libgps_core.c @@ -88,6 +88,15 @@ int gps_open(/*@null@*/const char *host, } #endif /* SHM_EXPORT_ENABLE */ +#ifdef DBUS_EXPORT_ENABLE + if (host != NULL && strcmp(host, GPSD_DBUS_EXPORT) == 0) { + status = gps_dbus_open(gpsdata); + if (status != 0) + /* FIXME: it would be better not to throw away information here */ + status = DBUS_FAILURE; + } +#endif /* DBUS_EXPORT_ENABLE */ + #ifdef SOCKET_EXPORT_ENABLE if (status == -1) { status = gps_sock_open(host, port, gpsdata); @@ -183,7 +192,6 @@ int gps_send(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, const char *fmt CO } return status; } - int gps_stream(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, unsigned int flags CONDITIONALLY_UNUSED, /*@null@*/ void *d CONDITIONALLY_UNUSED) @@ -242,6 +250,39 @@ bool gps_waiting(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, int time return waiting; } +int gps_mainloop(struct gps_data_t *gpsdata, int timeout, + void (*hook)(struct gps_data_t *gpsdata)) +{ + int status = -1; + + libgps_debug_trace((DEBUG_CALLS, "gps_mainloop() begins\n")); + + /*@ -usedef -compdef -uniondef @*/ + switch (PRIVATE(gpsdata)->export_type) { +#ifdef SHM_EXPORT_ENABLE + case shm: + status = gps_shm_mainloop(gpsdata, timeout, hook); + break; +#endif /* SHM_EXPORT_ENABLE */ +#ifdef SOCKET_EXPORT_ENABLE + case sockets: + status = gps_sock_mainloop(gpsdata, timeout, hook); + break; +#endif /* SOCKET_EXPORT_ENABLE */ +#ifdef DBUS_EXPORT_ENABLE + case dbus: + status = gps_dbus_mainloop(gpsdata, timeout, hook); + break; +#endif /* DBUS_EXPORT_ENABLE */ + } + /*@ +usedef +compdef +uniondef @*/ + + libgps_debug_trace((DEBUG_CALLS, "gps_mainloop() -> %d (%s)\n", + status, gps_maskdump(gpsdata->set))); + + return status; +} + extern const char /*@observer@*/ *gps_errstr(const int err) { /* @@ -255,6 +296,10 @@ extern const char /*@observer@*/ *gps_errstr(const int err) else if (err == SHM_NOATTACH) return "attach failed for unknown reason"; #endif /* SHM_EXPORT_ENABLE */ +#ifdef DBUS_EXPORT_ENABLE + if (err == DBUS_FAILURE) + return "DBUS initialization failure"; +#endif /* DBUS_EXPORT_ENABLE */ return netlib_errstr(err); #else static char buf[32]; |