summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/Makefile.am5
-rw-r--r--examples/list-known-gps-devices.c44
2 files changed, 49 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index a5f1d1c..fe78d51 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,8 +1,13 @@
noinst_PROGRAMS = \
+ list-known-gps-devices \
simple-gps-dbus \
simple-gps-gypsy \
simple-gps-satellites
+list_known_gps_devices_SOURCES = list-known-gps-devices.c
+list_known_gps_devices_LDADD = $(GYPSY_LIBS) $(top_builddir)/gypsy/libgypsy.la
+list_known_gps_devices_CFLAGS = $(GYPSY_CFLAGS) -I$(top_srcdir)
+
simple_gps_dbus_SOURCES = simple-gps-dbus.c
simple_gps_dbus_LDADD = $(GYPSY_LIBS)
simple_gps_dbus_CFLAGS = $(GYPSY_CFLAGS)
diff --git a/examples/list-known-gps-devices.c b/examples/list-known-gps-devices.c
new file mode 100644
index 0000000..a1e1ec0
--- /dev/null
+++ b/examples/list-known-gps-devices.c
@@ -0,0 +1,44 @@
+/*
+ * Gypsy
+ *
+ * A simple to use and understand GPSD replacement
+ * that uses D-Bus, GLib and memory allocations
+ *
+ * Author: Iain Holmes <iain@sleepfive.com>
+ * Copyright (C) 2011
+ *
+ * This example code is in the public domain.
+ */
+
+#include <gypsy/gypsy-discovery.h>
+
+int
+main (int argc,
+ char **argv)
+{
+ GypsyDiscovery *discovery;
+ GError *error = NULL;
+ char **known_devices;
+ int i;
+
+ g_type_init ();
+
+ discovery = gypsy_discovery_new ();
+ known_devices = gypsy_discovery_list_devices (discovery, &error);
+
+ if (known_devices == NULL) {
+ if (error != NULL) {
+ g_warning ("Error listing devices: %s", error->message);
+ return 0;
+ }
+
+ g_print ("No GPS devices found\n");
+ return 0;
+ }
+
+ for (i = 0; known_devices[i]; i++) {
+ g_print ("[%d] %s\n", i + 1, known_devices[i]);
+ }
+
+ return 0;
+}