txdbus icon indicating copy to clipboard operation
txdbus copied to clipboard

Return DBusObject instance when return type is Object Path

Open derekstavis opened this issue 10 years ago • 3 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.

derekstavis avatar Aug 22 '14 17:08 derekstavis

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

cocagne avatar Aug 25 '14 14:08 cocagne

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.

derekstavis avatar Aug 25 '14 14:08 derekstavis

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 < [email protected]> 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 https://github.com/cocagne/txdbus/issues/15#issuecomment-53274393.

cocagne avatar Aug 25 '14 15:08 cocagne