Can you retrieve a D-Bus property without calling org.freedesktop.DBus.Properties.Get?

user3243135 picture user3243135 · Aug 15, 2013 · Viewed 9.2k times · Source

Say I want to programmatically get the interface name of my ethernet card. This seems to work:

dbus-send --print-reply \
          --type=method_call \
          --system \
          --dest=org.freedesktop.NetworkManager \
          /org/freedesktop/NetworkManager/Devices/0 \
          org.freedesktop.DBus.Properties.Get \
          string:org.freedesktop.NetworkManager.Device \
          string:Interface

Which returns:

method return sender=:1.5 -> dest=:1.135 reply_serial=2
   variant       string "eth0"

Is there some way of cutting out the middleman org.freedesktop.DBus.Properties.Get and retrieve the property more directly? Alas, calling it as a method does not work:

dbus-send --print-reply \
          --type=method_call \
          --system \
          --dest=org.freedesktop.NetworkManager \
          /org/freedesktop/NetworkManager/Devices/0 \
          org.freedesktop.NetworkManager.Device.Interface

Returns:

Error org.freedesktop.DBus.Error.UnknownMethod: 
Method "Interface" with signature "" on interface 
"org.freedesktop.NetworkManager.Device" doesn't exist

I ask because having to call org.freedesktop.DBus.Properties.Get looks like having to call a object.getProp("someproperty") instead of object.getSomeProperty() in Python/Java/etc.

Answer

elboulangero picture elboulangero · May 14, 2014

Yep, you can do that if you use qdbus. I don't have NetworkManager with me, but a command like that should work:

qdbus --system \
      org.freedesktop.NetworkManager \
      /org/freedesktop/NetworkManager/Devices/0 \
      org.freedesktop.NetworkManager.Device.Interface

There are various command-line clients for talking to D-Bus, some are more convenient than others. Here's the list of the ones I know.

  • dbus-send (provided with D-Bus itself)
  • gdbus (provided by GLib)
  • qdbus (provided by Qt)
  • busctl (provided by systemd)