[Telepathy-commits] [telepathy-mission-control/master] Don't use TpChannel from McdConnection
Alberto Mardegan
alberto.mardegan at nokia.com
Mon Nov 17 00:05:17 PST 2008
Move the code that deals with TpChannel inside McdChannel only.
---
src/mcd-channel.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/mcd-channel.h | 7 ++++
src/mcd-connection.c | 56 ++++++++---------------------------
3 files changed, 98 insertions(+), 43 deletions(-)
diff --git a/src/mcd-channel.c b/src/mcd-channel.c
index 363e8bc..9db4629 100644
--- a/src/mcd-channel.c
+++ b/src/mcd-channel.c
@@ -799,6 +799,84 @@ mcd_channel_new (TpChannel * tp_chan,
return obj;
}
+/**
+ * mcd_channel_new_from_path:
+ * @connection: the #TpConnection on which the channel exists.
+ * @object_path: the D-Bus object path of an existing channel.
+ * @type: the channel type.
+ * @handle: the channel handle.
+ * @handle_type: the #TpHandleType.
+ *
+ * Creates a #McdChannel with an associated #TpChannel proxy for the channel
+ * located at @object_path.
+ *
+ * Returns: a new #McdChannel if the #TpChannel was created successfully, %NULL
+ * otherwise.
+ */
+McdChannel *
+mcd_channel_new_from_path (TpConnection *connection, const gchar *object_path,
+ const gchar *type, guint handle,
+ TpHandleType handle_type)
+{
+ McdChannel *channel;
+ channel = g_object_new (MCD_TYPE_CHANNEL,
+ "channel-type", type,
+ "channel-handle", handle,
+ "channel-handle-type", handle_type,
+ NULL);
+ if (mcd_channel_set_object_path (channel, connection, object_path))
+ return channel;
+ else
+ {
+ g_object_unref (channel);
+ return NULL;
+ }
+}
+
+/**
+ * mcd_channel_set_object_path:
+ * @channel: the #McdChannel.
+ * @connection: the #TpConnection on which the channel exists.
+ * @object_path: the D-Bus object path of an existing channel.
+ *
+ * This method makes @channel create a #TpChannel object for @object_path.
+ * It must not be called it @channel has already a #TpChannel associated with
+ * it.
+ *
+ * Returns: %TRUE if the #TpChannel has been created, %FALSE otherwise.
+ */
+gboolean
+mcd_channel_set_object_path (McdChannel *channel, TpConnection *connection,
+ const gchar *object_path)
+{
+ McdChannelPrivate *priv;
+ GError *error = NULL;
+
+ g_return_val_if_fail (MCD_IS_CHANNEL (channel), FALSE);
+ priv = channel->priv;
+
+ g_return_val_if_fail (priv->tp_chan == NULL, FALSE);
+ priv->tp_chan = tp_channel_new (connection, object_path,
+ priv->channel_type,
+ priv->channel_handle_type,
+ priv->channel_handle,
+ &error);
+ if (error)
+ {
+ g_warning ("%s: tp_channel_new returned error: %s",
+ G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
+ if (priv->tp_chan)
+ {
+ _mcd_channel_setup (channel, priv);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
void
mcd_channel_set_status (McdChannel *channel, McdChannelStatus status)
{
diff --git a/src/mcd-channel.h b/src/mcd-channel.h
index e4619df..ff38dfe 100644
--- a/src/mcd-channel.h
+++ b/src/mcd-channel.h
@@ -90,6 +90,13 @@ McdChannel *mcd_channel_new (TpChannel *channel,
gboolean outgoing,
guint requestor_serial,
const gchar *requestor_client_id);
+McdChannel *mcd_channel_new_from_path (TpConnection *connection,
+ const gchar *object_path,
+ const gchar *type, guint handle,
+ TpHandleType handle_type);
+gboolean mcd_channel_set_object_path (McdChannel *channel,
+ TpConnection *connection,
+ const gchar *object_path);
void mcd_channel_set_status (McdChannel *channel, McdChannelStatus status);
McdChannelStatus mcd_channel_get_status (McdChannel * channel);
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 7d10f66..3a87ed6 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -569,33 +569,19 @@ on_new_channel (TpConnection *proxy, const gchar *chan_obj_path,
{
McdConnection *connection = MCD_CONNECTION (weak_object);
McdConnectionPrivate *priv = user_data;
- TpChannel *tp_chan;
McdChannel *channel;
- GError *error = NULL;
-
+
/* ignore all our own requests (they have always suppress_handler = 1) as
* well as other requests for which our intervention has not been requested
* */
if (suppress_handler) return;
-
- tp_chan = tp_channel_new (priv->tp_conn, chan_obj_path, chan_type,
- handle_type, handle, &error);
- if (error)
- {
- g_warning ("%s: tp_channel_new returned error: %s",
- G_STRFUNC, error->message);
- g_error_free (error);
- return;
- }
/* It's an incoming channel, so we create a new McdChannel for it */
- channel = mcd_channel_new (tp_chan,
- chan_type,
- handle,
- handle_type,
- FALSE, /* incoming */
- 0, 0); /* There is no requestor, obviously */
-
+ channel = mcd_channel_new_from_path (proxy,
+ chan_obj_path,
+ chan_type, handle, handle_type);
+ if (G_UNLIKELY (!channel)) return;
+
mcd_operation_take_mission (MCD_OPERATION (connection),
MCD_MISSION (channel));
@@ -604,8 +590,6 @@ on_new_channel (TpConnection *proxy, const gchar *chan_obj_path,
/* Dispatch the incoming channel */
mcd_dispatcher_send (priv->dispatcher, channel);
-
- g_object_unref (tp_chan);
}
static void
@@ -1861,12 +1845,11 @@ request_channel_cb (TpConnection *proxy, const gchar *channel_path,
McdChannel *channel = MCD_CHANNEL (weak_object);
McdConnection *connection = user_data;
McdConnectionPrivate *priv = connection->priv;
- GError *error_on_creation, *error = NULL;
+ GError *error_on_creation;
struct capabilities_wait_data *cwd;
GQuark chan_type;
TpHandleType chan_handle_type;
guint chan_handle;
- TpChannel *tp_chan;
/* We handle only the dbus errors */
/* ChannelRequestor *chan_req = (ChannelRequestor *)user_data; */
@@ -1933,7 +1916,9 @@ request_channel_cb (TpConnection *proxy, const gchar *channel_path,
}
return;
}
-
+
+ priv->pending_channels = g_list_remove (priv->pending_channels,
+ channel);
if (channel_path == NULL)
{
GError *mc_error;
@@ -1950,29 +1935,16 @@ request_channel_cb (TpConnection *proxy, const gchar *channel_path,
* reference to this temporary channel.
*/
g_object_unref (channel);
- priv->pending_channels = g_list_remove (priv->pending_channels,
- channel);
return;
}
/* Everything here is well and fine. We can create the channel. */
- tp_chan = tp_channel_new (priv->tp_conn, channel_path,
- g_quark_to_string (chan_type),
- chan_handle_type, chan_handle, &error);
- if (error)
+ if (!mcd_channel_set_object_path (channel, priv->tp_conn, channel_path))
{
- g_warning ("%s: tp_channel_new returned error: %s",
- G_STRFUNC, error->message);
- g_error_free (error);
- return;
+ g_object_unref (channel);
+ return;
}
- g_object_set (channel,
- "tp-channel", tp_chan,
- NULL);
-
- /* The channel is no longer pending */
- priv->pending_channels = g_list_remove (priv->pending_channels, channel);
mcd_operation_take_mission (MCD_OPERATION (connection),
MCD_MISSION (channel));
@@ -1981,8 +1953,6 @@ request_channel_cb (TpConnection *proxy, const gchar *channel_path,
/* Dispatch the incoming channel */
mcd_dispatcher_send (priv->dispatcher, channel);
-
- g_object_unref (tp_chan);
}
static void
--
1.5.6.5
More information about the Telepathy-commits
mailing list