[PATCH 1/2] Make the SetOptions call take an a{sv}
Bastien Nocera
hadess at hadess.net
Fri Apr 23 09:12:53 PDT 2010
Instead of a{ss}, so that we can pass integers properly now.
---
interfaces/gc-iface-geoclue-full.xml | 2 +-
providers/example/geoclue-example.c | 5 +-
providers/gpsd/geoclue-gpsd.c | 17 +++--
providers/gypsy/geoclue-gypsy.c | 11 ++--
src/main.c | 104 +++++++++++++++++++++++++++-------
5 files changed, 104 insertions(+), 35 deletions(-)
diff --git a/interfaces/gc-iface-geoclue-full.xml b/interfaces/gc-iface-geoclue-full.xml
index 7543955..e2bded1 100644
--- a/interfaces/gc-iface-geoclue-full.xml
+++ b/interfaces/gc-iface-geoclue-full.xml
@@ -39,7 +39,7 @@
</signal>
<method name="SetOptions">
- <arg type="a{ss}" name="options" direction="in" />
+ <arg type="a{sv}" name="options" direction="in" />
</method>
<method name="AddReference">
diff --git a/providers/example/geoclue-example.c b/providers/example/geoclue-example.c
index 49d4ae3..a7ef6f7 100644
--- a/providers/example/geoclue-example.c
+++ b/providers/example/geoclue-example.c
@@ -62,7 +62,10 @@ print_option (gpointer key,
gpointer value,
gpointer data)
{
- g_print (" %s - %s\n", key, value);
+ if (G_VALUE_TYPE (value) == G_TYPE_STRING)
+ g_print (" %s - %s\n", key, g_value_get_string (value));
+ else
+ g_print (" %s - %d\n", key, g_value_get_int (value));
}
static gboolean
diff --git a/providers/gpsd/geoclue-gpsd.c b/providers/gpsd/geoclue-gpsd.c
index 6e141a6..dba91be 100644
--- a/providers/gpsd/geoclue-gpsd.c
+++ b/providers/gpsd/geoclue-gpsd.c
@@ -140,14 +140,17 @@ set_options (GcIfaceGeoclue *gc,
GError **error)
{
GeoclueGpsd *gpsd = GEOCLUE_GPSD (gc);
- char *port, *host;
+ GValue *port_value, *host_value;
+ const char *port, *host;
gboolean changed = FALSE;
-
- host = g_hash_table_lookup (options,
- "org.freedesktop.Geoclue.GPSHost");
- port = g_hash_table_lookup (options,
- "org.freedesktop.Geoclue.GPSPort");
-
+
+ host_value = g_hash_table_lookup (options,
+ "org.freedesktop.Geoclue.GPSHost");
+ host = host_value ? g_value_get_string (host_value) : NULL;
+ port_value = g_hash_table_lookup (options,
+ "org.freedesktop.Geoclue.GPSPort");
+ port = port_value ? g_value_get_string (port_value) : NULL;
+
if (port == NULL) {
port = DEFAULT_GPSD_PORT;
}
diff --git a/providers/gypsy/geoclue-gypsy.c b/providers/gypsy/geoclue-gypsy.c
index 7d43450..2b67a1c 100644
--- a/providers/gypsy/geoclue-gypsy.c
+++ b/providers/gypsy/geoclue-gypsy.c
@@ -378,15 +378,16 @@ set_options (GcIfaceGeoclue *gc,
GError **error)
{
GeoclueGypsy *gypsy = GEOCLUE_GYPSY (gc);
+ GValue *device_value;
const char *device_name;
char *path;
- device_name = g_hash_table_lookup (options,
- "org.freedesktop.Geoclue.GPSDevice");
+ device_value = g_hash_table_lookup (options,
+ "org.freedesktop.Geoclue.GPSDevice");
+ device_name = device_value ? g_value_get_string (device_value) : NULL;
- if (g_strcmp0 (gypsy->device_name, device_name) == 0) {
- return TRUE;
- }
+ if (g_strcmp0 (gypsy->device_name, device_name) == 0)
+ return TRUE;
g_free (gypsy->device_name);
gypsy->device_name = NULL;
diff --git a/src/main.c b/src/main.c
index 0f436af..adbe8a8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -44,33 +44,96 @@ static GcMaster *master;
#define GEOCLUE_GCONF_TOP "/apps/geoclue/master"
#define GEOCLUE_MASTER_NAME "org.freedesktop.Geoclue.Master"
+static GValue *
+gconf_value_to_value (GConfValue *value)
+{
+ GValue *gvalue;
+
+ g_return_val_if_fail (value != NULL, NULL);
+ g_return_val_if_fail (value->type == GCONF_VALUE_STRING ||
+ value->type == GCONF_VALUE_INT, NULL);
+
+ if (value->type == GCONF_VALUE_STRING) {
+ const char *str;
+
+ gvalue = g_new0 (GValue, 1);
+ str = gconf_value_get_string (value);
+
+ /* Don't add empty strings in the hashtable */
+ if (str != NULL && str[0] == '\0')
+ str = NULL;
+
+ g_value_init (gvalue, G_TYPE_STRING);
+ g_value_set_string (gvalue, str);
+ } else if (value->type == GCONF_VALUE_INT) {
+ int i;
+
+ gvalue = g_new0 (GValue, 1);
+ i = gconf_value_get_int (value);
+ g_value_init (gvalue, G_TYPE_INT);
+ g_value_set_int (gvalue, i);
+ }
+
+ return gvalue;
+}
+
+static void
+debug_print_key (gboolean init,
+ const char *key,
+ GValue *gvalue)
+{
+ const char *message;
+ char *string;
+
+ if (init)
+ message = "GConf key '%s' initialised to '%s'";
+ else
+ message = "GConf key '%s' changed to '%s'";
+
+ if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING) {
+ string = g_value_dup_string (gvalue);
+ } else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT) {
+ string = g_strdup_printf ("%d", g_value_get_int (gvalue));
+ } else {
+ return;
+ }
+
+ g_message (message, key, string);
+ g_free (string);
+}
+
static void
gconf_key_changed (GConfClient *client,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data)
{
- const char *key, *value;
+ const char *key;
GConfValue *v;
+ GValue *gvalue;
key = gconf_entry_get_key (entry);
v = gconf_entry_get_value (entry);
- if (v->type != GCONF_VALUE_STRING)
+ gvalue = gconf_value_to_value (v);
+ if (gvalue == NULL)
return;
- value = gconf_value_get_string (v);
- g_message ("gconf key changed %s", key);
+ debug_print_key (FALSE, key, gvalue);
- /* Don't add empty strings in the hashtable */
- if (value != NULL && value[0] == '\0')
- value = NULL;
-
- g_hash_table_insert (options, g_path_get_basename (key),
- g_strdup (value));
+ g_hash_table_insert (options, g_path_get_basename (key), gvalue);
g_signal_emit_by_name (G_OBJECT (master), "options-changed", options);
}
+static void
+free_gvalue (GValue *value)
+{
+ if (value == NULL)
+ return;
+ g_value_unset (value);
+ g_free (value);
+}
+
static GHashTable *
load_options (void)
{
@@ -94,26 +157,25 @@ load_options (void)
(GConfClientNotifyFunc) gconf_key_changed,
NULL, NULL, NULL);
- ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) free_gvalue);
g_print ("Master options:\n");
for (e = entries; e; e = e->next) {
GConfEntry *entry = e->data;
- const char *key, *value;
+ const char *key;
GConfValue *v;
+ GValue *gvalue;
key = gconf_entry_get_key (entry);
v = gconf_entry_get_value (entry);
- if (v->type != GCONF_VALUE_STRING)
- continue;
- value = gconf_value_get_string (v);
+ gvalue = gconf_value_to_value (v);
+ if (gvalue == NULL)
+ continue;
- if (value != NULL && value[0] == '\0')
- value = NULL;
+ debug_print_key (TRUE, key, gvalue);
- g_print (" %s = %s\n", key, value);
- g_hash_table_insert (ht, g_path_get_basename (key),
- g_strdup (value));
- gconf_entry_free (entry);
+ g_hash_table_insert (ht, g_path_get_basename (key), gvalue);
+ gconf_entry_free (entry);
}
g_slist_free (entries);
--
1.7.0.1
--=-pko3i9kxq5x/Wypyv0In
Content-Disposition: attachment; filename="0002-Add-support-for-baud-rates-setting-in-Gypsy.patch"
Content-Type: text/x-patch; name="0002-Add-support-for-baud-rates-setting-in-Gypsy.patch"; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit
More information about the GeoClue
mailing list