[Telepathy-commits] [telepathy-mission-control/master] Moving code around

Alberto Mardegan alberto.mardegan at nokia.com
Mon Nov 17 00:05:21 PST 2008


Move the implementation of channel requesting from mcd-account.c to
mcd-account-compat.c, and deprecate mcd_account_request_channel_nmc4().
Move the struct mcd_channel_request into mcd-account-compat.c, too.

Rename the prop_value_free() function as _mcd_prop_value_free(), and move it
into mcd-misc.c.
---
 src/mcd-account-compat.c |  119 ++++++++++++++++++++++++++++++++++++++++++++--
 src/mcd-account-compat.h |   15 ++++++
 src/mcd-account.c        |  112 +------------------------------------------
 src/mcd-account.h        |    3 +-
 src/mcd-channel.h        |   11 ----
 src/mcd-master.c         |    3 +-
 src/mcd-misc.c           |    7 +++
 src/mcd-misc.h           |    3 +
 src/mcd-service.c        |    1 +
 9 files changed, 148 insertions(+), 126 deletions(-)

diff --git a/src/mcd-account-compat.c b/src/mcd-account-compat.c
index 5677fb3..80a982e 100644
--- a/src/mcd-account-compat.c
+++ b/src/mcd-account-compat.c
@@ -32,11 +32,13 @@
 #include <dbus/dbus-glib-lowlevel.h>
 #include <telepathy-glib/svc-generic.h>
 #include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/interfaces.h>
 #include <telepathy-glib/util.h>
 #include "mcd-account.h"
 #include "mcd-account-priv.h"
 #include "mcd-account-compat.h"
 #include "mcd-account-manager.h"
+#include "mcd-misc.h"
 #include "_gen/interfaces.h"
 
 static guint last_operation_id = 1;
