[Telepathy-commits] [telepathy-gabble/master] Implements OfferStreamTube on org.freedesktop.Telepathy.Channel.Type.StreamTube

Alban Crequy alban.crequy at collabora.co.uk
Mon Nov 3 11:20:59 PST 2008


---
 src/tube-stream.c |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/src/tube-stream.c b/src/tube-stream.c
index 32ec950..6b094b8 100644
--- a/src/tube-stream.c
+++ b/src/tube-stream.c
@@ -1871,6 +1871,21 @@ gboolean gabble_tube_stream_offer (GabbleTubeStream *self,
   return result;
 }
 
+/* Callback plugged only if the tube has been offered with the new
+ * Channel.Type.StreamTube API. */
+static void
+stream_unix_tube_new_connection_cb (GabbleTubeStream *self,
+                                    guint contact,
+                                    gpointer user_data)
+{
+  GabbleTubeStreamPrivate *priv = GABBLE_TUBE_STREAM_GET_PRIVATE (self);
+
+  tp_svc_channel_type_tubes_emit_stream_tube_new_connection (self,
+      priv->id, contact);
+  gabble_svc_channel_type_stream_tube_emit_stream_tube_new_connection (self,
+      contact);
+}
+
 
 /**
  * gabble_tube_stream_offer_stream_tube
@@ -1886,7 +1901,46 @@ gabble_tube_stream_offer_stream_tube (GabbleSvcChannelTypeStreamTube *iface,
                                       const GValue *access_control_param,
                                       DBusGMethodInvocation *context)
 {
-  tp_dbus_g_method_return_not_implemented (context);
+  GabbleTubeStream *self = GABBLE_TUBE_STREAM (iface);
+  GabbleTubeStreamPrivate *priv = GABBLE_TUBE_STREAM_GET_PRIVATE (self);
+  GError *error = NULL;
+
+  if (priv->state != GABBLE_TUBE_CHANNEL_STATE_NOT_OFFERED)
+    {
+      g_set_error (&error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+          "Tube is not in the not offered state");
+      dbus_g_method_return_error (context, error);
+      g_error_free (error);
+      return;
+    }
+
+  if (!gabble_tube_stream_check_params (address_type, address,
+        access_control, access_control_param, &error))
+    {
+      dbus_g_method_return_error (context, error);
+      g_error_free (error);
+      return;
+    }
+
+  if (priv->handle_type == TP_HANDLE_TYPE_CONTACT)
+    {
+      /* Stream initiation */
+      if (!gabble_tube_stream_offer (self, address_type,
+          address, access_control, access_control_param, &error))
+        {
+          gabble_tube_stream_close (GABBLE_TUBE_IFACE (self));
+
+          dbus_g_method_return_error (context, error);
+
+          g_error_free (error);
+          return;
+        }
+    }
+
+  g_signal_connect (self, "tube-new-connection",
+      G_CALLBACK (stream_unix_tube_new_connection_cb), self);
+
+  gabble_svc_channel_type_stream_tube_return_from_offer_stream_tube (context);
 }
 
 /**
-- 
1.5.6.5




More information about the Telepathy-commits mailing list