Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dbus

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.

like image 852
user3243135 Avatar asked Aug 14 '13 23:08

user3243135


People also ask

What are Dbus commands?

The dbus-send command is used to send a message to a D-Bus message bus. See https://www.freedesktop.org/wiki/Software/dbus/ for more information about the big picture.

What is a dbus interface?

Dbus is an Inter-Process Communication protocol (IPC). It allows multiple processes to exchange information in a standardized way. This is typically used to separate the back end system control from the user-facing interface.


1 Answers

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)
like image 177
elboulangero Avatar answered Oct 01 '22 22:10

elboulangero