Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return DBusObject instance when return type is Object Path #15

Open
derekstavis opened this issue Aug 22, 2014 · 3 comments
Open

Return DBusObject instance when return type is Object Path #15

derekstavis opened this issue Aug 22, 2014 · 3 comments

Comments

@derekstavis
Copy link

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.

@cocagne
Copy link
Owner

cocagne commented Aug 25, 2014

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

@derekstavis
Copy link
Author

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.

@cocagne
Copy link
Owner

cocagne commented Aug 25, 2014

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).

@derekstavis derekstavis changed the title Allow returning DBusObject instances when return type is Object Path Return DBusObject instance when return type is Object Path Nov 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants