summaryrefslogtreecommitdiff
path: root/gpsdclient.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-09-29 17:08:47 -0400
committerEric S. Raymond <esr@thyrsus.com>2011-09-29 17:08:47 -0400
commita288b35ae72d57f01ec3f0d829f8087b5405a390 (patch)
treecb1dd3185392d532b56d8e35b31fcb6007668943 /gpsdclient.c
parentfde39f7182173446ba1f6098588dfa21c17e3e30 (diff)
downloadgpsd-a288b35ae72d57f01ec3f0d829f8087b5405a390.tar.gz
Refactor to create shared code useful for clockwatcher.
Diffstat (limited to 'gpsdclient.c')
-rw-r--r--gpsdclient.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/gpsdclient.c b/gpsdclient.c
index 83ca07dd..e56afc28 100644
--- a/gpsdclient.c
+++ b/gpsdclient.c
@@ -15,6 +15,18 @@
#include "gps.h"
#include "gpsdclient.h"
+static struct exportmethod_t exportmethods[] = {
+#if defined(DBUS_EXPORT_ENABLE) && !defined(S_SPLINT_S)
+ {"dbus", GPSD_DBUS_EXPORT, "DBUS broadcast"},
+#endif /* defined(DBUS_EXPORT_ENABLE) && !defined(S_SPLINT_S) */
+#ifdef SHM_EXPORT_ENABLE
+ {"shm", GPSD_SHARED_MEMORY, "shared memory"},
+#endif /* SOCKET_EXPORT_ENABLE */
+#ifdef SOCKET_EXPORT_ENABLE
+ {"sockets", NULL, "JSON via sockets"},
+#endif /* SOCKET_EXPORT_ENABLE */
+};
+
/* convert double degrees to a static string and return a pointer to it
*
* deg_str_type:
@@ -218,4 +230,35 @@ char *maidenhead(double n, double e)
return buf;
}
+#define NITEMS(x) (int)(sizeof(x)/sizeof(x[0])) /* from gpsd.h-tail */
+
+/*null observer*/struct exportmethod_t *export_lookup(const char *name)
+/* Look up an available export method by name */
+{
+ struct exportmethod_t *mp, *method = NULL;
+
+ for (mp = exportmethods;
+ mp < exportmethods + NITEMS(exportmethods);
+ mp++)
+ if (strcmp(mp->name, name) == 0)
+ method = mp;
+ return method;
+}
+
+void export_list(FILE *fp)
+/* list known export methods */
+{
+ struct exportmethod_t *method;
+
+ for (method = exportmethods;
+ method < exportmethods + NITEMS(exportmethods);
+ method++)
+ (void)fprintf(fp, "%s: %s\n", method->name, method->description);
+}
+
+/*null observer*/struct exportmethod_t *export_default(void)
+{
+ return (NITEMS(exportmethods) > 0) ? &exportmethods[0] : NULL;
+}
+
/* gpsclient.c ends here */