common-example.c 3.47 KB
Newer Older
Jussi Kukkonen's avatar
Jussi Kukkonen committed
1 2 3 4 5
/*
 * Geoclue
 * common-example.c - Example using the Geoclue common client API
 *
 * Author: Jussi Kukkonen <jku@openedhand.com>
6
 * Copyright 2007 by Garmin Ltd. or its subsidiaries
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
Jussi Kukkonen's avatar
Jussi Kukkonen committed
23 24 25
 */

#include <glib.h>
26
#include <geoclue/geoclue-position.h>
Jussi Kukkonen's avatar
Jussi Kukkonen committed
27 28 29 30

int main (int argc, char** argv)
{
	gchar *service, *path;
31
	GeocluePosition *pos = NULL;
Jussi Kukkonen's avatar
Jussi Kukkonen committed
32 33
	gchar *name = NULL;
	gchar *desc = NULL;
34
	GeoclueStatus status;
35
        GHashTable *options;
Jussi Kukkonen's avatar
Jussi Kukkonen committed
36 37 38 39 40 41 42 43
	GError *error = NULL;
	
	g_type_init();
	
	if (argc != 2) {
		g_printerr ("Usage:\n  common-example <provider_name>\n");
		return 1;
	}
Iain Holmes's avatar
Iain Holmes committed
44
	g_print ("Using provider '%s'\n", argv[1]);
Jussi Kukkonen's avatar
Jussi Kukkonen committed
45 46 47 48 49
	service = g_strdup_printf ("org.freedesktop.Geoclue.Providers.%s", argv[1]);
	path = g_strdup_printf ("/org/freedesktop/Geoclue/Providers/%s", argv[1]);
	
	
	/* Create new GeoclueCommon */
50
	pos = geoclue_position_new (service, path);
Jussi Kukkonen's avatar
Jussi Kukkonen committed
51 52
	g_free (service);
	g_free (path);
53 54
	if (pos == NULL) {
		g_printerr ("Error while creating GeocluePosition object.\n");
Jussi Kukkonen's avatar
Jussi Kukkonen committed
55 56 57
		return 1;
	}
	
58
	
59 60 61 62
	options = g_hash_table_new (g_str_hash, g_str_equal);
        g_hash_table_insert (options, "GPSProvider", "Gypsy");
        g_hash_table_insert (options, "PlaySong", "MGMT-Kids.mp3");

63
        if (!geoclue_provider_set_options (GEOCLUE_PROVIDER (pos), options, &error)) {
64 65 66 67 68 69 70 71
                g_printerr ("Error setting options: %s\n\n", error->message);
                g_error_free (error);
                error = NULL;
        } else {
                g_print ("Options set correctly\n\n");
        }
        g_hash_table_destroy (options);

72 73 74
	if (!geoclue_provider_get_provider_info (GEOCLUE_PROVIDER (pos), 
	                                         &name, &desc,
	                                         &error)) {
Jussi Kukkonen's avatar
Jussi Kukkonen committed
75 76 77 78 79 80 81 82 83 84 85
		g_printerr ("Error getting provider info: %s\n\n", error->message);
		g_error_free (error);
		error = NULL;
	} else {
		g_print ("Provider info:\n");
		g_print ("\tName: %s\n", name);
		g_print ("\tDescription: %s\n\n", desc);
		g_free (name);
		g_free (desc);
	}
	
86 87
	if (!geoclue_provider_get_status (GEOCLUE_PROVIDER (pos), &status, &error)) {
		g_printerr ("Error getting status: %s\n\n", error->message);
Jussi Kukkonen's avatar
Jussi Kukkonen committed
88 89 90
		g_error_free (error);
		error = NULL;
	} else {
91
		switch (status) {
Iain Holmes's avatar
Iain Holmes committed
92
                case GEOCLUE_STATUS_ERROR:
93
                        g_print ("Provider status: error\n");
Iain Holmes's avatar
Iain Holmes committed
94 95
                        break;
                case GEOCLUE_STATUS_UNAVAILABLE:
96
                        g_print ("Provider status: unavailable\n");
Iain Holmes's avatar
Iain Holmes committed
97 98
                        break;
                case GEOCLUE_STATUS_ACQUIRING:
99
                        g_print ("Provider status: acquiring\n");
Iain Holmes's avatar
Iain Holmes committed
100 101
                        break;
                case GEOCLUE_STATUS_AVAILABLE:
102
                        g_print ("Provider status: available\n");
Iain Holmes's avatar
Iain Holmes committed
103
                        break;
104
		}
Jussi Kukkonen's avatar
Jussi Kukkonen committed
105
	}
Jussi Kukkonen's avatar
Jussi Kukkonen committed
106
	
107
	g_object_unref (pos);
Jussi Kukkonen's avatar
Jussi Kukkonen committed
108
	
Jussi Kukkonen's avatar
Jussi Kukkonen committed
109
	return 0;
Jussi Kukkonen's avatar
Jussi Kukkonen committed
110
}