Search code examples
dbus

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


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.


Solution

  • No.

    Most likely org.freedesktop.DBus.Properties.GetAll will return you same value, but internally every service implement properties as handlers to messages with org.freedesktop.DBus.Properties.Get/org.freedesktop.DBus.Properties.GetAll method calls.

    It looks like object.getProp("someproperty") because it actually is more like this pseudo-code

    bus.handleMessage({
      service: "org.freedesktop.NetworkManager",
      object: "/org/freedesktop/NetworkManager/Devices/0",
      iface: "org.freedesktop.NetworkManager.Device.Interface",
      body: [ "org.freedesktop.NetworkManager.Device", "Interface"],
      thisMessageIsReplyTo: null
    })
    

    Internally every method call/signal/reply is just a message with big signature (service name/object path/interface) and body