[Telepathy-commits] [telepathy-gabble/master] Move responsibility for checking VoIP capabilities into create_session()

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


20080430151928-53eee-81bab7f32516ddd27b20d0fe418c06954093b8b3.gz
---
 src/gabble-media-channel.c |   74 ++++++++++++++++++++++---------------------
 1 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/src/gabble-media-channel.c b/src/gabble-media-channel.c
index 453e3b1..75a0b6f 100644
--- a/src/gabble-media-channel.c
+++ b/src/gabble-media-channel.c
@@ -241,7 +241,38 @@ create_session (GabbleMediaChannel *channel,
 
   if (sid == NULL)
     {
+      /* We are the initiator */
+      GabblePresence *presence;
+#ifdef ENABLE_DEBUG
+      TpBaseConnection *conn = (TpBaseConnection *) priv->conn;
+      TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (
+          conn, TP_HANDLE_TYPE_CONTACT);
+#endif
+
       initiator = INITIATOR_LOCAL;
+
+      presence = gabble_presence_cache_get (priv->conn->presence_cache, peer);
+
+      if (presence == NULL)
+        {
+          DEBUG ("failed to add contact %d (%s) to media channel: "
+              "no presence available", peer,
+              tp_handle_inspect (contact_handles, peer));
+          goto NO_CAPS;
+        }
+
+      if (!(presence->caps & PRESENCE_CAP_GOOGLE_VOICE ||
+            presence->caps & PRESENCE_CAP_JINGLE_DESCRIPTION_AUDIO ||
+            presence->caps & PRESENCE_CAP_JINGLE_DESCRIPTION_VIDEO))
+        {
+          DEBUG ("failed to add contact %d (%s) to media channel: "
+              "caps %x aren't sufficient", peer,
+              tp_handle_inspect (contact_handles, peer),
+              presence->caps);
+          goto NO_CAPS;
+        }
+
+
       sid = _gabble_media_factory_allocate_sid (priv->factory, channel);
     }
   else
@@ -277,6 +308,11 @@ create_session (GabbleMediaChannel *channel,
   g_free (object_path);
 
   return session;
+
+NO_CAPS:
+  g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+      "handle %u has no media capabilities", peer);
+  return NULL;
 }
 
 gboolean
@@ -1057,46 +1093,17 @@ _gabble_media_channel_add_member (GObject *obj,
   GabbleMediaChannel *chan = GABBLE_MEDIA_CHANNEL (obj);
   GabbleMediaChannelPrivate *priv = GABBLE_MEDIA_CHANNEL_GET_PRIVATE (chan);
   TpGroupMixin *mixin = TP_GROUP_MIXIN (obj);
-#ifdef ENABLE_DEBUG
-  TpBaseConnection *conn = (TpBaseConnection *)priv->conn;
-  TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (conn,
-      TP_HANDLE_TYPE_CONTACT);
-#endif
 
   /* did we create this channel? */
   if (priv->creator == mixin->self_handle)
     {
-      GabblePresence *presence;
       TpIntSet *set;
 
-      /* yes: check the peer's capabilities */
-
-      presence = gabble_presence_cache_get (priv->conn->presence_cache, handle);
-
-      if (presence == NULL)
-        {
-          DEBUG ("failed to add contact %d (%s) to media channel: "
-              "no presence available", handle,
-              tp_handle_inspect (contact_handles, handle));
-          goto NO_CAPS;
-        }
-
-      if (!(presence->caps & PRESENCE_CAP_GOOGLE_VOICE ||
-            presence->caps & PRESENCE_CAP_JINGLE_DESCRIPTION_AUDIO ||
-            presence->caps & PRESENCE_CAP_JINGLE_DESCRIPTION_VIDEO))
-        {
-          DEBUG ("failed to add contact %d (%s) to media channel: "
-              "caps %x aren't sufficient", handle,
-              tp_handle_inspect (contact_handles, handle),
-              presence->caps);
-          goto NO_CAPS;
-        }
-
       /* yes: invite the peer */
 
       /* create a new session */
-      create_session (chan, handle, NULL, NULL, NULL);
-      g_assert (priv->session != NULL);
+      if (create_session (chan, handle, NULL, NULL, error) == NULL)
+        return FALSE;
 
       /* make the peer remote pending */
       set = tp_intset_new ();
@@ -1149,11 +1156,6 @@ _gabble_media_channel_add_member (GObject *obj,
   g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
       "handle %u cannot be added in the current state", handle);
   return FALSE;
-
-NO_CAPS:
-  g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
-      "handle %u has no media capabilities", handle);
-  return FALSE;
 }
 
 static gboolean
-- 
1.5.6.3




More information about the Telepathy-commits mailing list