@@ -158,8 +160,8 @@ account_request_channel (McSvcAccountInterfaceCompat *self,
     req.channel_handle_type = handle_type;
     req.requestor_serial = last_operation_id++;
     req.requestor_client_id = dbus_g_method_get_sender (context);
-    mcd_account_request_channel_nmc4 (MCD_ACCOUNT (self),
-				      &req, &error);
+    _mcd_account_compat_request_channel_nmc4 (MCD_ACCOUNT (self),
+                                              &req, &error);
     if (error)
     {
 	dbus_g_method_return_error (context, error);
@@ -185,8 +187,8 @@ account_request_channel_with_string_handle (McSvcAccountInterfaceCompat *self,
     req.channel_handle_type = handle_type;
     req.requestor_serial = last_operation_id++;
     req.requestor_client_id = dbus_g_method_get_sender (context);
-    mcd_account_request_channel_nmc4 (MCD_ACCOUNT (self),
-				      &req, &error);
+    _mcd_account_compat_request_channel_nmc4 (MCD_ACCOUNT (self),
+                                              &req, &error);
     if (error)
     {
 	dbus_g_method_return_error (context, error);
@@ -221,3 +223,112 @@ account_compat_iface_init (McSvcAccountInterfaceCompatClass *iface,
 #undef IMPLEMENT
 }
 
+static void
+process_channel_request (McdAccount *account, gpointer userdata,
+			 const GError *error)
+{
+    McdChannel *channel = MCD_CHANNEL (userdata);
+    McdConnection *connection;
+    GError *err = NULL;
+
+    if (error)
+    {
+        g_warning ("%s: got error: %s", G_STRFUNC, error->message);
+        /* TODO: report the error to the requestor process */
+        g_object_unref (channel);
+        return;
+    }
+    g_debug ("%s called", G_STRFUNC);
+    connection = mcd_account_get_connection (account);
+    g_return_if_fail (connection != NULL);
+    g_return_if_fail (mcd_connection_get_connection_status (connection)
+                      == TP_CONNECTION_STATUS_CONNECTED);
+
+    mcd_connection_request_channel (connection, channel, &err);
+}
+
+static void
+on_channel_status_changed (McdChannel *channel, McdChannelStatus status,
+                           McdAccount *account)
+{
+    g_debug ("%s (%u)", G_STRFUNC, status);
+    g_return_if_fail (MCD_IS_ACCOUNT (account));
+
+    if (status == MCD_CHANNEL_DISPATCHING)
+    {
+        /* from now on, errors are reported by the dispatcher */
+        g_signal_handlers_disconnect_by_func (channel,
+                                              on_channel_status_changed,
+                                              account);
+    }
+    else if (status == MCD_CHANNEL_FAILED)
+    {
+        const GError *error;
+        McdMaster *master;
+        McdDispatcher *dispatcher = NULL;
+
+        master = mcd_master_get_default ();
+        g_object_get (master, "dispatcher", &dispatcher, NULL);
+        g_return_if_fail (dispatcher != NULL);
+
+        error = _mcd_channel_get_error (channel);
+        g_signal_emit_by_name (G_OBJECT(dispatcher),
+                               "dispatch-failed", channel, error);
+        g_object_unref (dispatcher);
+    }
+}
+
+gboolean
+_mcd_account_compat_request_channel_nmc4 (McdAccount *account,
+                                          const struct mcd_channel_request *req,
+                                          GError **error)
+{
+    McdChannel *channel;
+    GHashTable *properties;
+    GValue *value;
+
+    properties = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                        NULL, _mcd_prop_value_free);
+
+    value = g_slice_new0 (GValue);
+    g_value_init (value, G_TYPE_STRING);
+    g_value_set_string (value, req->channel_type);
+    g_hash_table_insert (properties, TP_IFACE_CHANNEL ".ChannelType", value);
+
+    if (req->channel_handle_string)
+    {
+        value = g_slice_new0 (GValue);
+        g_value_init (value, G_TYPE_STRING);
+        g_value_set_string (value, req->channel_handle_string);
+        g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetID", value);
+    }
+
+    if (req->channel_handle)
+    {
+        value = g_slice_new0 (GValue);
+        g_value_init (value, G_TYPE_UINT);
+        g_value_set_uint (value, req->channel_handle);
+        g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetHandle",
+                             value);
+    }
+
+    value = g_slice_new0 (GValue);
+    g_value_init (value, G_TYPE_UINT);
+    g_value_set_uint (value, req->channel_handle_type);
+    g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetHandleType",
+                         value);
+
+    channel = mcd_channel_new_request (properties);
+    g_object_set ((GObject *)channel,
+                  "requestor-serial", req->requestor_serial,
+                  "requestor-client-id", req->requestor_client_id,
+                  NULL);
+    g_signal_connect (channel, "status-changed",
+                      G_CALLBACK (on_channel_status_changed), account);
+
+    return _mcd_account_online_request (account,
+                                        process_channel_request,
+                                        channel,
+                                        error);
+}
+
diff --git a/src/mcd-account-compat.h b/src/mcd-account-compat.h
index 5158aca..62f9e19 100644
--- a/src/mcd-account-compat.h
+++ b/src/mcd-account-compat.h
@@ -38,5 +38,20 @@ extern const McdDBusProp account_compat_properties[];
 void account_compat_iface_init (McSvcAccountInterfaceCompatClass *iface,
 				     gpointer iface_data);
 
+struct mcd_channel_request
+{
+    const gchar *account_name;
+    const gchar *channel_type;
+    guint channel_handle;
+    const gchar *channel_handle_string;
+    gint channel_handle_type;
+    guint requestor_serial;
+    const gchar *requestor_client_id;
+};
+
+/* not exported */
+gboolean _mcd_account_compat_request_channel_nmc4 (McdAccount *account,
+    const struct mcd_channel_request *req, GError **error);
+
 G_END_DECLS
 #endif
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 8d58fd4..9ce5241 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -43,6 +43,7 @@
 #include "mcd-account-connection.h"
 #include "mcd-account-requests.h"
 #include "mcd-account-manager.h"
+#include "mcd-misc.h"
 #include "mcd-signals-marshal.h"
 #include "mcd-manager.h"
 #include "mcd-master.h"
@@ -151,14 +152,6 @@ enum
 guint _mcd_account_signals[LAST_SIGNAL] = { 0 };
 
 static void
-prop_value_free (gpointer data)
-{
-  GValue *value = (GValue *) data;
-  g_value_unset (value);
-  g_slice_free (GValue, value);
-}
-
-static void
 process_online_request (gpointer key, gpointer cb_userdata, gpointer userdata)
 {
     McdOnlineRequestCb callback = key;
@@ -1611,7 +1604,7 @@ mcd_account_get_parameters (McdAccount *account)
     if (!priv->manager && !load_manager (priv)) return NULL;
 
     params = g_hash_table_new_full (g_str_hash, g_str_equal,
-				    g_free, prop_value_free);
+				    g_free, _mcd_prop_value_free);
     parameters = mcd_manager_get_parameters (priv->manager,
 					     priv->protocol_name);
     if (!parameters) return params;
@@ -2131,111 +2124,12 @@ _mcd_account_online_request (McdAccount *account,
     return TRUE;
 }
 
-static void
-process_channel_request (McdAccount *account, gpointer userdata,
-			 const GError *error)
-{
-    McdAccountPrivate *priv = MCD_ACCOUNT_PRIV (account);
-    McdChannel *channel = MCD_CHANNEL (userdata);
-    GError *err = NULL;
-
-    if (error)
-    {
-	g_warning ("%s: got error: %s", G_STRFUNC, error->message);
-	/* TODO: report the error to the requestor process */
-        g_object_unref (channel);
-	return;
-    }
-    g_debug ("%s called", G_STRFUNC);
-    g_return_if_fail (priv->connection != NULL);
-    g_return_if_fail (priv->conn_status == TP_CONNECTION_STATUS_CONNECTED);
-
-    mcd_connection_request_channel (priv->connection, channel, &err);
-}
-
-static void
-on_channel_status_changed (McdChannel *channel, McdChannelStatus status,
-                           McdAccount *account)
-{
-    g_debug ("%s (%u)", G_STRFUNC, status);
-    g_return_if_fail (MCD_IS_ACCOUNT (account));
-
-    if (status == MCD_CHANNEL_DISPATCHING)
-    {
-        /* from now on, errors are reported by the dispatcher */
-        g_signal_handlers_disconnect_by_func (channel,
-                                              on_channel_status_changed,
-                                              account);
-    }
-    else if (status == MCD_CHANNEL_FAILED)
-    {
-        const GError *error;
-        McdMaster *master;
-        McdDispatcher *dispatcher = NULL;
-
-        master = mcd_master_get_default ();
-        g_object_get (master, "dispatcher", &dispatcher, NULL);
-        g_return_if_fail (dispatcher != NULL);
-
-        error = _mcd_channel_get_error (channel);
-        g_signal_emit_by_name (G_OBJECT(dispatcher),
-                               "dispatch-failed", channel, error);
-        g_object_unref (dispatcher);
-    }
-}
-
 gboolean
 mcd_account_request_channel_nmc4 (McdAccount *account,
 				  const struct mcd_channel_request *req,
 				  GError **error)
 {
-    McdChannel *channel;
-    GHashTable *properties;
-    GValue *value;
-
-    properties = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                        NULL, prop_value_free);
-
-    value = g_slice_new0 (GValue);
-    g_value_init (value, G_TYPE_STRING);
-    g_value_set_string (value, req->channel_type);
-    g_hash_table_insert (properties, TP_IFACE_CHANNEL ".ChannelType", value);
-
-    if (req->channel_handle_string)
-    {
-        value = g_slice_new0 (GValue);
-        g_value_init (value, G_TYPE_STRING);
-        g_value_set_string (value, req->channel_handle_string);
-        g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetID", value);
-    }
-
-    if (req->channel_handle)
-    {
-        value = g_slice_new0 (GValue);
-        g_value_init (value, G_TYPE_UINT);
-        g_value_set_uint (value, req->channel_handle);
-        g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetHandle",
-                             value);
-    }
-
-    value = g_slice_new0 (GValue);
-    g_value_init (value, G_TYPE_UINT);
-    g_value_set_uint (value, req->channel_handle_type);
-    g_hash_table_insert (properties, TP_IFACE_CHANNEL ".TargetHandleType",
-                         value);
-
-    channel = mcd_channel_new_request (properties);
-    g_object_set ((GObject *)channel,
-                  "requestor-serial", req->requestor_serial,
-                  "requestor-client-id", req->requestor_client_id,
-                  NULL);
-    g_signal_connect (channel, "status-changed",
-                      G_CALLBACK (on_channel_status_changed), account);
-
-    return _mcd_account_online_request (account,
-                                        process_channel_request,
-                                        channel,
-                                        error);
+    return _mcd_account_compat_request_channel_nmc4 (account, req, error);
 }
 
 GKeyFile *
