From 9d558486fd0a2904ff4ae0f87a0ae8f99e616b2e Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Tue, 12 Mar 2013 11:04:43 +0200 Subject: [PATCH 4/4] Clean up closure handling in the example domain. The explicit OpData struct is not necessary, and not what the rest of the code does. --- service/realm-example.c | 59 +++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/service/realm-example.c b/service/realm-example.c index 3c0c2ba..9419c93 100644 --- a/service/realm-example.c +++ b/service/realm-example.c @@ -131,11 +131,6 @@ match_admin_and_password (RealmIniConfig *config, return (memcmp (data, pass, size) == 0); } -typedef struct { - RealmExample *self; - GSimpleAsyncResult *async; -} OpData; - static gdouble settings_delay (const gchar *realm_name, const gchar *key) { @@ -143,25 +138,18 @@ settings_delay (const gchar *realm_name, const gchar *key) } static void -free_op_data (OpData *data) -{ - g_object_unref (data->self); - g_object_unref (data->async); - g_free (data); -} - -static void on_join_sleep_done (GObject *source, GAsyncResult *res, gpointer user_data) { - OpData *data = user_data; + GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); + RealmExample *self = REALM_EXAMPLE (g_simple_async_result_get_op_res_gpointer (async)); GError *error = NULL; const gchar *realm_name; if (realm_usleep_finish (res, &error)) { - realm_name = realm_kerberos_get_name (REALM_KERBEROS (data->self)); - realm_ini_config_change (data->self->config, realm_name, &error, + realm_name = realm_kerberos_get_name (REALM_KERBEROS (self)); + realm_ini_config_change (self->config, realm_name, &error, "login-formats", "%U@%D", "login-permitted", "", "login-policy", REALM_DBUS_LOGIN_POLICY_PERMITTED, @@ -169,10 +157,9 @@ on_join_sleep_done (GObject *source, } if (error) - g_simple_async_result_take_error (data->async, error); + g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (data->async); - free_op_data (data); + g_simple_async_result_complete (async); } static void @@ -211,12 +198,10 @@ realm_example_join_async (RealmKerberosMembership *membership, g_simple_async_result_complete_in_idle (async); } else { - OpData *data = g_new0 (OpData, 1); - data->self = g_object_ref (self); - data->async = g_object_ref (async); + g_simple_async_result_set_op_res_gpointer (async, g_object_ref (self), g_object_unref); realm_usleep_async (settings_delay (realm_name, "example-join-delay"), realm_invocation_get_cancellable (invocation), - on_join_sleep_done, data); + on_join_sleep_done, g_object_ref (async)); } g_object_unref (async); @@ -227,24 +212,24 @@ on_leave_sleep_done (GObject *source, GAsyncResult *res, gpointer user_data) { - OpData *data = user_data; + GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); + RealmExample *self = REALM_EXAMPLE (g_simple_async_result_get_op_res_gpointer (async)); GError *error = NULL; const gchar *realm_name; if (realm_usleep_finish (res, &error)) { - realm_name = realm_kerberos_get_name (REALM_KERBEROS (data->self)); + realm_name = realm_kerberos_get_name (REALM_KERBEROS (self)); - if (realm_ini_config_begin_change (data->self->config, &error)) { - realm_ini_config_remove_section (data->self->config, realm_name); - realm_ini_config_finish_change (data->self->config, &error); + if (realm_ini_config_begin_change (self->config, &error)) { + realm_ini_config_remove_section (self->config, realm_name); + realm_ini_config_finish_change (self->config, &error); } } if (error) - g_simple_async_result_take_error (data->async, error); + g_simple_async_result_take_error (async, error); - g_simple_async_result_complete (data->async); - free_op_data (data); + g_simple_async_result_complete (async); } static GSimpleAsyncResult * @@ -298,12 +283,10 @@ realm_example_leave_password_async (RealmKerberosMembership *membership, g_simple_async_result_complete_in_idle (async); } else { - OpData *data = g_new0 (OpData, 1); - data->self = g_object_ref (self); - data->async = g_object_ref (async); + g_simple_async_result_set_op_res_gpointer (async, g_object_ref (self), g_object_unref); realm_usleep_async (settings_delay (realm_name, "example-leave-delay"), realm_invocation_get_cancellable (invocation), - on_leave_sleep_done, data); + on_leave_sleep_done, g_object_ref (async)); } g_object_unref (async); @@ -333,12 +316,10 @@ realm_example_leave_automatic_async (RealmKerberosMembership *membership, g_simple_async_result_complete_in_idle (async); } else { - OpData *data = g_new0 (OpData, 1); - data->self = g_object_ref (self); - data->async = g_object_ref (async); + g_simple_async_result_set_op_res_gpointer (async, g_object_ref (self), g_object_unref); realm_usleep_async (settings_delay (realm_name, "example-leave-delay"), realm_invocation_get_cancellable (invocation), - on_leave_sleep_done, data); + on_leave_sleep_done, g_object_ref (async)); } g_object_unref (async); -- 1.8.1.4