Bug 26883 - InterfaceFactory._valid_interfaces is not really valid before connection
Summary: InterfaceFactory._valid_interfaces is not really valid before connection
Status: RESOLVED MOVED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: tp-python (show other bugs)
Version: unspecified
Hardware: Other Linux (All)
: medium normal
Assignee: Telepathy bugs list
QA Contact: Telepathy bugs list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-04 06:32 UTC by Fabien LOUIS
Modified: 2019-12-03 20:14 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Patch to fix _valid_interfaces attribute (633 bytes, patch)
2010-03-04 06:32 UTC, Fabien LOUIS
Details | Splinter Review

Description Fabien LOUIS 2010-03-04 06:32:44 UTC
Created attachment 33757 [details] [review]
Patch to fix _valid_interfaces attribute

Before the status of the connection was set to CONNECTION_STATUS_CONNECTED (which calls self._get_interfaces()), the attribute _valid_interfaces (InterfaceFactory.) isn't the copy of self[CONN_INTERFACE].GetInterfaces().

Indeed, once Connection is created (but not connected), the attribute _valid_interfaces contains only
set(['org.freedesktop.Telepathy.Connection', 'org.freedesktop.DBus.Properties'])

In the other hand, self[CONN_INTERFACE].GetInterfaces() returns:
dbus.Array([dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Aliasing'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Capabilities'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.SimplePresence'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Presence'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Avatars'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Contacts'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Requests'), dbus.String(u'org.laptop.Telepathy.Gadget'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.ContactCapabilities.DRAFT'), dbus.String(u'org.freedesktop.Telepathy.Connection.Interface.Location')], signature=dbus.Signature('s'))

----

So I created a patche which calls self[CONN_INTERFACE].GetInterfaces() and updates this attribute (_valid_interfaces) in the __init__ of Connection.

Of course, you are free to modify this patch :)

----

HS: I had need this changes because I want to call SetPresence before calling Connect(), which wasn't possible before.
Comment 1 Simon McVittie 2010-03-04 06:45:08 UTC
This is more of a documentation bug: the valid interfaces aren't necessarily known until the connection connects, so the result of GetInterfaces() is incomplete until CONNECTED is signalled. (Also, telepathy-python shouldn't block on D-Bus calls as your patch does.)

The right thing to do is not trust _valid_interfaces to be complete until the Connection signals that it is "ready" (I believe there's a ready_handler __init__ argument or something?
Comment 2 Fabien LOUIS 2010-03-04 07:09:27 UTC
Yep there is a ready handler, but it is emit when Connection is CONNECTED (which is good).

So if I want to call SetPresence before calling Connect() (so before CONNECTED), I need a right _valid_interfaces attribute.

Currently (before my patch), if we cant to change presence before calling Connect(), I get a KeyError because org.freedesktop.Telepathy.Connection.Interface.SimplePresence isn't in _valid_interfaces.

I think we need an attribute which is always valid no?
Comment 3 Simon McVittie 2010-03-04 07:38:45 UTC
The attribute can't always be valid (without blocking the main loop, which is bad - <http://smcv.pseudorandom.co.uk/2008/11/nonblocking/>), since on a newly created Connection we just don't have that information yet - we have to ask over D-Bus, which takes time.

I think what you need to pre-load SimplePresence is something that resembles ready_handler, but can run as soon as the initial Status and Interfaces have been fetched, without waiting for CONNECTED. telepathy-qt4 has a mechanism like that, and putting a similar thing into telepathy-glib is among my medium-term plans for Telepathy.

I'm not sure exactly how this should be implemented in telepathy-python, which doesn't natively have any mechanism for signals; perhaps binding telepathy-glib into Python would be a better long-term solution for this sort of thing.

(In the meantime, if you know through out-of-band information, or your own call to GetInterfaces, that the Connection has the SimplePresence interface, I believe you should be able to just make a dbus.Interface for it, and call the method on that?)
Comment 4 Fabien LOUIS 2010-03-04 08:00:10 UTC
Yes I could bypass this by creating a specific code for this case but I don't want to patch my code :)
So I prefer use your bindings all time.

Anyway, for moment, the current method (patch) is good for my case.

I let you decide how to allow this in the future (for example, calling SetPresence on SimplePresence, before connecting the connection without throw an error).
Comment 5 GitLab Migration User 2019-12-03 20:14:22 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/telepathy/telepathy-python/issues/12.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.