int main (int argc, char **argv) { GMainLoop *mainloop; GypsyDevice *device; GypsyPosition *position; GypsyCourse *course; GError *error = NULL; char *path; if (argc < 2) { g_print ("Usage: %s device\n", argv[0]); return 0; } g_type_init (); control = gypsy_control_get_default (); path = gypsy_control_create (control, argv[1], &error); if (path == NULL) { g_warning ("Error creating client for %s: %s", argv[1], error->message); g_error_free (error); return 0; } device = gypsy_device_new (path); position = gypsy_position_new (path); g_signal_connect (position, "position-changed", G_CALLBACK (position_changed), NULL); course = gypsy_course_new (path); g_signal_connect (course, "course-changed", G_CALLBACK (course_changed), NULL); gypsy_device_start (device, &error); if (error != NULL) { g_warning ("Error starting %s: %s", argv[1], error->message); g_error_free (error); return 0; } mainloop = g_main_loop_new (NULL, FALSE); g_main_loop_run (mainloop); /* FIXME: Need some way to quit the mainloop */ g_object_unref (control); return 0; }
static gboolean set_options (GcIfaceGeoclue *gc, GHashTable *options, GError **error) { GeoclueGypsy *gypsy = GEOCLUE_GYPSY (gc); const char *device_name; char *path; device_name = g_hash_table_lookup (options, "org.freedesktop.Geoclue.GPSDevice"); if (g_strcmp0 (gypsy->device_name, device_name) == 0) { return TRUE; } g_free (gypsy->device_name); gypsy->device_name = NULL; if (device_name == NULL || *device_name == '\0') { return TRUE; } gypsy->device_name = g_strdup (device_name); g_print ("Gypsy provider using '%s'\n", gypsy->device_name); path = gypsy_control_create (gypsy->control, gypsy->device_name, error); if (*error != NULL) { g_print ("Error - %s?\n", (*error)->message); gypsy->status = GEOCLUE_STATUS_ERROR; return FALSE; } /* If we've got here, then we are out of the ERROR condition */ gypsy->status = GEOCLUE_STATUS_UNAVAILABLE; gypsy->device = gypsy_device_new (path); g_signal_connect (gypsy->device, "connection-changed", G_CALLBACK (connection_changed), gypsy); g_signal_connect (gypsy->device, "fix-status-changed", G_CALLBACK (fix_status_changed), gypsy); gypsy->position = gypsy_position_new (path); g_signal_connect (gypsy->position, "position-changed", G_CALLBACK (position_changed), gypsy); gypsy->course = gypsy_course_new (path); g_signal_connect (gypsy->course, "course-changed", G_CALLBACK (course_changed), gypsy); gypsy->acc = gypsy_accuracy_new (path); g_signal_connect (gypsy->acc, "accuracy-changed", G_CALLBACK (accuracy_changed), gypsy); g_debug ("starting device"); gypsy_device_start (gypsy->device, error); if (*error != NULL) { g_print ("Error - %s?\n", (*error)->message); gypsy->status = GEOCLUE_STATUS_ERROR; g_free (path); return FALSE; } get_initial_status (gypsy); g_free (path); return TRUE; }