[Telepathy-commits] [telepathy-mission-control/master] Don't duplicate the channel_request struct

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


Instead of duplicating the channel_request struct, instantiate the McdChannel
earlier, and set the desired properties on it.
---
 src/mcd-account.c    |   37 +++++++++++++++----------------------
 src/mcd-channel.c    |   26 ++++++++++++++++++++++++++
 src/mcd-channel.h    |    4 ++++
 src/mcd-connection.c |   43 +++++++++++++++++++++----------------------
 src/mcd-connection.h |    2 +-
 5 files changed, 67 insertions(+), 45 deletions(-)

diff --git a/src/mcd-account.c b/src/mcd-account.c
index 5d98f98..7bbebbe 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -2121,36 +2121,25 @@ mcd_account_online_request (McdAccount *account,
 }
 
 static void
-requested_channel_free (struct mcd_channel_request *req)
-{
-    g_free ((gchar *)req->account_name);
-    g_free ((gchar *)req->channel_type);
-    g_free ((gchar *)req->channel_handle_string);
-    g_free ((gchar *)req->requestor_client_id);
-    g_free (req);
-}
-
-static void
 process_channel_request (McdAccount *account, gpointer userdata,
 			 const GError *error)
 {
     McdAccountPrivate *priv = MCD_ACCOUNT_PRIV (account);
-    struct mcd_channel_request *req = userdata;
+    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 */
-	requested_channel_free (req);
+        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, req, &err);
-    requested_channel_free (req);
+    mcd_connection_request_channel (priv->connection, channel, &err);
 }
 
 gboolean
@@ -2158,18 +2147,22 @@ mcd_account_request_channel_nmc4 (McdAccount *account,
 				  const struct mcd_channel_request *req,
 				  GError **error)
 {
-    struct mcd_channel_request *req_cp;
+    McdChannel *channel;
 
-    req_cp = g_malloc (sizeof (struct mcd_channel_request));
-    memcpy(req_cp, req, sizeof (struct mcd_channel_request));
-    req_cp->account_name = g_strdup (req->account_name);
-    req_cp->channel_type = g_strdup (req->channel_type);
-    req_cp->channel_handle_string = g_strdup (req->channel_handle_string);
-    req_cp->requestor_client_id = g_strdup (req->requestor_client_id);
+    /* The channel is temporary */
+    channel = mcd_channel_new (NULL,
+			       req->channel_type,
+			       req->channel_handle,
+			       req->channel_handle_type,
+			       TRUE, /* outgoing */
+			       req->requestor_serial,
+			       req->requestor_client_id);
+    _mcd_channel_set_target_id (channel, req->channel_handle_string);
+    mcd_channel_set_status (channel, MCD_CHANNEL_NO_PROXY);
 
     return mcd_account_online_request (account,
 				       process_channel_request,
-				       req_cp,
+				       channel,
 				       error);
 }
 
diff --git a/src/mcd-channel.c b/src/mcd-channel.c
index 23bffdf..15d945a 100644
--- a/src/mcd-channel.c
+++ b/src/mcd-channel.c
@@ -1144,4 +1144,30 @@ _mcd_channel_details_free (GPtrArray *channels)
     g_value_unset (&value);
 }
 
+/*
+ * _mcd_channel_set_target_id:
+ * @channel: the #McdChannel.
+ * @target_id: string representing target contact.
+ */
+void
+_mcd_channel_set_target_id (McdChannel *channel,
+                            const gchar *target_id)
+{
+    g_return_if_fail (MCD_IS_CHANNEL (channel));
+    g_object_set_data_full ((GObject *)channel, "TargetID",
+                            g_strdup (target_id), g_free);
+}
+
+/*
+ * _mcd_channel_get_target_id:
+ * @channel: the #McdChannel.
+ *
+ * Returns: string representing the target contact, or %NULL.
+ */
+const gchar *
+_mcd_channel_get_target_id (McdChannel *channel)
+{
+    g_return_val_if_fail (MCD_IS_CHANNEL (channel), NULL);
+    return g_object_get_data ((GObject *)channel, "TargetID");
+}
 
diff --git a/src/mcd-channel.h b/src/mcd-channel.h
index fa96572..4268d2f 100644
--- a/src/mcd-channel.h
+++ b/src/mcd-channel.h
@@ -126,5 +126,9 @@ GHashTable *_mcd_channel_get_immutable_properties (McdChannel *channel);
 GPtrArray *_mcd_channel_details_build_from_list (GList *channels);
 void _mcd_channel_details_free (GPtrArray *channels);
 
