From: Marcel Holtmann Date: Sat, 19 Dec 2009 08:24:47 +0000 (-0800) Subject: Add helpers for appending flexible D-Bus arrays X-Git-Tag: 0.48~88 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c87b66b1687f815151bc9303ba6ae4dad09d93a;p=platform%2Fupstream%2Fconnman.git Add helpers for appending flexible D-Bus arrays --- diff --git a/include/dbus.h b/include/dbus.h index a3c36af..09a0a6c 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -45,16 +45,13 @@ extern "C" { #define CONNMAN_CONNECTION_INTERFACE CONNMAN_SERVICE ".Connection" #define CONNMAN_PROVIDER_INTERFACE CONNMAN_SERVICE ".Provider" +typedef void (* connman_dbus_append_cb_t) (DBusMessageIter *iter); + DBusConnection *connman_dbus_get_connection(void); void connman_dbus_property_append_variant(DBusMessageIter *property, const char *key, int type, void *val); -void connman_dbus_dict_append_array(DBusMessageIter *dict, - const char *key, int type, void *val, int len); -void connman_dbus_dict_append_variant(DBusMessageIter *dict, - const char *key, int type, void *val); - static inline void connman_dbus_dict_open(DBusMessageIter *iter, DBusMessageIter *dict) { @@ -70,6 +67,14 @@ static inline void connman_dbus_dict_close(DBusMessageIter *iter, dbus_message_iter_close_container(iter, dict); } +void connman_dbus_dict_append_variant(DBusMessageIter *dict, + const char *key, int type, void *val); + +void connman_dbus_dict_append_fixed_array(DBusMessageIter *dict, + const char *key, int type, void *val, int len); +void connman_dbus_dict_append_variable_array(DBusMessageIter *dict, + const char *key, int type, connman_dbus_append_cb_t function); + dbus_bool_t connman_dbus_validate_ident(const char *ident); char *connman_dbus_encode_string(const char *value); diff --git a/plugins/supplicant.c b/plugins/supplicant.c index c5ed97a..f8d34af 100644 --- a/plugins/supplicant.c +++ b/plugins/supplicant.c @@ -787,7 +787,7 @@ static int set_network(struct supplicant_task *task, DBUS_TYPE_UINT32, &scan_ssid); if (network) - connman_dbus_dict_append_array(&dict, "ssid", + connman_dbus_dict_append_fixed_array(&dict, "ssid", DBUS_TYPE_BYTE, &network, len); else if (address) connman_dbus_dict_append_variant(&dict, "bssid", @@ -831,7 +831,7 @@ static int set_network(struct supplicant_task *task, key[i] = (unsigned char) strtol(tmp, NULL, 16); } - connman_dbus_dict_append_array(&dict, + connman_dbus_dict_append_fixed_array(&dict, "wep_key0", DBUS_TYPE_BYTE, &key, size / 2); free(key); diff --git a/src/dbus.c b/src/dbus.c index 9cb13dd..c025979 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -118,7 +118,20 @@ void connman_dbus_property_append_variant(DBusMessageIter *iter, dbus_message_iter_close_container(iter, &value); } -void connman_dbus_dict_append_array(DBusMessageIter *dict, +void connman_dbus_dict_append_variant(DBusMessageIter *dict, + const char *key, int type, void *val) +{ + DBusMessageIter entry; + + dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, + NULL, &entry); + + connman_dbus_property_append_variant(&entry, key, type, val); + + dbus_message_iter_close_container(dict, &entry); +} + +void connman_dbus_dict_append_fixed_array(DBusMessageIter *dict, const char *key, int type, void *val, int len) { DBusMessageIter entry, value, array; @@ -151,15 +164,40 @@ void connman_dbus_dict_append_array(DBusMessageIter *dict, dbus_message_iter_close_container(dict, &entry); } -void connman_dbus_dict_append_variant(DBusMessageIter *dict, - const char *key, int type, void *val) +void connman_dbus_dict_append_variable_array(DBusMessageIter *dict, + const char *key, int type, connman_dbus_append_cb_t function) { - DBusMessageIter entry; + DBusMessageIter entry, value, array; + const char *variant_sig, *array_sig; + + switch (type) { + case DBUS_TYPE_STRING: + variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING; + array_sig = DBUS_TYPE_STRING_AS_STRING; + break; + case DBUS_TYPE_OBJECT_PATH: + variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING; + array_sig = DBUS_TYPE_OBJECT_PATH_AS_STRING; + break; + default: + return; + } dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); - connman_dbus_property_append_variant(&entry, key, type, val); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, + variant_sig, &value); + + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + array_sig, &array); + if (function) + function(&array); + dbus_message_iter_close_container(&value, &array); + + dbus_message_iter_close_container(&entry, &value); dbus_message_iter_close_container(dict, &entry); } diff --git a/src/network.c b/src/network.c index 8ae72e9..3ad649c 100644 --- a/src/network.c +++ b/src/network.c @@ -143,7 +143,7 @@ static DBusMessage *get_properties(DBusConnection *conn, DBUS_TYPE_UINT16, &network->frequency); if (network->wifi.ssid != NULL && network->wifi.ssid_len > 0) - connman_dbus_dict_append_array(&dict, "WiFi.SSID", + connman_dbus_dict_append_fixed_array(&dict, "WiFi.SSID", DBUS_TYPE_BYTE, &network->wifi.ssid, network->wifi.ssid_len);