diff --git a/src/mcd-account.h b/src/mcd-account.h
index f80025e..8a85ead 100644
--- a/src/mcd-account.h
+++ b/src/mcd-account.h
@@ -127,9 +127,10 @@ TpConnectionStatusReason mcd_account_get_connection_status_reason (McdAccount *a
 
 McdConnection *mcd_account_get_connection (McdAccount *account);
 
+struct mcd_channel_request;
 gboolean mcd_account_request_channel_nmc4 (McdAccount *account,
 					   const struct mcd_channel_request *req,
-					   GError **error);
+                                           GError **error) G_GNUC_DEPRECATED;
 
 gchar *mcd_account_get_avatar_filename (McdAccount *account);
 
diff --git a/src/mcd-channel.h b/src/mcd-channel.h
index 7278822..0bb9102 100644
--- a/src/mcd-channel.h
+++ b/src/mcd-channel.h
@@ -72,17 +72,6 @@ struct _McdChannelClass
     void (*members_accepted_signal) (McdChannel *channel);
 };
 
-struct mcd_channel_request
-{
-    const gchar *account_name;
-    const gchar *channel_type;
-    guint channel_handle;
-    const gchar *channel_handle_string;
-    gint channel_handle_type;
-    guint requestor_serial;
-    const gchar *requestor_client_id;
-};
-
 GType mcd_channel_get_type (void);
 
 McdChannel *mcd_channel_new (TpChannel *channel,
diff --git a/src/mcd-master.c b/src/mcd-master.c
index 7923c87..9fdffd6 100644
--- a/src/mcd-master.c
+++ b/src/mcd-master.c
@@ -62,6 +62,7 @@
 #include "mcd-dispatcher.h"
 #include "mcd-account-manager.h"
 #include "mcd-account-conditions.h"
+#include "mcd-account-compat.h"
 #include "mcd-plugin.h"
 #include "mcd-transport.h"
 #include "mcd-account-connection.h"
@@ -950,7 +951,7 @@ mcd_master_request_channel (McdMaster *master,
 	}
 	return FALSE;
     }
