[Telepathy-commits] [telepathy-gabble/master] GabbleTubeStream: implements D-Bus property o.f.T.Channel.Type.StreamTube.SupportedSocketTypes. Add a basic test for it.

Alban Crequy alban.crequy at collabora.co.uk
Tue Oct 28 06:11:25 PDT 2008


---
 src/tube-stream.c                    |   69 +++++++++++++++++++++++++++++++++-
 src/tube-stream.h                    |    2 +
 src/tubes-channel.c                  |   33 +---------------
 tests/twisted/tubes/test-si-tubes.py |   10 +++++
 4 files changed, 82 insertions(+), 32 deletions(-)

diff --git a/src/tube-stream.c b/src/tube-stream.c
index 47eefc4..1df4c07 100644
--- a/src/tube-stream.c
+++ b/src/tube-stream.c
@@ -129,6 +129,7 @@ enum
   PROP_TARGET_ID,
   PROP_INITIATOR_HANDLE,
   PROP_INITIATOR_ID,
+  PROP_SUPPORTED_SOCKET_TYPES,
   LAST_PROPERTY
 };
 
@@ -1080,6 +1081,10 @@ gabble_tube_stream_get_property (GObject *object,
                 tp_handle_inspect (repo, priv->handle));
           }
         break;
+      case PROP_SUPPORTED_SOCKET_TYPES:
+        g_value_set_boxed (value,
+            gabble_tube_stream_get_supported_socket_types ());
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -1259,7 +1264,7 @@ gabble_tube_stream_class_init (GabbleTubeStreamClass *gabble_tube_stream_class)
   };
   static TpDBusPropertiesMixinPropImpl stream_tube_props[] = {
       { "Service", "service", NULL },
-      /*{ "AvailableStreamTubeTypes", NULL, NULL },*/
+      { "SupportedSocketTypes", "supported-socket-types", NULL },
       { NULL }
   };
   static TpDBusPropertiesMixinPropImpl tube_iface_props[] = {
@@ -1326,6 +1331,16 @@ gabble_tube_stream_class_init (GabbleTubeStreamClass *gabble_tube_stream_class)
   g_object_class_override_property (object_class, PROP_CHANNEL_PROPERTIES,
       "channel-properties");
 
+  param_spec = g_param_spec_boxed (
+      "supported-socket-types",
+      "Supported socket types",
+      "GHashTable containing supported socket types.",
+      dbus_g_type_get_map ("GHashTable", G_TYPE_UINT, DBUS_TYPE_G_UINT_ARRAY),
+      G_PARAM_READABLE |
+      G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_SUPPORTED_SOCKET_TYPES,
+      param_spec);
+
   param_spec = g_param_spec_uint (
       "address-type",
       "address type",
@@ -1904,6 +1919,58 @@ gabble_tube_stream_offer (GabbleTubeStream *self,
   return result;
 }
 
+static void
+destroy_socket_control_list (gpointer data)
+{
+  GArray *tab = data;
+  g_array_free (tab, TRUE);
+}
+
+/**
+ * gabble_tube_stream_get_supported_socket_types
+ *
+ * Used to implement D-Bus property
+ * org.freedesktop.Telepathy.Channel.Type.StreamTube.SupportedSocketTypes
+ * and D-Bus method GetAvailableStreamTubeTypes
+ * on org.freedesktop.Telepathy.Channel.Type.Tubes
+ */
+GHashTable *
+gabble_tube_stream_get_supported_socket_types (void)
+{
+  GHashTable *ret;
+  GArray *unix_tab, *ipv4_tab, *ipv6_tab;
+  TpSocketAccessControl access_control;
+
+  ret = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
+      destroy_socket_control_list);
+
+  /* Socket_Address_Type_Unix */
+  unix_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl),
+      1);
+  access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
+  g_array_append_val (unix_tab, access_control);
+  g_hash_table_insert (ret, GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_UNIX),
+      unix_tab);
+
+  /* Socket_Address_Type_IPv4 */
+  ipv4_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl),
+      1);
+  access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
+  g_array_append_val (ipv4_tab, access_control);
+  g_hash_table_insert (ret, GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_IPV4),
+      ipv4_tab);
+
+  /* Socket_Address_Type_IPv6 */
+  ipv6_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl),
+      1);
+  access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
+  g_array_append_val (ipv6_tab, access_control);
+  g_hash_table_insert (ret, GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_IPV6),
+      ipv6_tab);
+
+  return ret;
+}
+
 /* Callback plugged only if the tube has been offered with the new
  * Channel.Type.StreamTube API. */
 static void
