[Telepathy-commits] [telepathy-mission-control/master] Update the Creation interface

Alberto Mardegan alberto.mardegan at nokia.com
Tue Feb 3 06:37:16 PST 2009


Fix it so that it uses the new asynchronous API.
---
 src/mcd-account-manager-creation.c |   70 +++++++++++++++++++++++-------------
 1 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/src/mcd-account-manager-creation.c b/src/mcd-account-manager-creation.c
index 58d1d39..58f7efe 100644
--- a/src/mcd-account-manager-creation.c
+++ b/src/mcd-account-manager-creation.c
@@ -40,6 +40,8 @@
 typedef struct
 {
     McdAccount *account;
+    GHashTable *properties;
+    DBusGMethodInvocation *context;
     GError *error;
 } McdCreationData;
 
@@ -72,42 +74,60 @@ set_property (gpointer key, gpointer val, gpointer userdata)
     }
 }
 
+static inline void
+mcd_creation_data_free (McdCreationData *cd)
+{
+    g_hash_table_unref (cd->properties);
+    if (cd->error)
+	g_error_free (cd->error);
+    g_slice_free (McdCreationData, cd);
+}
+
 static void
-account_manager_create_account (McSvcAccountManagerInterfaceCreation *self,
-				const gchar *manager,
-				const gchar *protocol,
-				const gchar *display_name,
-				GHashTable *parameters,
-				GHashTable *properties,
-				DBusGMethodInvocation *context)
+create_account_cb (McdAccountManager *account_manager, McdAccount *account,
+                   const GError *error, gpointer user_data)
 {
-    McdCreationData cd;
-    GError *error = NULL;
+    McdCreationData *cd = user_data;
     const gchar *object_path;
 
-    cd.error = NULL;
-    cd.account =
-	mcd_account_manager_create_account (MCD_ACCOUNT_MANAGER (self),
-					    manager, protocol, display_name,
-					    parameters, &object_path, &error);
-    if (!cd.account)
+    if (G_UNLIKELY (error))
     {
-	if (!error)
-	    g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
-			 "Internal error");
-	dbus_g_method_return_error (context, error);
-	g_error_free (error);
+	dbus_g_method_return_error (cd->context, (GError *)error);
 	return;
     }
 
-    g_hash_table_foreach (properties, set_property, &cd);
-    if (cd.error)
+    g_return_if_fail (MCD_IS_ACCOUNT (account));
+    cd->account = account;
+    g_hash_table_foreach (cd->properties, set_property, cd);
+    if (cd->error)
     {
-	dbus_g_method_return_error (context, cd.error);
-	g_error_free (cd.error);
+	dbus_g_method_return_error (cd->context, cd->error);
 	return;
     }
-    mc_svc_account_manager_interface_creation_return_from_create_account (context, object_path);
+    object_path = mcd_account_get_object_path (account);
+    mc_svc_account_manager_interface_creation_return_from_create_account
+        (cd->context, object_path);
+}
+
+static void
+account_manager_create_account (McSvcAccountManagerInterfaceCreation *self,
+                                const gchar *manager,
+                                const gchar *protocol,
+                                const gchar *display_name,
+                                GHashTable *parameters,
+                                GHashTable *properties,
+                                DBusGMethodInvocation *context)
+{
+    McdCreationData *cd;
+
+    cd = g_slice_new (McdCreationData);
+    cd->error = NULL;
+    cd->properties = g_hash_table_ref (properties);
+    cd->context = context;
+    mcd_account_manager_create_account (MCD_ACCOUNT_MANAGER (self),
+                                        manager, protocol, display_name,
+                                        parameters, create_account_cb, cd,
+                                        (GDestroyNotify)mcd_creation_data_free);
 }
 
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list