[Telepathy-commits] [telepathy-gabble/master] Fix "Parameters" property on Channel.Type.StreamTube

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


src/tube-stream.c: Implement a custom Set implementation for the
"Parameters" property

src/tubes-channel.c: OfferStreamTube on Channel.Type.StreamTube gives
the right "Parameters" property

tests/twisted/tubes/test-si-tubes.py: check that the "Parameters"
property is correctly given, can be changed, but not after the tube is
offered.
---
 src/tube-stream.c                    |   36 ++++++++++++++++-
 src/tubes-channel.c                  |   14 +++++-
 tests/twisted/tubes/test-si-tubes.py |   71 +++++++++++++++++++++++++---------
 3 files changed, 97 insertions(+), 24 deletions(-)

diff --git a/src/tube-stream.c b/src/tube-stream.c
index 5d4f102..350688e 100644
--- a/src/tube-stream.c
+++ b/src/tube-stream.c
@@ -1216,6 +1216,38 @@ gabble_tube_stream_constructor (GType type,
   return obj;
 }
 
+static gboolean
+tube_iface_props_setter (GObject *object,
+                         GQuark interface,
+                         GQuark name,
+                         const GValue *value,
+                         gpointer setter_data,
+                         GError **error)
+{
+  GabbleTubeStream *self = GABBLE_TUBE_STREAM (object);
+  GabbleTubeStreamPrivate *priv = GABBLE_TUBE_STREAM_GET_PRIVATE (self);
+
+  g_return_if_fail (interface ==
+      GABBLE_IFACE_QUARK_CHANNEL_INTERFACE_TUBE);
+
+  if (name != g_quark_from_static_string ("Parameters"))
+    {
+      g_object_set_property (object, setter_data, value);
+      return TRUE;
+    }
+
+  if (priv->state != GABBLE_TUBE_CHANNEL_STATE_NOT_OFFERED)
+  {
+    g_set_error (error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+        "Can change parameters only if the tube is not offered");
+    return FALSE;
+  }
+
+  priv->parameters = g_value_dup_boxed (value);
+
+  return TRUE;
+}
+
 static void
 gabble_tube_stream_class_init (GabbleTubeStreamClass *gabble_tube_stream_class)
 {
@@ -1240,7 +1272,7 @@ gabble_tube_stream_class_init (GabbleTubeStreamClass *gabble_tube_stream_class)
   };
   static TpDBusPropertiesMixinPropImpl tube_iface_props[] = {
       { "Initiator", "initiator", NULL },
-      { "Parameters", "parameters", NULL },
+      { "Parameters", "parameters", "parameters" },
       { "Status", "state", NULL },
       { NULL }
   };
@@ -1262,7 +1294,7 @@ gabble_tube_stream_class_init (GabbleTubeStreamClass *gabble_tube_stream_class)
       },
       { GABBLE_IFACE_CHANNEL_INTERFACE_TUBE,
         tp_dbus_properties_mixin_getter_gobject_properties,
-        NULL,
+        tube_iface_props_setter,
         tube_iface_props,
       },
       { NULL }
diff --git a/src/tubes-channel.c b/src/tubes-channel.c
index 98725e3..709c32f 100644
--- a/src/tubes-channel.c
+++ b/src/tubes-channel.c
@@ -1596,9 +1596,6 @@ GabbleTubeIface *gabble_tubes_channel_tube_request (GabbleTubesChannel *self,
 
   tube_id = generate_tube_id ();
 
-  parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
-      (GDestroyNotify) tp_g_value_slice_free);
-
   channel_type = tp_asv_get_string (request_properties,
             TP_IFACE_CHANNEL ".ChannelType");
 
@@ -1618,6 +1615,17 @@ GabbleTubeIface *gabble_tubes_channel_tube_request (GabbleTubesChannel *self,
   else
     g_assert_not_reached ();
 
+  parameters = tp_asv_get_boxed (request_properties,
+               GABBLE_IFACE_CHANNEL_INTERFACE_TUBE ".Parameters",
+               TP_HASH_TYPE_STRING_VARIANT_MAP);
+  if (parameters == NULL)
+    {
+      /* If it is not included in the request, the connection manager MUST
+       * consider the property to be empty. */
+      parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+          (GDestroyNotify) tp_g_value_slice_free);
+    }
+
   DEBUG ("Request a tube channel with type='%s' and service='%s'",
       channel_type, service);
 
diff --git a/tests/twisted/tubes/test-si-tubes.py b/tests/twisted/tubes/test-si-tubes.py
index 545aea0..23fa5df 100644
--- a/tests/twisted/tubes/test-si-tubes.py
+++ b/tests/twisted/tubes/test-si-tubes.py
@@ -31,6 +31,13 @@ sample_parameters = dbus.Dictionary({
     'i': dbus.Int32(-123),
     }, signature='sv')
 
