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

Cannot return several values #132

Open
nschoe opened this issue Jun 21, 2016 · 1 comment
Open

Cannot return several values #132

nschoe opened this issue Jun 21, 2016 · 1 comment

Comments

@nschoe
Copy link

nschoe commented Jun 21, 2016

I was trying to implement org.freedesktop.Notifications as "Hello, World" dbus application. When using notify-send "Title" "Message", the application should display on screen the message.

As per defined here, we need to first implement org.freedesktop.Notifications.GetServerInformation which takes no IN argument, but whose return values is OUT string, OUT string, OUT string, OUT string, so 4 output string values (not an array of string, which would be as).

I've tried it with:

iface.addMethod ('GetServerInformation', { in: [], out: [DBus.Define (String), DBus.Define (String), DBus.Define (String), DBus.Define (String)]}, function (callback) {
        console.log ('GetServerInformation was called.');
        callback (['Awesome Notification Server', 'example.org', '0.1', '1.2']);
    });

But then, when introspecting with gdbus introspect -e -d org.freedesktop.Notifications -o /org/freedesktop/Notifications I've got:

interface org.freedesktop.Notifications {
    methods:
      GetServerInformation(out undefined arg_0);

So it writes it as undefined, and when I try to call it with gdbus call [...], I've got () as return value and nodejs complains with Invalid type which makes sense.

No matter how I tried I could not manage to return several values (in this case 4 strings), so I defaulted to returning an array with:

iface.addMethod ('GetServerInformation', {in: [], out: DBus.Define(Array)}, function (callback) {
        console.log ('GetServerInformation was called.');
        callback (['Awesome Notification Server', 'example.org', '0.1', '1.2']);
    });

This time, when I introspect I've got:

interface org.freedesktop.Notifications {
    methods:
      GetServerInformation(out av arg_0);

which is consistent, but when I call with gdbus call [...] I've got:

([<'Awesome Notification Server'>, <'example.org'>, <'0.1'>, <'1.2'>],)

Which is not 4 strings, and when I directly call notify-send, it fails too.

I've confirmed this is not the desired behavior by running a proper notification daemon (which works with notify-send) and when I call GetServerInformation with gdbus call [...] I've got this as result:

('Notification Daemon', 'GNOME', '3.18.2', '1.2')

which is 4 strings :-)

So my question is: how can I return 4 strings with this binding?

Thanks in advance.

@FliiFe
Copy link

FliiFe commented Jul 26, 2018

Yeah, this has to get fixed, as a lot of methods need to output multiple values.

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