Read dbus-monitor Output – How to Guide


I'm playing around with dbus-monitor to try and understand how dbus is working in Ubuntu environment. I have several questions in this regard:

  1. Could you please let me know how to read the following properly? I understand the big idea, but not the details.

    signal sender=:1.1948 -> dest=(null destination) serial=1829990 path=/org/ayatana/menu/DA00003; interface=org.ayatana.dbusmenu; member=ItemPropertyUpdated
    int32 23
    string "enabled"
    variant boolean true
    method call sender=:1.6 -> dest=org.freedesktop.Notifications serial=1399 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications;

    I get that the first one is a signal whereas the second is a method. Does destination mean there can be a specific receiver/slot for a signal? What's a member? And are the items of the list following the signal the arguments passed in the signal? What are sender and serials?

  2. I noticed something about the relationship between volume-control and notifications. From what I read from the dbus-monitor output

    method call sender=:1.6 -> dest=org.freedesktop.Notifications serial=1400 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications; member=Notify
    string "gnome-settings-daemon"
    uint32 0
    string "notification-audio-volume-medium"
    string " "
    string ""
    array [
    array [
    dict entry(
    string "value"
    variant int32 38
    dict entry(
    string "x-canonical-private-synchronous"
    variant string "volume"
    int32 -1

    It seems that the notification is triggered by its method. I just don't really understand why it works this way. In my view it would make more sense if there was a signal emitted "notification-audio-volume-medium" while the notification would listen for this signal and react accordingly. If the sending / receiving would be public rather than private, wouldn't it allow for more flexibility and efficiency? For instance if there was a public signal for "notification-audio-volume-medium" then several applications could listen for this signal (which would allow for competing notification applications to come to existence) and developers would just have to be concerned with sending signals, while picking up and handling a signal would be the notifying application's business (or any other program that needs those signals).

  3. I'm just new to Dbus and want to learn more as I am working with Dbus on Python, mainly to develop some applets. I've seen the dbus-python tutorial and it teaches how to listen to all signals (by specifying neither interface nor path etc.) But how to track methods when they are called, like dbus-monitor does?

If you have the patience to teach how that works, you're welcome.

Best Answer

D-Bus introduction

  • D-Bus provides means for communicating between services. Services can be anonymous (identified solely by bus address, like :1.6), and services can aquire well-known names, like org.freedesktop.Notifications or org.freedesktop.NetworkManager. The sender and destination which you can see in the logs are services. "Null destination" means broadcast: delivery to all services.

  • A service can export one or several objects to the bus. Objects are given object paths, like /org/freedesktop/NetworkManager/ActiveConnection/1 or /org/ayatana/menu/DA00003. Object paths use slash as separator, like filesystem paths.

  • Each object can support one or several interfaces. An interface is nothing more than a set of methods and signals, coloquially known as members (very similar to OOP interface). Methods and signals have fixed signatures. Members are always namespaced within well-known interface names.

  • Once published, well-known names never change.

  • Any service can connect to another service's signals and asynchronously call its methods. Any service can emit signals.


Now to your specific questions.

signal sender=:1.1948 -> dest=(null destination) serial=1829990 path=/org/ayatana/menu/DA00003; interface=org.ayatana.dbusmenu; member=ItemPropertyUpdated
int32 23
string "enabled"
variant boolean true

Yes, you're right, this is a signal. It's broadcasted by service :1.1948, and "self" object is /org/ayatana/menu/DA00003. The signal has name ItemPropertyUpdated which is defined in the interface org.ayatana.dbusmenu (like org.ayatana.dbusmenu::ItemPropertyUpdated in C++). The serial, I guess, is a kind of unique identifier of the event on the bus.

Then we see the signal arguments. According to the interface documentation, the first int32 argument is an item's id, second string is its property name, and the third variant is the property value. So, the /org/ayatana/menu/DA00003 object is notifying us that the item id #23 changed its enabled property to true.

Another example on signals:

signal sender=:1.1602 -> dest=(null destination) serial=20408 path=/im/pidgin/purple/PurpleObject; interface=im.pidgin.purple.PurpleInterface; member=SendingChatMsg
   int32 47893
   string "test"
   uint32 1
signal sender=:1.1602 -> dest=(null destination) serial=20409 path=/im/pidgin/purple/PurpleObject; interface=im.pidgin.purple.PurpleInterface; member=IrcSendingText
   int32 64170
   string "PRIVMSG #chat :test

I sent a text message "test" using Pidgin to an IRC channel, and /im/pidgin/purple/PurpleObject emitted two signals under the im.pidgin.purple.PurpleInterface interface: first a general SendingChatMsg, then a more specific IrcSendingText.


Now methods. Methods are a way to ask D-Bus objects to do something, or to perform some query and return data. They are quite similar to classic OOP methods, except that D-Bus methods are called asynchronously.

Let's call a D-Bus method programmatically.

import dbus, dbus.proxies

#-- connect to the session bus (as opposed to the system bus)
session = dbus.SessionBus()

#-- create proxy object of D-Bus object
obj_proxy = dbus.proxies.ProxyObject(conn=session,
         bus_name="org.freedesktop.Notifications",     #-- name of the service we are retrieving object from
         object_path="/org/freedesktop/Notifications") #-- the object path

#-- create proxy object of the D-Bus object wrapped into specific interface
intf_proxy = dbus.proxies.Interface(obj_proxy, "org.freedesktop.Notifications")

#-- lastly, create proxy object of the D-Bus method
method_proxy = intf_proxy.get_dbus_method("Notify")

#-- ... and call the method
method_proxy("test from python",
             "bluetooth",     #-- icon name
             "Notification summary",
             "Here goes notification body",
             [], {},
             5) #-- timeout

Note the arguments, especially the icon name. In your example "notification-audio-volume-medium" was the icon of medium-powered volume speaker.

Custom services

It is absolutely possible to run your own D-Bus services, export your own D-Bus objects and define your own D-Bus interfaces with your own methods and signals. This all can be done in Python pretty easily once you grasp the overall concept and read the dbus module documentation. :)