diff --git a/src/tube-stream.h b/src/tube-stream.h
index b873e3a..6d32a4e 100644
--- a/src/tube-stream.h
+++ b/src/tube-stream.h
@@ -76,6 +76,8 @@ gboolean gabble_tube_stream_offer (GabbleTubeStream *self, guint address_type,
     const GValue *address, guint access_control,
     const GValue *access_control_param, GError **error);
 
+GHashTable *gabble_tube_stream_get_supported_socket_types (void);
+
 G_END_DECLS
 
 #endif /* #ifndef __GABBLE_TUBE_STREAM_H__ */
diff --git a/src/tubes-channel.c b/src/tubes-channel.c
index cc8a941..b8d8e48 100644
--- a/src/tubes-channel.c
+++ b/src/tubes-channel.c
@@ -2246,41 +2246,12 @@ gabble_tubes_channel_get_available_stream_tube_types (TpSvcChannelTypeTubes *ifa
                                                       DBusGMethodInvocation *context)
 {
   GHashTable *ret;
-  GArray *unix_tab, *ipv4_tab, *ipv6_tab;
-  TpSocketAccessControl access_control;
-
-  ret = g_hash_table_new (g_direct_hash, g_direct_equal);
-
-  /* Socket_Address_Type_Unix */
-  unix_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl),
-      1);
-  access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
-  g_array_append_val (unix_tab, access_control);
-  g_hash_table_insert (ret, GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_UNIX),
-      unix_tab);
-
-  /* Socket_Address_Type_IPv4 */
-  ipv4_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl),
-      1);
-  access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
-  g_array_append_val (ipv4_tab, access_control);
-  g_hash_table_insert (ret, GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_IPV4),
-      ipv4_tab);
-
-  /* Socket_Address_Type_IPv6 */
-  ipv6_tab = g_array_sized_new (FALSE, FALSE, sizeof (TpSocketAccessControl),
-      1);
-  access_control = TP_SOCKET_ACCESS_CONTROL_LOCALHOST;
-  g_array_append_val (ipv6_tab, access_control);
-  g_hash_table_insert (ret, GUINT_TO_POINTER (TP_SOCKET_ADDRESS_TYPE_IPV6),
-      ipv6_tab);
+
+  ret = gabble_tube_stream_get_supported_socket_types ();
 
   tp_svc_channel_type_tubes_return_from_get_available_stream_tube_types (
       context, ret);
 
-  g_array_free (unix_tab, TRUE);
-  g_array_free (ipv4_tab, TRUE);
-  g_array_free (ipv6_tab, TRUE);
   g_hash_table_destroy (ret);
 }
 
diff --git a/tests/twisted/tubes/test-si-tubes.py b/tests/twisted/tubes/test-si-tubes.py
index b87eaef..4a07f7d 100644
--- a/tests/twisted/tubes/test-si-tubes.py
+++ b/tests/twisted/tubes/test-si-tubes.py
@@ -113,6 +113,7 @@ def check_channel_properties(q, bus, conn, stream, channel, channel_type,
     if channel_type == "Tubes":
         assert state is None
         assert len(channel_props['Interfaces']) == 0, channel_props['Interfaces']
+        supported_socket_types = channel.GetAvailableStreamTubeTypes()
     else:
         assert state is not None
         tube_props = channel.GetAll(
@@ -126,6 +127,15 @@ def check_channel_properties(q, bus, conn, stream, channel, channel_type,
                     signature='s'), \
             channel_props['Interfaces']
 
+        stream_tube_props = channel.GetAll(
+                'org.freedesktop.Telepathy.Channel.Type.StreamTube.DRAFT',
+                dbus_interface='org.freedesktop.DBus.Properties')
+        supported_socket_types = stream_tube_props['SupportedSocketTypes']
+
+    # Support for different socket types. no strict check but at least check
+    # there is some support.
+    assert len(supported_socket_types) == 3
+
 def check_NewChannel_signal(old_sig, channel_type, chan_path, contact_handle):
     assert old_sig[0] == chan_path
     assert old_sig[1] == tp_name_prefix + '.Channel.Type.' + channel_type
-- 
1.5.6.5




More information about the Telepathy-commits mailing list