summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/adapter.c6
-rw-r--r--src/dbus-common.c126
-rw-r--r--src/dbus-common.h6
-rw-r--r--src/device.c4
4 files changed, 70 insertions, 72 deletions
diff --git a/src/adapter.c b/src/adapter.c
index 24f0b3ae..b9307e7d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3369,8 +3369,8 @@ void adapter_update_devices(struct btd_adapter *adapter)
devices[i] = (char *) device_get_path(dev);
}
- emit_property_changed(connection, adapter->path,
- ADAPTER_INTERFACE, "Devices",
- DBUS_TYPE_ARRAY, &devices);
+ emit_array_property_changed(connection, adapter->path,
+ ADAPTER_INTERFACE, "Devices",
+ DBUS_TYPE_OBJECT_PATH, &devices);
g_free(devices);
}
diff --git a/src/dbus-common.c b/src/dbus-common.c
index 89deccbf..b2edd4c1 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -235,64 +235,39 @@ int hcid_dbus_init(void)
return 0;
}
-static void dbus_message_iter_append_variant(DBusMessageIter *iter,
- int type, void *val)
+static void append_variant(DBusMessageIter *iter, int type, void *val)
{
DBusMessageIter value;
- DBusMessageIter array;
- char *sig;
-
- switch (type) {
- case DBUS_TYPE_STRING:
- sig = DBUS_TYPE_STRING_AS_STRING;
- break;
- case DBUS_TYPE_BYTE:
- sig = DBUS_TYPE_BYTE_AS_STRING;
- break;
- case DBUS_TYPE_INT16:
- sig = DBUS_TYPE_INT16_AS_STRING;
- break;
- case DBUS_TYPE_UINT16:
- sig = DBUS_TYPE_UINT16_AS_STRING;
- break;
- case DBUS_TYPE_INT32:
- sig = DBUS_TYPE_INT32_AS_STRING;
- break;
- case DBUS_TYPE_UINT32:
- sig = DBUS_TYPE_UINT32_AS_STRING;
- break;
- case DBUS_TYPE_BOOLEAN:
- sig = DBUS_TYPE_BOOLEAN_AS_STRING;
- break;
- case DBUS_TYPE_ARRAY:
- sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING;
- break;
- case DBUS_TYPE_OBJECT_PATH:
- sig = DBUS_TYPE_OBJECT_PATH_AS_STRING;
- break;
- default:
- error("Could not append variant with type %d", type);
- return;
- }
+ char sig[2] = { type, '\0' };
dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &value);
- if (type == DBUS_TYPE_ARRAY) {
- int i;
- const char ***str_array = val;
+ dbus_message_iter_append_basic(&value, type, val);
+
+ dbus_message_iter_close_container(iter, &value);
+}
- dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
- DBUS_TYPE_STRING_AS_STRING, &array);
+static void append_array_variant(DBusMessageIter *iter, int type, void *val)
+{
+ DBusMessageIter variant, array;
+ char type_sig[2] = { type, '\0' };
+ char array_sig[3] = { DBUS_TYPE_ARRAY, type, '\0' };
+ const char ***str_array = val;
+ int i;
- for (i = 0; (*str_array)[i]; i++)
- dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING,
- &((*str_array)[i]));
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+ array_sig, &variant);
- dbus_message_iter_close_container(&value, &array);
- } else
- dbus_message_iter_append_basic(&value, type, val);
+ dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+ type_sig, &array);
- dbus_message_iter_close_container(iter, &value);
+ for (i = 0; (*str_array)[i]; i++)
+ dbus_message_iter_append_basic(&array, type,
+ &((*str_array)[i]));
+
+ dbus_message_iter_close_container(&variant, &array);
+
+ dbus_message_iter_close_container(iter, &variant);
}
void dict_append_entry(DBusMessageIter *dict,
@@ -311,7 +286,7 @@ void dict_append_entry(DBusMessageIter *dict,
dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
- dbus_message_iter_append_variant(&entry, type, val);
+ append_variant(&entry, type, val);
dbus_message_iter_close_container(dict, &entry);
}
@@ -319,35 +294,50 @@ void dict_append_entry(DBusMessageIter *dict,
void dict_append_array(DBusMessageIter *dict, const char *key, int type,
void *val, int n_elements)
{
- DBusMessageIter entry, variant, array;
- char type_sig[2] = { type, '\0' };
- char array_sig[3] = { DBUS_TYPE_ARRAY, type, '\0' };
- const char ***str_array = val;
- int i;
+ DBusMessageIter entry;
dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
NULL, &entry);
dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
- dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
- array_sig, &variant);
+ append_array_variant(&entry, type, val);
- dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
- type_sig, &array);
+ dbus_message_iter_close_container(dict, &entry);
+}
- for (i = 0; (*str_array)[i]; i++)
- dbus_message_iter_append_basic(&array, type,
- &((*str_array)[i]));
+dbus_bool_t emit_property_changed(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name,
+ int type, void *value)
+{
+ DBusMessage *signal;
+ DBusMessageIter iter;
+ gboolean ret;
- dbus_message_iter_close_container(&variant, &array);
+ signal = dbus_message_new_signal(path, interface, "PropertyChanged");
- dbus_message_iter_close_container(&entry, &variant);
+ if (!signal) {
+ error("Unable to allocate new %s.PropertyChanged signal",
+ interface);
+ return FALSE;
+ }
- dbus_message_iter_close_container(dict, &entry);
+ dbus_message_iter_init_append(signal, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+ append_variant(&iter, type, value);
+
+ ret = dbus_connection_send(conn, signal, NULL);
+
+ dbus_message_unref(signal);
+
+ return ret;
}
-dbus_bool_t emit_property_changed(DBusConnection *conn,
+dbus_bool_t emit_array_property_changed(DBusConnection *conn,
const char *path,
const char *interface,
const char *name,
@@ -368,10 +358,12 @@ dbus_bool_t emit_property_changed(DBusConnection *conn,
dbus_message_iter_init_append(signal, &iter);
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
- dbus_message_iter_append_variant(&iter, type, value);
+
+ append_array_variant(&iter, type, value);
ret = dbus_connection_send(conn, signal, NULL);
dbus_message_unref(signal);
+
return ret;
}
diff --git a/src/dbus-common.h b/src/dbus-common.h
index 3b758b9d..43393d71 100644
--- a/src/dbus-common.h
+++ b/src/dbus-common.h
@@ -40,3 +40,9 @@ dbus_bool_t emit_property_changed(DBusConnection *conn,
const char *interface,
const char *name,
int type, void *value);
+
+dbus_bool_t emit_array_property_changed(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name,
+ int type, void *value);
diff --git a/src/device.c b/src/device.c
index df9306eb..322d9efe 100644
--- a/src/device.c
+++ b/src/device.c
@@ -828,8 +828,8 @@ static void services_changed(struct btd_device *device)
for (i = 0, l = device->uuids; l; l = l->next, i++)
uuids[i] = l->data;
- emit_property_changed(conn, device->path, DEVICE_INTERFACE, "UUIDs",
- DBUS_TYPE_ARRAY, &uuids);
+ emit_array_property_changed(conn, device->path, DEVICE_INTERFACE,
+ "UUIDs", DBUS_TYPE_STRING, &uuids);
g_free(uuids);
}