[Telepathy-commits] [telepathy-mission-control/master] Call HandleChannels with all channel properties

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


Have mcd_connection_request_channel() invoke different functions for invoking
the old RequestChannel or the new CreateChannel based on the availability of
the Requests interface on the connection.
In case the new interface is used, store the channel immutable properties, so
that they will be passed to the handler.
---
 src/mcd-channel.c    |   17 +++++++++
 src/mcd-channel.h    |    1 +
 src/mcd-connection.c |   93 +++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 95 insertions(+), 16 deletions(-)

diff --git a/src/mcd-channel.c b/src/mcd-channel.c
index 8ece97a..b1c2ede 100644
--- a/src/mcd-channel.c
+++ b/src/mcd-channel.c
@@ -1269,3 +1269,20 @@ mcd_channel_new_request (GHashTable *properties, guint64 user_time,
     return channel;
 }
 
+/*
+ * _mcd_channel_get_requested_properties:
+ * @channel: the #McdChannel.
+ *
+ * Returns: #GHashTable of requested properties.
+ */
+GHashTable *
+_mcd_channel_get_requested_properties (McdChannel *channel)
+{
+    McdChannelRequestData *crd;
+
+    g_return_val_if_fail (MCD_IS_CHANNEL (channel), NULL);
+    crd = g_object_get_data ((GObject *)channel, CD_REQUEST);
+    if (G_UNLIKELY (!crd)) return NULL;
+    return crd->properties;
+}
+
diff --git a/src/mcd-channel.h b/src/mcd-channel.h
index feb84af..adc7d04 100644
--- a/src/mcd-channel.h
+++ b/src/mcd-channel.h
@@ -121,6 +121,7 @@ GPtrArray *_mcd_channel_details_build_from_list (GList *channels);
 void _mcd_channel_details_free (GPtrArray *channels);
 
 const gchar *_mcd_channel_get_target_id (McdChannel *channel);
+GHashTable *_mcd_channel_get_requested_properties (McdChannel *channel);
 
 void _mcd_channel_set_error (McdChannel *channel, GError *error);
 const GError *_mcd_channel_get_error (McdChannel *channel);
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 7636d36..f15c552 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -55,6 +55,7 @@
 #include "mcd-connection.h"
 #include "mcd-channel.h"
 #include "mcd-provisioning-factory.h"
+#include "mcd-misc.h"
 
 #define MAX_REF_PRESENCE 4
 #define LAST_MC_PRESENCE (TP_CONNECTION_PRESENCE_TYPE_BUSY + 1)
@@ -2199,29 +2200,61 @@ request_handles_cb (TpConnection *proxy, const GArray *handles,
     mcd_connection_request_channel (connection, channel);
 }
 
-gboolean
-mcd_connection_request_channel (McdConnection *connection,
-                                McdChannel *channel)
+static void
+create_channel_cb (TpConnection *proxy, const gchar *channel_path,
+                   GHashTable *properties, const GError *error,
+                   gpointer user_data, GObject *weak_object)
 {
-    McdConnectionPrivate *priv = MCD_CONNECTION_PRIV (connection);
-    guint channel_handle, channel_handle_type;
+    McdChannel *channel = MCD_CHANNEL (weak_object);
+    McdConnection *connection = user_data;
+    McdConnectionPrivate *priv = connection->priv;
 
-    g_return_val_if_fail (priv->tp_conn != NULL, FALSE);
-    g_return_val_if_fail (TP_IS_CONNECTION (priv->tp_conn), FALSE);
-    g_return_val_if_fail (MCD_IS_CHANNEL (channel), FALSE);
+    if (error != NULL)
+    {
+        GError *mc_error;
 
-    if (!mcd_mission_get_parent ((McdMission *)channel))
-        mcd_operation_take_mission (MCD_OPERATION (connection),
-                                    MCD_MISSION (channel));
+        /* No special handling of "no capabilities" error: being confident that
+         * https://bugs.freedesktop.org/show_bug.cgi?id=15769 will be fixed
+         * soon :-) */
+        g_debug ("%s: Got error: %s", G_STRFUNC, error->message);
+        mc_error = map_tp_error_to_mc_error (channel, error);
+        _mcd_channel_set_error (channel, mc_error);
+        mcd_mission_abort ((McdMission *)channel);
+        return;
+    }
 
-    if (!tp_connection_is_ready (priv->tp_conn))
+    _mcd_channel_set_immutable_properties (channel,
+                                           _mcd_deepcopy_asv (properties));
+    /* Everything here is well and fine. We can create the channel. */
+    if (!mcd_channel_set_object_path (channel, priv->tp_conn, channel_path))
     {
-        /* don't request any channel until the connection is ready (because we
-         * don't know if the CM implements the Requests interface). The channel
-         * will be processed once the connection is ready */
-        return TRUE;
+        mcd_mission_abort ((McdMission *)channel);
+        return;
     }
 
+    /* Dispatch the incoming channel */
+    mcd_dispatcher_send (priv->dispatcher, channel);
+}
+
+static gboolean
+request_channel_new_iface (McdConnection *connection, McdChannel *channel)
+{
+    McdConnectionPrivate *priv = MCD_CONNECTION_PRIV (connection);
+    GHashTable *properties;
+
+    properties = _mcd_channel_get_requested_properties (channel);
+    tp_cli_connection_interface_requests_call_create_channel
+        (priv->tp_conn, -1, properties, create_channel_cb, connection, NULL,
+         (GObject *)channel);
+    return TRUE;
+}
+
+static gboolean
+request_channel_old_iface (McdConnection *connection, McdChannel *channel)
+{
+    McdConnectionPrivate *priv = MCD_CONNECTION_PRIV (connection);
+    guint channel_handle, channel_handle_type;
+
     channel_handle_type = mcd_channel_get_handle_type (channel);
     channel_handle = mcd_channel_get_handle (channel);
 
@@ -2267,6 +2300,34 @@ mcd_connection_request_channel (McdConnection *connection,
 }
 
 gboolean
+mcd_connection_request_channel (McdConnection *connection,
+                                McdChannel *channel)
+{
+    McdConnectionPrivate *priv = MCD_CONNECTION_PRIV (connection);
+
+    g_return_val_if_fail (priv->tp_conn != NULL, FALSE);
+    g_return_val_if_fail (TP_IS_CONNECTION (priv->tp_conn), FALSE);
+    g_return_val_if_fail (MCD_IS_CHANNEL (channel), FALSE);
+
+    if (!mcd_mission_get_parent ((McdMission *)channel))
+        mcd_operation_take_mission (MCD_OPERATION (connection),
+                                    MCD_MISSION (channel));
+
+    if (!tp_connection_is_ready (priv->tp_conn))
+    {
+        /* don't request any channel until the connection is ready (because we
+         * don't know if the CM implements the Requests interface). The channel
+         * will be processed once the connection is ready */
+        return TRUE;
+    }
+
+    if (priv->has_requests_if)
+        return request_channel_new_iface (connection, channel);
+    else
+        return request_channel_old_iface (connection, channel);
+}
+
+gboolean
 mcd_connection_cancel_channel_request (McdConnection *connection,
 				       guint operation_id,
 				       const gchar *requestor_client_id,
-- 
1.5.6.5




More information about the Telepathy-commits mailing list