Add set property result handling for supplicant test program
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 30 Dec 2009 18:41:47 +0000 (10:41 -0800)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 30 Dec 2009 18:41:47 +0000 (10:41 -0800)
tools/supplicant-dbus.c
tools/supplicant-dbus.h
tools/supplicant.c

index e6378c3..e0e0432 100644 (file)
@@ -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,
index 51981e2..162ec72 100644 (file)
@@ -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);
index cd5c6ae..b9b11fc 100644 (file)
@@ -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));
 }