[Telepathy-commits] [telepathy-gabble/master] gabble_media_channel_request_streams: lazily create a session if necessary (also simplify error handling)

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Aug 19 10:51:56 PDT 2008


20080430153959-53eee-dd8be2453c6882a1880e7cb8b27d75eb60562889.gz
---
 src/gabble-media-channel.c |   49 +++++++++++++++++++++++++++++++------------
 1 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/src/gabble-media-channel.c b/src/gabble-media-channel.c
index f036fa3..4e01b75 100644
--- a/src/gabble-media-channel.c
+++ b/src/gabble-media-channel.c
@@ -1048,32 +1048,48 @@ gabble_media_channel_request_streams (TpSvcChannelTypeStreamedMedia *iface,
       TP_HANDLE_TYPE_CONTACT);
 
   if (!tp_handle_is_valid (contact_handles, contact_handle, &error))
-    {
-      dbus_g_method_return_error (context, error);
-      g_error_free (error);
-      return;
-    }
+    goto error;
 
   if (!tp_handle_set_is_member (self->group.members, contact_handle) &&
       !tp_handle_set_is_member (self->group.remote_pending, contact_handle))
     {
       g_set_error (&error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
           "given handle %u is not a member of the channel", contact_handle);
-      dbus_g_method_return_error (context, error);
-      g_error_free (error);
-      return;
+      goto error;
+    }
+
+  if (priv->session == NULL)
+    {
+      if (create_session (self, contact_handle, NULL, NULL, &error)
+          == NULL)
+        {
+          dbus_g_method_return_error (context, error);
+          g_error_free (error);
+          return;
+        }
+    }
+  else
+    {
+      TpHandle peer;
+
+      g_object_get (priv->session,
+          "peer", &peer,
+          NULL);
+
+      if (peer != handle)
+        {
+          g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+              "cannot add streams for %u: this channel's peer is %u",
+              handle, peer);
+          goto error;
+        }
     }
 
-  /* if the person is a channel member, we should have a session */
   g_assert (priv->session != NULL);
 
   if (!_gabble_media_session_request_streams (priv->session, types, &streams,
         &error))
-    {
-      dbus_g_method_return_error (context, error);
-      g_error_free (error);
-      return;
-    }
+    goto error;
 
   ret = make_stream_list (self, streams);
 
@@ -1081,6 +1097,11 @@ gabble_media_channel_request_streams (TpSvcChannelTypeStreamedMedia *iface,
 
   tp_svc_channel_type_streamed_media_return_from_request_streams (context, ret);
   g_ptr_array_free (ret, TRUE);
+  return;
+
+error:
+  dbus_g_method_return_error (context, error);
+  g_error_free (error);
 }
 
 
-- 
1.5.6.3




More information about the Telepathy-commits mailing list