cocagne / txdbus

Native Python implementation of DBus for Twisted

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return DBusObject instance when return type is Object Path

derekstavis opened this issue · comments

DBusObject methods with object path return type doesn't allow returning a DBusObject subclass. It would be very nice to support this, as subclasses of DBusObject are initialized with its path.

I'm not sure I understand what you mean. Would you mind explaining a bit further?

Take this code as an example:

FOO_INTERFACE = 'com.foo.Interface'
BAR_INTERFACE = 'com.foo.Bar'

class Bar(DBusObject):
    iface = DBusInterface(BAR_INTERFACE, Method('FooBar')
    dbusInterfaces = [iface] 

    @dbusMethod(BAR_INTERFACE, 'FooBar')
    def FooBar(self):
        print('foobar')

class FooInterface(DBusObject):
    iface = DBusInterface(FOO_INTERFACE, Method('GetBar', returns='o'))
    dbusInterfaces = [iface]

    @dbusMethod(FOO_INTERFACE, 'GetBar')
    def GetBar(self):
        obj = FooBar()
        self.getConnection().exportObject(obj)
        return obj # <- Exception trying to call startswith, as it waits for a str type

Actually the return obj line must be written as return obj.getObjectPath(). I propose accepting return a DBusObject subclass, as the example code does.

Ok, I think I follow you now. So you're saying that if the DBus interface
for a method specifies a single object path as it's return type and the
Python method implementing that interface method returns DBusObject
instance instead of a string, just go ahead and convert it to an object
path. Excellent suggestion.

I'll put this on the queue for the next txdbus release but, honestly, I
haven't been able to devote much time to the project recently. It may be a
while before I get around to it but it'll go in eventually.

Thanks for the suggestion Derek.

Tom

On Mon, Aug 25, 2014 at 9:55 AM, Derek Willian Stavis <
notifications@github.com> wrote:

Take this code as an example:

FOO_INTERFACE = 'com.foo.Interface'BAR_INTERFACE = 'com.foo.Bar'
class Bar(DBusObject):
iface = DBusInterface(BAR_INTERFACE, Method('FooBar')
dbusInterfaces = [iface]

@dbusMethod(BAR_INTERFACE, 'FooBar')
def FooBar(self):
    print('foobar')

class FooInterface(DBusObject):
iface = DBusInterface(FOO_INTERFACE, Method('GetBar', returns='o'))
dbusInterfaces = [iface]

@dbusMethod(FOO_INTERFACE, 'GetBar')
def GetBar(self):
    obj = FooBar()
    self.getConnection().exportObject(obj)
    return obj # <- Exception trying to call startswith, as it waits for a str type

Actually the return obj line must be written as return obj.getObjectPath().
I propose accepting return a DBusObject subclass, as the example code does.


Reply to this email directly or view it on GitHub
#15 (comment).