diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-12-30 10:41:47 -0800 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-12-30 10:41:47 -0800 |
commit | a4585e1e6f58be216876a5de9630556e9dd25f04 (patch) | |
tree | c272a4a8a47686355a1bc91fb3af12e447809c1c | |
parent | a6b51d4e45f15c0eca7e5cfce377e4883ceae8e0 (diff) | |
download | connman-a4585e1e6f58be216876a5de9630556e9dd25f04.tar.gz connman-a4585e1e6f58be216876a5de9630556e9dd25f04.tar.bz2 connman-a4585e1e6f58be216876a5de9630556e9dd25f04.zip |
Add set property result handling for supplicant test program
-rw-r--r-- | tools/supplicant-dbus.c | 27 | ||||
-rw-r--r-- | tools/supplicant-dbus.h | 8 | ||||
-rw-r--r-- | tools/supplicant.c | 15 |
3 files changed, 40 insertions, 10 deletions
diff --git a/tools/supplicant-dbus.c b/tools/supplicant-dbus.c index e6378c32..e0e0432e 100644 --- a/tools/supplicant-dbus.c +++ b/tools/supplicant-dbus.c @@ -180,24 +180,40 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface, } struct property_set_data { + supplicant_dbus_result_function function; void *user_data; }; static void property_set_reply(DBusPendingCall *call, void *user_data) { - //struct property_set_data *data = user_data; + struct property_set_data *data = user_data; DBusMessage *reply; + DBusMessageIter iter; + const char *error; reply = dbus_pending_call_steal_reply(call); if (reply == NULL) return; + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) + error = dbus_message_get_error_name(reply); + else + error = NULL; + + if (dbus_message_iter_init(reply, &iter) == FALSE) + goto done; + + if (data->function != NULL) + data->function(error, &iter, data->user_data); + +done: dbus_message_unref(reply); } int supplicant_dbus_property_set(const char *path, const char *interface, const char *key, const char *signature, - supplicant_dbus_value_function function, + supplicant_dbus_setup_function setup, + supplicant_dbus_result_function function, void *user_data) { struct property_set_data *data; @@ -208,6 +224,9 @@ int supplicant_dbus_property_set(const char *path, const char *interface, if (path == NULL || interface == NULL) return -EINVAL; + if (key == NULL || signature == NULL || setup == NULL) + return -EINVAL; + data = dbus_malloc0(sizeof(*data)); if (data == NULL) return -ENOMEM; @@ -227,8 +246,7 @@ int supplicant_dbus_property_set(const char *path, const char *interface, dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, signature, &value); - if (function != NULL) - function(&value, user_data); + setup(&value, user_data); dbus_message_iter_close_container(&iter, &value); if (dbus_connection_send_with_reply(connection, message, @@ -244,6 +262,7 @@ int supplicant_dbus_property_set(const char *path, const char *interface, return -EIO; } + data->function = function; data->user_data = user_data; dbus_pending_call_set_notify(call, property_set_reply, diff --git a/tools/supplicant-dbus.h b/tools/supplicant-dbus.h index 51981e27..162ec72e 100644 --- a/tools/supplicant-dbus.h +++ b/tools/supplicant-dbus.h @@ -31,9 +31,12 @@ typedef void (* supplicant_dbus_array_function) (DBusMessageIter *iter, typedef void (* supplicant_dbus_property_function) (const char *key, DBusMessageIter *iter, void *user_data); -typedef void (* supplicant_dbus_value_function) (DBusMessageIter *iter, +typedef void (* supplicant_dbus_setup_function) (DBusMessageIter *iter, void *user_data); +typedef void (* supplicant_dbus_result_function) (const char *error, + DBusMessageIter *iter, void *user_data); + void supplicant_dbus_setup(DBusConnection *conn); void supplicant_dbus_array_foreach(DBusMessageIter *iter, @@ -50,5 +53,6 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface, int supplicant_dbus_property_set(const char *path, const char *interface, const char *key, const char *signature, - supplicant_dbus_value_function function, + supplicant_dbus_setup_function setup, + supplicant_dbus_result_function function, void *user_data); diff --git a/tools/supplicant.c b/tools/supplicant.c index cd5c6ae5..b9b11fcf 100644 --- a/tools/supplicant.c +++ b/tools/supplicant.c @@ -1141,6 +1141,13 @@ void supplicant_unregister(const struct supplicant_callbacks *callbacks) eap_methods = 0; } +static void debug_level_result(const char *error, + DBusMessageIter *iter, void *user_data) +{ + if (error != NULL) + DBG("debug level failure: %s", error); +} + static void add_debug_level(DBusMessageIter *iter, void *user_data) { dbus_int32_t level = GPOINTER_TO_UINT(user_data); @@ -1161,8 +1168,8 @@ static void add_debug_level(DBusMessageIter *iter, void *user_data) void supplicant_set_debug_level(unsigned int level) { supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE, - "DebugParams", "(ibb)", - add_debug_level, GUINT_TO_POINTER(level)); + "DebugParams", "(ibb)", add_debug_level, + debug_level_result, GUINT_TO_POINTER(level)); } static void add_show_timestamps(DBusMessageIter *iter, void *user_data) @@ -1185,6 +1192,6 @@ static void add_show_timestamps(DBusMessageIter *iter, void *user_data) void supplicant_set_debug_show_timestamps(dbus_bool_t enabled) { supplicant_dbus_property_set(SUPPLICANT_PATH, SUPPLICANT_INTERFACE, - "DebugParams", "(ibb)", - add_show_timestamps, GUINT_TO_POINTER(enabled)); + "DebugParams", "(ibb)", add_show_timestamps, + NULL, GUINT_TO_POINTER(enabled)); } |