+new_sample_parameters = dbus.Dictionary({
+    's': 'newhello',
+    'ay': dbus.ByteArray('newhello'),
+    'u': dbus.UInt32(123),
+    'i': dbus.Int32(-123),
+    }, signature='sv')
+
 
 class Echo(Protocol):
     def dataReceived(self, data):
@@ -180,6 +187,8 @@ def test(q, bus, conn, stream):
                 bob_handle,
              'org.freedesktop.Telepathy.Channel.Type.StreamTube.DRAFT.Service':
                 "newecho",
+             'org.freedesktop.Telepathy.Channel.Interface.Tube.DRAFT.Parameters':
+                dbus.Dictionary({'foo': 'bar'}, signature='sv'),
             });
 
     ret, old_sig, new_sig = q.expect_many(
@@ -321,13 +330,21 @@ def test(q, bus, conn, stream):
             'org.freedesktop.Telepathy.Channel.Interface.Tube.DRAFT',
             dbus_interface='org.freedesktop.DBus.Properties')
     assert tube_props.get("Initiator") == self_handle
-    #print str(tube_props.get("Parameters"))
-    #assert tube_props.get("Parameters") == {'ay': ('bytes', 'aGVsbG8='),
-    #                  's': ('str', 'hello'),
-    #                  'i': ('int', '-123'),
-    #                  'u': ('uint', '123'),
-    #                 }
-
+    print str(tube_props.get("Parameters"))
+    assert tube_props.get("Parameters") == dbus.Dictionary(
+            {dbus.String(u'foo'): dbus.String(u'bar')},
+            signature=dbus.Signature('sv'))
+    # change the parameters
+    tube_chan.Set('org.freedesktop.Telepathy.Channel.Interface.Tube.DRAFT',
+            'Parameters', new_sample_parameters,
+            dbus_interface='org.freedesktop.DBus.Properties')
+    # check it is correctly changed
+    tube_props = tube_chan.GetAll(
+            'org.freedesktop.Telepathy.Channel.Interface.Tube.DRAFT',
+            dbus_interface='org.freedesktop.DBus.Properties', byte_arrays=True)
+    assert tube_props.get("Parameters") == new_sample_parameters, \
+            tube_props.get("Parameters")
+    
     # 3 == Tube_Channel_State_Not_Offered
     assert tube_props.get("Status") == 3, tube_props
 
@@ -378,17 +395,33 @@ def test(q, bus, conn, stream):
     assert not tube.hasAttribute('initiator')
     new_stream_tube_id = long(tube['id'])
 
-    #parameters not yet correctly implemented..
-    #params = {}
-    #parameter_nodes = xpath.queryForNodes('/tube/parameters/parameter', tube)
-    #for node in parameter_nodes:
-    #    assert node['name'] not in params
-    #    params[node['name']] = (node['type'], str(node))
-    #assert params == {'ay': ('bytes', 'aGVsbG8='),
-    #                  's': ('str', 'hello'),
-    #                  'i': ('int', '-123'),
-    #                  'u': ('uint', '123'),
-    #                 }
+    params = {}
+    parameter_nodes = xpath.queryForNodes('/tube/parameters/parameter', tube)
+    for node in parameter_nodes:
+        assert node['name'] not in params
+        params[node['name']] = (node['type'], str(node))
+    assert params == {'ay': ('bytes', 'bmV3aGVsbG8='),
+                      's': ('str', 'newhello'),
+                      'i': ('int', '-123'),
+                      'u': ('uint', '123'),
+                     }
+    # The new tube has been offered, the parameters cannot be changed anymore
+    # We need to use call_async to check the error
+    tube_prop_iface = dbus.Interface(tube_chan,
+        'org.freedesktop.DBus.Properties')
+    call_async(q, tube_prop_iface, 'Set',
+        'org.freedesktop.Telepathy.Channel.Interface.Tube.DRAFT',
+            'Parameters', dbus.Dictionary(
+            {dbus.String(u'foo2'): dbus.String(u'bar2')},
+            signature=dbus.Signature('sv')),
+            dbus_interface='org.freedesktop.DBus.Properties')
+    set_error = q.expect('dbus-error')
+    # check it is *not* correctly changed
+    tube_props = tube_chan.GetAll(
+            'org.freedesktop.Telepathy.Channel.Interface.Tube.DRAFT',
+            dbus_interface='org.freedesktop.DBus.Properties', byte_arrays=True)
+    assert tube_props.get("Parameters") == new_sample_parameters, \
+            tube_props.get("Parameters")
 
     # The CM is the server, so fake a client wanting to talk to it
     # Old API tube
@@ -484,7 +517,7 @@ def test(q, bus, conn, stream):
         self_handle,
         1,      # Unix stream
         'newecho',
-        {}, # sample_parameters, # FIXME: parameters should work too...
+        new_sample_parameters,
         2,      # OPEN
         ) in tubes, tubes
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list