-    return mcd_account_request_channel_nmc4 (account, req, error);
+    return _mcd_account_compat_request_channel_nmc4 (account, req, error);
 }
 
 gboolean
diff --git a/src/mcd-misc.c b/src/mcd-misc.c
index 65af958..1d13334 100644
--- a/src/mcd-misc.c
+++ b/src/mcd-misc.c
@@ -87,4 +87,11 @@ _mcd_xdg_data_subdir_foreach (const gchar *subdir,
     }
 }
 
+void
+_mcd_prop_value_free (gpointer data)
+{
+  GValue *value = (GValue *) data;
+  g_value_unset (value);
+  g_slice_free (GValue, value);
+}
 
diff --git a/src/mcd-misc.h b/src/mcd-misc.h
index cfbda68..419b29b 100644
--- a/src/mcd-misc.h
+++ b/src/mcd-misc.h
@@ -27,6 +27,7 @@
 #define MCD_MISC_H
 
 #include <glib.h>
+#include <glib-object.h>
 
 G_BEGIN_DECLS
 
@@ -37,5 +38,7 @@ void _mcd_xdg_data_subdir_foreach (const gchar *subdir,
                                    McdXdgDataSubdirFunc callback,
                                    gpointer user_data);
 
+void _mcd_prop_value_free (gpointer data);
+
 G_END_DECLS
 #endif /* MCD_MISC_H */
diff --git a/src/mcd-service.c b/src/mcd-service.c
index 8b0a9f4..1c9a012 100644
--- a/src/mcd-service.c
+++ b/src/mcd-service.c
@@ -52,6 +52,7 @@
 #include "mcd-signals-marshal.h"
 #include "mcd-dispatcher.h"
 #include "mcd-dispatcher-context.h"
+#include "mcd-account-compat.h"
 #include "mcd-connection.h"
 #include "mcd-service.h"
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list