+void _mcd_channel_set_target_id (McdChannel *channel,
+                                 const gchar *target_id);
+const gchar *_mcd_channel_get_target_id (McdChannel *channel);
+
 G_END_DECLS
 #endif /* MCD_CHANNEL_H */
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 3b727e7..4f7efab 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -2206,39 +2206,35 @@ request_handles_cb (TpConnection *proxy, const GArray *handles,
 
 gboolean
 mcd_connection_request_channel (McdConnection *connection,
-				const struct mcd_channel_request *req,
+                                McdChannel *channel,
 			       	GError ** error)
 {
-    McdChannel *channel;
     McdConnectionPrivate *priv = MCD_CONNECTION_PRIV (connection);
-    
+    guint channel_handle, channel_handle_type;
+
     g_return_val_if_fail (priv->tp_conn != NULL, FALSE);
     g_return_val_if_fail (TP_IS_CONNECTION (priv->tp_conn), FALSE);
-    
-    /* The channel is temporary */
-    channel = mcd_channel_new (NULL,
-			       req->channel_type,
-			       req->channel_handle,
-			       req->channel_handle_type,
-			       TRUE, /* outgoing */
-			       req->requestor_serial,
-			       req->requestor_client_id);
-    mcd_channel_set_status (channel, MCD_CHANNEL_NO_PROXY);
+    g_return_val_if_fail (MCD_IS_CHANNEL (channel), FALSE);
 
     /* We do not add the channel in connection until tp_channel is created */
     g_object_set_data (G_OBJECT (channel), "temporary_connection", connection);
-    
-    if (req->channel_handle != 0 || req->channel_handle_type == 0)
+
+    channel_handle_type = mcd_channel_get_handle_type (channel);
+    channel_handle = mcd_channel_get_handle (channel);
+
+    if (channel_handle != 0 || channel_handle_type == 0)
     {
 	TpProxyPendingCall *call;
+        const gchar *channel_type;
 
         mcd_operation_take_mission (MCD_OPERATION (connection),
                                     MCD_MISSION (channel));
 
+        channel_type = mcd_channel_get_channel_type (channel);
 	call = tp_cli_connection_call_request_channel (priv->tp_conn, -1,
-						       req->channel_type,
-						       req->channel_handle_type,
-						       req->channel_handle, TRUE,
+                                                       channel_type,
+                                                       channel_handle_type,
+                                                       channel_handle, TRUE,
 						       request_channel_cb,
 						       connection, NULL,
 						       (GObject *)channel);
@@ -2249,16 +2245,19 @@ mcd_connection_request_channel (McdConnection *connection,
 	/* if channel handle is 0, this means that the channel was requested by
 	 * a string handle; in that case, we must first request a channel
 	 * handle for it */
-	const gchar *name_array[2];
-	g_return_val_if_fail (req->channel_handle_string != NULL, FALSE);
+        const gchar *name_array[2], *target_id;
+
+        target_id = _mcd_channel_get_target_id (channel);
+        g_return_val_if_fail (target_id != NULL, FALSE);
+        g_return_val_if_fail (channel_handle_type != 0, FALSE);
 
-	name_array[0] = req->channel_handle_string;
+        name_array[0] = target_id;
 	name_array[1] = NULL;
 
 	/* Channel is temporary and will be added as a child mission
 	 * only when we successfully resolve the handle. */
 	tp_cli_connection_call_request_handles (priv->tp_conn, -1,
-						req->channel_handle_type,
+                                                channel_handle_type,
 						name_array,
 						request_handles_cb,
 						connection, NULL,
diff --git a/src/mcd-connection.h b/src/mcd-connection.h
index fbfd7b1..9ced972 100644
--- a/src/mcd-connection.h
+++ b/src/mcd-connection.h
@@ -74,7 +74,7 @@ TpConnectionStatus mcd_connection_get_connection_status (McdConnection *connecti
 TpConnectionStatusReason mcd_connection_get_connection_status_reason (McdConnection *connection);
 
 gboolean mcd_connection_request_channel (McdConnection *connection,
-					 const struct mcd_channel_request *req,
+					 McdChannel *channel,
 					 GError ** error);
 
 gboolean mcd_connection_cancel_channel_request (McdConnection *connection,
-- 
1.5.6.5




More information about the Telepathy-commits mailing list