D-Bus
D-Bus is an inter-process communication (IPC) protocol used in the Linux, Windows and BSD operating systems. It allows multiple applications to exchange data and signals in a standardized way.
D-Bus has several layers: a library, libdbus, which allows two applications to connect to each other and exchange messages; a message bus daemon executable, built on libdbus, which multiple applications can connect to; and native objects and object paths. Native objects are objects that the application owns and manages and object paths allow applications to access those native objects.
Applications that use D-Bus are either servers or clients. A server listens for incoming connections and a client connects to a server. Once the connection is established, it is a symmetric flow of messages. D-Bus provides its own marshaling and language bindings for different languages like Glib, Qt, Python, etc.
Using D-Bus should feel more like object-oriented programming than like communication. Bus names can be used to coordinate single-instance applications. Addresses are also used to identify connections. The idea is to fit the D-Bus API into the native language and libraries as naturally as possible.
D-Bus is non-transactional and behaves like an RPC mechanism. Semantics are similar to the existing DCOP system, allowing KDE to adopt it more easily. It is also tailored to meet the needs of the desktop projects in particular.
To get started with using D-Bus, one should refer to the D-Bus specification, Doxygen reference documentation, and look at some examples of how other apps use D-Bus. An example of an application that uses D-Bus is ØMQ, an open source messaging middleware.
To query D-Bus from the terminal, you can use the dbus-send command.
Example 1: Get the current volume level of the PulseAudio server:
dbus-send --print-reply --dest=org.pulseaudio.Server /org/pulseaudio/server_lookup org.freedesktop.DBus.Properties.Get string:'org.pulseaudio.Server' string:'Volume'
Example 2: Change the volume level of the PulseAudio server:
dbus-send --print-reply --dest=org.pulseaudio.Server /org/pulseaudio/server_lookup org.freedesktop.DBus.Properties.Set string:'org.pulseaudio.Server' string:'Volume' variant:double:0.5
Example 3: Get the current time from the system bus:
dbus-send --print-reply --system --dest=org.freedesktop.timedate1 /org/freedesktop/timedate1 org.freedesktop.DBus.Properties.Get string:'org.freedesktop.timedate1' string:'TimeUSec'
Note: in above examples, the --dest flag
specifies the destination service and the /org/pulseaudio/server_lookup
or /org/freedesktop/timedate1 specifies the object path
. The org.freedesktop.DBus.Properties.Get or org.freedesktop.DBus.Properties.Set specifies the interface and the method you want to call.
You can also use gdbus command which is a command-line tool for interacting with D-Bus objects.
You can get more information about dbus-send and gdbus from their man pages.
References: [1] https://www.freedesktop.org/wiki/IntroductionToDBus/ [2] https://dbus.freedesktop.org/doc/dbus-tutorial.html [3] https://en.wikipedia.org/wiki/D-Bus [4] https://www.cardinalpeak.com/blog/using-dbus-in-embedded-linux [5] https://stackoverflow.com/questions/482681/d-bus-equivalent-for-windows [6] https://alternativeto.net/software/d-bus/
Citations :
- https://www.freedesktop.org/wiki/IntroductionToDBus/
- https://dbus.freedesktop.org/doc/dbus-tutorial.html
- https://www.cardinalpeak.com/blog/using-dbus-in-embedded-linux
- https://en.wikipedia.org/wiki/D-Bus
- https://stackoverflow.com/questions/482681/d-bus-equivalent-for-windows
- https://alternativeto.net/software/d-bus/
- https://dbus.freedesktop.org/doc/dbus-tutorial.html#:~:text=D%2DBus%20is%20a%20system,multiple%20applications%20can%20connect%20to.