Understanding D-Bus: Myl' Ene Josserand
Understanding D-Bus: Myl' Ene Josserand
Understanding D-Bus
Mylène Josserand
[email protected]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/1
What is this talk about?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/1
Understanding D-Bus
D-Bus generality
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/1
D-Bus
I Created in 2002
I Is part of the freedesktop.org project
I Maintained by RedHat and the community
I Is an Inter-process communication mechanism
I Initiated to standardize services of Linux
desktop environments
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/1
Inter-Process Communication (IPC)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/1
IPC using D-Bus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/1
Understanding D-Bus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 7/1
D-Bus elements
I D-Bus includes:
I libdbus: a low-level library
I dbus-daemon: a daemon based on libdbus. Handles and controls data transfers
between DBus peers
I two types of busses: a system and a session one. Each bus instance is managed
by a dbus-daemon
I a security mechanism using policy files
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/1
System & Session busses
I System bus
I On desktop, a single bus for all users
I Dedicated to system services
I Is about low-level events such as connection to a network, USB devices, etc
I On embedded Linux systems, this bus is often the only D-Bus type
I Session bus
I One instance per user session
I Provides desktop services to user applications
I Linked to the X session
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/1
Understanding D-Bus
The principles
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/1
Generality
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/1
Service
I An application can expose its services to all D-Bus users by registering to a bus
instance
I A service is a collection of objects providing a specific set of features
I When an application opens a connection to a bus instance, it is assigned a unique
name (ie :1.40)
I Can request a more human-readable service name: the well-known name (ie
org.ofono) See the freedesktop.org specification
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 12/1
Objects
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 13/1
Interfaces
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 14/1
Interfaces
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 15/1
Interfaces
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 16/1
Properties
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 18/1
Signals
I Messages / notifications
I Unidirectionnal
I Sent to every clients that are listening to it
I Can contain parameters
I A client will subscribe to signals to get notifications
org.freedesktop.DBus.Properties :
PropertiesChanged (String, Dict of {String, Variant}, Array of String)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 19/1
Policy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 20/1
Policy - file example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 21/1
Understanding D-Bus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 22/1
Libraries & bindings
I Libdbus
I This is the low-level library used by the dbus-daemon.
I As the homepage of the project says: “If you use this low-level API directly, you’re
signing up for some pain”.
I Recommended to use it only for small programs and you do not want to add many
dependencies
I GDbus
I Is part of GLib (GIO)
I Provides a very comfortable API
I QtDbus
I Is a Qt module
I Is useful if you already have Qt on your system
I Contains many classes to handle/interact such as QDBusInterface
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 23/1
Libraries & bindings
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 24/1
Tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 25/1
Tools: dbus-send
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 26/1
Tools: dbus-send - demo
I Get properties:
dbus-send --system --print-reply --dest=net.connman / net.connman.Clock.GetProperties
I Set property:
dbus-send --system --print-reply --dest=net.connman \
/ net.connman.Clock.SetProperty \
string:TimeUpdates variant:string:manual
I Using standard interfaces:
dbus-send --system --print-reply --dest=net.connman \
/ org.freedesktop.DBus.Introspectable.Introspect
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 27/1
Tools: dbus-monitor
I Can monitor all traffic (including methods and signals if enabled in policy):
dbus-monitor
I Or filter messages based on the interface:
dbus-monitor --system type=signal interface=net.connman.Clock
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 28/1
Tools: gdbus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 29/1
Tools: d-feet
I Is a GUI interface
I Handles system and session busses
I Can call methods with parameters
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 30/1
Understanding D-Bus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 31/1
Projects using D-Bus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 32/1
Understanding D-Bus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 33/1
Ofono
I Started in 2009
I Developed by Intel and Nokia
I Used in 2013 by Canonical for Ubuntu-touch
I Handles all the different parts to connect a modem: pin code, network
registration, etc
I Communicates with connman using D-Bus
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 34/1
Connman
I Started in 2008
I Developed by Intel
I Used by Sailfish OS and Jolla
I Manages internet connexion within embbeded devices
I Provides a plugin based architecture (ofono provides such a plugin to
communicate with the ofono daemon)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 35/1
Communication
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 36/1
Communication
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 37/1
Example with Active property
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 38/1
Example with Active property
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 39/1
Understanding D-Bus
Conclusion
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 40/1
Conclusion
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 41/1
Questions? Suggestions? Comments?
Mylène Josserand
[email protected]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 42/1