From 18a3d24fe50455bb0c8d39473262c0a49710a225 Mon Sep 17 00:00:00 2001 From: iain Date: Wed, 24 Aug 2011 17:37:43 +0100 Subject: Add and build an example for testing the ListDevices --- examples/Makefile.am | 5 +++++ examples/list-known-gps-devices.c | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 examples/list-known-gps-devices.c 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 + * Copyright (C) 2011 + * + * This example code is in the public domain. + */ + +#include + +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; +} -- cgit v1.2.3