summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gps.h4
-rw-r--r--libgps.xml6
-rw-r--r--libgps_core.c59
-rw-r--r--libgps_sock.c20
4 files changed, 73 insertions, 16 deletions
diff --git a/gps.h b/gps.h
index 9e92b74a..f2ff9630 100644
--- a/gps.h
+++ b/gps.h
@@ -1717,8 +1717,12 @@ extern int gps_sock_open(/*@null@*/const char *, /*@null@*/const char *,
/*@out@*/struct gps_data_t *);
extern int gps_sock_read(/*@out@*/struct gps_data_t *);
extern int gps_sock_close(struct gps_data_t *);
+extern int gps_sock_send(struct gps_data_t *, const char *);
extern int gps_shm_open(/*@out@*/struct gps_data_t *);
extern int gps_shm_read(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 void gps_shm_close(struct gps_data_t *);
extern void libgps_trace(int errlevel, const char *, ...);
diff --git a/libgps.xml b/libgps.xml
index a05e4ce9..02d93eb8 100644
--- a/libgps.xml
+++ b/libgps.xml
@@ -121,7 +121,7 @@ these.</para>
<para><function>gps_close()</function> ends the session.</para>
<para><function>gps_send()</function> writes a command to the daemon.
-It is not available when using the shared-memory export.
+It does nothing when using the shared-memory export.
The second argument must be a format string containing elements from
the command set documented at
<citerefentry><refentrytitle>gpsd</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
@@ -142,7 +142,7 @@ socket to the daemon has closed or if the shared-memory segment was
unavailable, and 0 if no data is available.</para>
<para><function>gps_waiting()</function> can be used to check whether
-there is data from the daemon (it is not available when usng the
+there is data from the daemon (it always returns true when using the
shared-memory export). The second argument is the maximum amount of
time to wait (in microseconds) on input before returning. It returns
true if there input waiting, false on timeout (no data waiting) or
@@ -158,7 +158,7 @@ Included in case your application wishes to manage socket I/O
itself.</para>
<para><function>gps_data()</function> returns the contents of the
-client data buffer (not available when using the shared-memory
+client data buffer (it returns NULL when using the shared-memory
export). Use with care; this may fail to be a NUL-terminated string if
WATCH_RAW is enabled.</para>
diff --git a/libgps_core.c b/libgps_core.c
index 1aa11e44..eefaf783 100644
--- a/libgps_core.c
+++ b/libgps_core.c
@@ -7,6 +7,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
@@ -136,6 +137,64 @@ int gps_read(struct gps_data_t *gpsdata)
return status;
}
+int gps_send(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, const char *fmt CONDITIONALLY_UNUSED, ...)
+/* send a command to the gpsd instance */
+{
+ int status = -1;
+ char buf[BUFSIZ];
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void)vsnprintf(buf, sizeof(buf) - 2, fmt, ap);
+ va_end(ap);
+ if (buf[strlen(buf) - 1] != '\n')
+ (void)strlcat(buf, "\n", BUFSIZ);
+
+#ifdef SOCKET_EXPORT_ENABLE
+ status = gps_sock_send(gpsdata, buf);
+#endif /* SOCKET_EXPORT_ENABLE */
+
+ return status;
+}
+
+int gps_stream(struct gps_data_t *gpsdata CONDITIONALLY_UNUSED,
+ unsigned int flags CONDITIONALLY_UNUSED,
+ /*@null@*/ void *d CONDITIONALLY_UNUSED)
+{
+ int status = -1;
+
+#ifdef SOCKET_EXPORT_ENABLE
+ status = gps_sock_stream(gpsdata, flags, d);
+#endif /* SOCKET_EXPORT_ENABLE */
+
+ return status;
+}
+
+const char /*@observer@*/ *gps_data(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED)
+/* return the contents of the client data buffer */
+{
+ const char *bufp = NULL;
+
+#ifdef SOCKET_EXPORT_ENABLE
+ bufp = gps_sock_data(gpsdata);
+#endif /* SOCKET_EXPORT_ENABLE */
+
+ return bufp;
+}
+
+bool gps_waiting(const struct gps_data_t *gpsdata CONDITIONALLY_UNUSED, int timeout CONDITIONALLY_UNUSED)
+/* is there input waiting from the GPS? */
+{
+ /* this is bogus, but I can't think of a better solution yet */
+ bool waiting = true;
+
+#ifdef SOCKET_EXPORT_ENABLE
+ waiting = gps_sock_waiting(gpsdata, timeout);
+#endif /* SOCKET_EXPORT_ENABLE */
+
+ return waiting;
+}
+
extern const char /*@observer@*/ *gps_errstr(const int err)
{
/*
diff --git a/libgps_sock.c b/libgps_sock.c
index 159da239..eda50f8c 100644
--- a/libgps_sock.c
+++ b/libgps_sock.c
@@ -10,7 +10,6 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
-#include <stdarg.h>
#include <math.h>
#include <locale.h>
#include <assert.h>
@@ -32,6 +31,7 @@
#include "gps.h"
#include "gpsd.h"
+#ifdef SOCKET_EXPORT_ENABLE
#include "gps_json.h"
#ifdef S_SPLINT_S
@@ -94,7 +94,7 @@ int gps_sock_open(/*@null@*/const char *host, /*@null@*/const char *port,
}
/*@+branchstate@*/
-bool gps_waiting(const struct gps_data_t *gpsdata, int timeout)
+bool gps_sock_waiting(const struct gps_data_t *gpsdata, int timeout)
/* is there input waiting from the GPS? */
{
#ifndef USE_QT
@@ -467,23 +467,15 @@ int gps_unpack(char *buf, struct gps_data_t *gpsdata)
}
/*@ +compdef @*/
-const char /*@observer@*/ *gps_data(const struct gps_data_t *gpsdata)
+const char /*@observer@*/ *gps_sock_data(const struct gps_data_t *gpsdata)
/* return the contents of the client data buffer */
{
return PRIVATE(gpsdata)->buffer;
}
-int gps_send(struct gps_data_t *gpsdata, const char *fmt, ...)
+int gps_sock_send(struct gps_data_t *gpsdata, const char *buf)
/* send a command to the gpsd instance */
{
- char buf[BUFSIZ];
- va_list ap;
-
- va_start(ap, fmt);
- (void)vsnprintf(buf, sizeof(buf) - 2, fmt, ap);
- va_end(ap);
- if (buf[strlen(buf) - 1] != '\n')
- (void)strlcat(buf, "\n", BUFSIZ);
#ifndef USE_QT
if (write(gpsdata->gps_fd, buf, strlen(buf)) == (ssize_t) strlen(buf))
return 0;
@@ -501,7 +493,7 @@ int gps_send(struct gps_data_t *gpsdata, const char *fmt, ...)
#endif
}
-int gps_stream(struct gps_data_t *gpsdata, unsigned int flags,
+int gps_sock_stream(struct gps_data_t *gpsdata, unsigned int flags,
/*@null@*/ void *d)
/* ask gpsd to stream reports at you, hiding the command details */
{
@@ -569,4 +561,6 @@ int gps_stream(struct gps_data_t *gpsdata, unsigned int flags,
}
}
+#endif /* SOCKET_EXPORT_ENABLE */
+
/* end */