DBusInterface: how to pass a dbus 'as' object in Nemo.DBus?

Hi,

I feel a bit stupid but I can’t get this to work.

Using gdbus I can do this:

 gdbus call  --session --dest=org.freedesktop.systemd1 --object-path /org/freedesktop/systemd1 --method org.freedesktop.systemd1.Manager.ListUnitsFiltered "[ 'listening' ]"

which prints an array of dbus objects.

Trying the equivalent in QML I always get:

[W] :52 - DBus call failed:  org.freedesktop.DBus.Error.InvalidArgs message:  Invalid arguments 'av' to call org.freedesktop.systemd1.Manager.ListUnitsFiltered(), expecting 'as'.

[W] :52 - DBus call failed:  org.freedesktop.DBus.Error.InvalidArgs message:  Invalid arguments 's' to call org.freedesktop.systemd1.Manager.ListUnitsFiltered(), expecting 'as'.

This is what I try in qml:

import QtQuick 2.0
import Sailfish.Silica 1.0
import Nemo.DBus 2.0

 // systemd manager
 DBusInterface {
    id: systemd
    bus: DBus.SessionBus
    service: "org.freedesktop.systemd1"
    path: "/org/freedesktop/systemd1"
    iface: "org.freedesktop.systemd1.Manager"
    function unitList() {
      //  call('ListUnitsFiltered', [ "listening" ],  // <--- complains about 's'
      call('ListUnitsFiltered', [ ["listening",] ],  // <--- complains about 'av'
                  function (result) {         console.debug('DBus call result: ' + result) },
                  function (error, message) { console.warn('DBus call failed: ', error, 'message: ', message) }
          )
    }
}
Component.onCompleted: checkSocketState()
function checkSocketState() {
    console.log(systemd.unitList());
}

Coincidence? I just posted this related question.

I used import org.nemomobile.dbus 2.0
is import Nemo.DBus 2.0 the same?

Apparently great minds get confused alike… :slight_smile: I seem to remember the org.nemomobile.foo imports being deprecated in favour of Nemo.Foo but I’m not sure.

Looking at this source it seems all arrays get converted to a variant, so I guess I can’t actually pass a string array using call()

Using typedCall like this I get no errors - next step: how to deal with the resulting object (it is always empty…).

    function unitList() {
      typedCall('ListUnitsFiltered', [
                        { 'type': 'as', 'value': [ { 'type': 's', 'value': 'listening' } ] }
                  ],
                  function (result) {         console.debug('DBus call result: ' + result) },
                  function (error, message) { console.warn('DBus call failed: ', error, 'message: ', message) }
          )
    }
dbus-send --print-reply --session \
         --dest=org.example.Service / org.example.Service.ListSorter \
         array:string:"1st item","next item","last item"

Thanks, but I’m trying to do it from QML, not shell.

but in your OP you had a gdbus call this confused me

have you seen this Nemo QML Plugin D-Bus - Sailfish OS

I have, it’s what I’m using to do the dbus call from QML.

Now, I have managed to get the parameters right, I think.

The problem now is, the result dataset is always empty. A plain ListUnits works fine, but ListUnitsFiltered and ListUnitsByName and friends do not, and I can’t figure out why.

All these calls work as expected when executed through cli tools.