SlideShare a Scribd company logo
D-Bus Usage and Debug
Introduction
潘建宏 Jian-Hong Pan (StarNight)
@ COSCUP 2024
Who am I
潘建宏 / Jian-Hong Pan (StarNight)
Endless OS Foundation
You can find me at
● http://www.slideshare.net/chienhungpan/
● GitHub: starnight
● X: starnight_pan
● Email:
jhp [AT] endlessos.org
chienhung.pan [AT] gmail.com
Agenda
1. How to implement Inter Proccess Communication (IPC)
2. What is D-Bus
a. Resource Addressing
b. Message Bus
c. Data Types
d. Message Types
3. Debug Tools
4. Write D-Bus Applications
5. Reference
Inter Process Communication (IPC)
A process communicates with another process for exchanging information.
How to implement?
● Share memory between the processes
● The processes write and read the same file
● Pipeline
● Communicate with Sockets
● How about with a library, such as D-Bus library?
Why D-Bus?
● Based on UNIX Domain socket
● Ecosystem uses it widely
○ systemd, Desktop Environment: GNOME, KDE …
● Server-client architecture
● Data serialization format
● Method call communication and broadcasting mechanism
This slide is more like a note extracted
from
D-Bus Specification & D-Bus Tutorial
D-Bus is
● A message bus system, a simple way for applications to talk to one another.
● A system for interprocess communication (IPC). Architecturally, it has several
layers:
○ A library, libdbus, that allows two applications to connect to each other
and exchange messages.
○ A message bus daemon executable, built on libdbus, that multiple
applications can connect to. The daemon can route messages from one
application to zero or more other applications.
○ Wrapper libraries or bindings based on particular application frameworks.
Some reimplement by following D-Bus specification, such as GLib’s
built-in D-Bus library GDBus. There are also bindings to languages such
as Python, Go, Rust ...
D-Bus Supplies Bus Types
● System daemon (for system related things)
○ NetworkManager, UPower, udisks …
● Per-user-login-session daemon (for general IPC needs among user
applications)
○ GNOME Files, IBus …
● Some applications use both:
○ systemd, GNOME Control Center (Settings), GNOME Shell …
Resource Addressing: Bus, Object, Interface
● Bus Name:
When each application connects to the bus daemon, the daemon immediately
assigns it a name, called the unique connection name. A unique name begins
with a ':' (colon) character, for example, ‘:34.907’. The application may ask to
own additional well-known names, for example ’com.example.foo’. Then,
’com.example.foo’ maps to ‘:34.907’. Just like DNS maps to IP.
● Object Path:
The application should have an object at supporting interfaces. Here is an
object path example: ’/com/example/foo’.
● Interface:
Each object supports one or more interfaces. An interface holds some
members: Methods, Signals, Properties … For example,
’com.example.foo.property1’.
Note: The names and path should start like with the reversed DNS domain name.
D-Bus Message Bus
Process B
Process A
Interface com.example.foo: Method, Property1, Signal …
Object: /com/example/foo
Bus Name: com.example.foo maps to :34.907
Example: Enumerate power devices
$ dbus-send --print-reply --system --dest=org.freedesktop.UPower
/org/freedesktop/UPower org.freedesktop.UPower.EnumerateDevices
method return time=1719720362.974990 sender=:1.28 -> destination=:1.120
serial=333 reply_serial=2
array [
object path "/org/freedesktop/UPower/devices/battery_BAT0"
object path "/org/freedesktop/UPower/devices/line_power_AC"
object path
"/org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001"
]
$ dbus-send --print-reply --system --dest=org.freedesktop.UPower
/org/freedesktop/UPower/devices/battery_BAT0
org.freedesktop.DBus.Properties.GetAll string:org.freedesktop.UPower.Device
method return time=1719721654.476315 sender=:1.28 -> destination=:1.126
serial=432 reply_serial=2
array [
dict entry(
string "NativePath"
variant string "BAT0"
)
…
dict entry(
string "Percentage"
variant double 100
)
…
$ dbus-send --print-reply --system --dest=org.freedesktop.UPower
/org/freedesktop/UPower/devices/battery_BAT0
org.freedesktop.DBus.Properties.Get string:org.freedesktop.UPower.Device
string:Percentage
method return time=1719840496.847174 sender=:1.29 -> destination=:1.164
serial=154 reply_serial=2
variant double 100
Message Bus
● The message bus accepts connections from one or more applications. Once
connected, applications can exchange messages with other applications that
are also connected to the bus.
● In order to route messages among connections, the message bus keeps a
mapping from names to connections.
● The bus itself owns a special name, org.freedesktop.DBus, with an object
located at /org/freedesktop/DBus that implements the
org.freedesktop.DBus interface. This service allows applications to make
administrative requests of the bus itself. For example, applications can ask
the bus to assign a name to a connection.
● Message bus daemon: dbus-daemon, dbus-broker …
Standard Interfaces
There are some standard interfaces across various D-Bus applications:
● org.freedesktop.DBus.Introspectable
● org.freedesktop.DBus.Properties
● …
org.freedesktop.DBus.Introspectable interface
● org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)
Objects instances may implement Introspect which returns an XML
description of the object, including its interfaces (with signals and methods),
objects below it in the object path tree, and its properties.
The section “Introspection Data Format” describes the format of this XML
string.
1
2
3
4
5
6
org.freedesktop.DBus.Properties interface
Many native APIs will have a concept of object properties or attributes. These can
be exposed via this interface.
● org.freedesktop.DBus.Properties.Get (in STRING interface_name, in STRING
property_name, out VARIANT value)
● org.freedesktop.DBus.Properties.Set (in STRING interface_name, in STRING
property_name, in VARIANT value)
● org.freedesktop.DBus.Properties.GetAll (in STRING interface_name, out
ARRAY of DICT_ENTRY<STRING,VARIANT> props)
If one or more properties change on an object, the
org.freedesktop.DBus.Properties.PropertiesChanged signal may be emitted:
org.freedesktop.DBus.Properties.PropertiesChanged (STRING interface_name,
ARRAY of DICT_ENTRY<STRING,VARIANT> changed_properties,
ARRAY<STRING> invalidated_properties)
Type System
● Basic types
BYTE: ‘y’, BOOLEAN: ‘b’, INT16: ‘n’, UINT16: ‘q’, INT32: ‘i’, UINT32: ‘u’,
INT64: ‘x’, UINT64: ‘t’, DOUBLE: ‘d’, UNIX_FD: ‘h’
● String-like types
STRING: ‘s’, OBJECT_PATH: ‘o’, SIGNATURE: ‘g’
● Container types
STRUCT: “(ii)”, Nested STRUCT “(i(ii))”,
Array of INT32: “ai”, Array of STRUCT: “a(ii)”, Array of array of INT32: “aai”,
VARIANT: ‘v’, DICT_ENTRY: “{<key type><value type>}”
Big Conceptual Picture
A particular method call on a particular object instance:
Address -> [Bus Name] -> Object Path -> Interface -> Method
Address:
A D-Bus address specifies where a server will listen, and where a client will
connect. For example, the address unix:path=/tmp/abcdef specifies that the server
will listen on a UNIX domain socket at the path /tmp/abcdef and the client will
connect to that socket. An address can also specify TCP/IP sockets, or any other
transport defined in future iterations of the D-Bus specification.
D-Bus’ UNIX Socket Domain Examples
$ ss -a | grep dbus
u_str ESTAB 0 0 /run/user/1000/.dbus-proxy/session-bus-proxy-Z5DOQ2 3576 * 19926
u_str ESTAB 0 0 /run/dbus/system_bus_socket 812 * 811
u_str ESTAB 0 0 /run/user/1000/.dbus-proxy/system-bus-proxy-N7DOQ2 20773 * 8687
u_str ESTAB 0 0 /run/dbus/system_bus_socket 815 * 5448
…
Message Types
● METHOD_CALL
● METHOD_RETURN
● ERROR
● SIGNAL
METHOD_CALL, METHOD_RETURN & ERROR
● METHOD_CALL messages ask to invoke a method on an object.
● METHOD_RETURN messages return the results of invoking a method.
● Or, ERROR messages return an exception caused by invoking a method.
D-Bus client D-Bus server
METHOD_CALL
METHOD_RETURN, or ERROR
SIGNALS
SIGNAL messages are notifications that a given signal has been emitted (that an
event has occurred). It is like an "event" message.
D-Bus server D-Bus client A, B, C …
broadcast SIGNAL
D-Bus Message Bus
Process B
METHOD_CALL
Process C
Process X@#
Process A
Interface a: Methods, Signals, Properties …
Interface b: Methods, Signals, Properties …
.
.
.
Interface c: Methods, Signals, Properties …
Object #1
Object #N
Bus Name
Broadcast Signal
Process D
Interface: ,,. ,
Interface: … .
Bus Name
D-Bus Debug Tools
● dbus-monitor
● gdbus
● Bustle: Can be installed via flatpak
● D-Bus Spy
● D-Spy: Can be installed via flatpak
dbus-monitor Monitors (Un)Plugging USB Storage
$ sudo dbus-monitor --system "path='/org/freedesktop/UDisks2'"
…
signal time=1711795582.184807 sender=:1.62 -> destination=(null destination) serial=205
path=/org/freedesktop/UDisks2; interface=org.freedesktop.DBus.ObjectManager;
member=InterfacesAdded
object path "/org/freedesktop/UDisks2/drives/General_UDisk_General_UDisk_0_3a0"
array [
dict entry(
string "org.freedesktop.UDisks2.Drive"
array [
…
dict entry(
string "Serial"
variant string "General_UDisk-0:0"
...
D-Bus Usage and Debug Introduction @ COSCUP 2024
Write applications using D-Bus
ChatDBus Room as an Example
● gdbus-server: https://github.com/starnight/gdbus-server
● gdbus-client: https://github.com/starnight/gdbus-client
● pydbus-client: https://github.com/starnight/pydbus-client
Scenario
D-Bus client #1
SendMsg method
D-Bus client #2 D-Bus server
MsgNotification Signal
Some GDBus API (Server Side)
● g_bus_own_name (): Acquire "Bus Name" on the bus.
● g_dbus_node_info_new_for_xml (): Parses the introspection XML and returns
a GDBusNodeInfo representing the data.
● g_dbus_connection_register_object (): Registers callbacks in the virtual table
(↓) for exported objects at "Object Path" with the D-Bus interface that is
described in interface information.
● struct GDBusInterfaceVTable {
GDBusInterfaceMethodCallFunc method_call;
GDBusInterfaceGetPropertyFunc get_property;
GDBusInterfaceSetPropertyFunc set_property;
}
● g_dbus_connection_emit_signal ()
Some GDBus API (Client Side)
● g_dbus_proxy_new_for_bus_sync (): Creates a proxy for accessing the
Interface on the remote Object owned by the Bus name.
● g_dbus_proxy_get_cached_property ()
● g_dbus_proxy_set_cached_property ()
● g_dbus_proxy_get_connection (): Gets the connection proxy is for.
● g_dbus_connection_call_sync (): Synchronously invokes the Method on the
Interface on the remote Object owned by the Bus name.
● g_dbus_proxy_call_sync (): Synchronously invokes the Method on proxy.
● g_signal_connect (): Connects a GCallback function to a Signal for a
particular object.
Reference
● D-Bus
○ D-Bus Specification
■ Message Bus Starting Services (Activation)
○ D-Bus Overview
○ D-Bus Tutorial
● D-Bus API Design Guidelines
● GLib
● dbus-send, dbus-monitor, Bustle and D-Spy
● pydbus
● gdbus-codegen
D-Bus Usage and Debug Introduction @ COSCUP 2024

More Related Content

PPTX
D-bus basics
PDF
D bus specification
PDF
IPC with Qt
PDF
Your Watch can watch you ! Gear up for broken privilege pitfalls in the samsu...
PPTX
UE4 Twitch 2016 05-05: Unreal Message Bus Overview
PDF
EclipseCon 2011: Deciphering the CDT debugger alphabet soup
PDF
FreeBSD and Drivers
PPT
serial.ppt
D-bus basics
D bus specification
IPC with Qt
Your Watch can watch you ! Gear up for broken privilege pitfalls in the samsu...
UE4 Twitch 2016 05-05: Unreal Message Bus Overview
EclipseCon 2011: Deciphering the CDT debugger alphabet soup
FreeBSD and Drivers
serial.ppt

Similar to D-Bus Usage and Debug Introduction @ COSCUP 2024 (20)

PPT
serial.ppt
DOC
M-Bus Tool User's Guide
PDF
From Silicon to Software - IIT Madras
PDF
Freesmartphone.org
PPT
Linux Kernel Debugging
PPT
Arbitration in computer organization
PDF
A22 Introduction to DTrace by Kyle Hailey
PPT
UART Protocol For Serial Communication.ppt
PPT
lesson01.ppt
DOCX
Bsdtw17: george neville neil: realities of dtrace on free-bsd
PPTX
serial_busses_i2c.pptx
PDF
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
PPTX
Computer system bus
PDF
freertos-proj.pdf
PPTX
Serial Busses.pptx
PDF
Freeswitch
PDF
10 system bus.pdf
PPTX
businterconnection ppt.pptx
PDF
Debugging embedded devices using GDB
PDF
Real practice of Networking design on specialized for ARM Cortex-M
serial.ppt
M-Bus Tool User's Guide
From Silicon to Software - IIT Madras
Freesmartphone.org
Linux Kernel Debugging
Arbitration in computer organization
A22 Introduction to DTrace by Kyle Hailey
UART Protocol For Serial Communication.ppt
lesson01.ppt
Bsdtw17: george neville neil: realities of dtrace on free-bsd
serial_busses_i2c.pptx
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
Computer system bus
freertos-proj.pdf
Serial Busses.pptx
Freeswitch
10 system bus.pdf
businterconnection ppt.pptx
Debugging embedded devices using GDB
Real practice of Networking design on specialized for ARM Cortex-M
Ad

More from Jian-Hong Pan (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
國稅局,我也好想用電腦報稅
PDF
Share the Experience of Using Embedded Development Board
PDF
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
PDF
Launch the First Process in Linux System
PDF
Let's trace Linux Lernel with KGDB @ COSCUP 2021
PDF
A Journey to Boot Linux on Raspberry Pi
PDF
Have a Simple Modbus Server
PDF
Software Packaging for Cross OS Distribution
PDF
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
PDF
LoRaWAN class module and subsystem
PDF
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
PDF
The Considerations for Internet of Things @ 2017
PDF
Build a Micro HTTP Server for Embedded System
PDF
Micro HTTP Server Implemented in C @ COSCUP 2016
PDF
Bind Python and C @ COSCUP 2015
PDF
Find the bottleneck of your system
PDF
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
PDF
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
PDF
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
國稅局,我也好想用電腦報稅
Share the Experience of Using Embedded Development Board
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Launch the First Process in Linux System
Let's trace Linux Lernel with KGDB @ COSCUP 2021
A Journey to Boot Linux on Raspberry Pi
Have a Simple Modbus Server
Software Packaging for Cross OS Distribution
Nasa Hackthon 2018 Light Wonder - Go! Polar Bear!
LoRaWAN class module and subsystem
Let's Have an IEEE 802.15.4 over LoRa Linux Device Driver for IoT
The Considerations for Internet of Things @ 2017
Build a Micro HTTP Server for Embedded System
Micro HTTP Server Implemented in C @ COSCUP 2016
Bind Python and C @ COSCUP 2015
Find the bottleneck of your system
Learn How to Develop Embedded System for ARM @ 2014.12.22 JuluOSDev
Debug C/C++ Programs More Comfortably @ 2014.12.14 Trace Code Meetup
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Ad

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administration Chapter 2
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
System and Network Administraation Chapter 3
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPT
Introduction Database Management System for Course Database
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
2025 Textile ERP Trends: SAP, Odoo & Oracle
CHAPTER 2 - PM Management and IT Context
Digital Systems & Binary Numbers (comprehensive )
Introduction to Artificial Intelligence
System and Network Administration Chapter 2
L1 - Introduction to python Backend.pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Choose the Right IT Partner for Your Business in Malaysia
Reimagine Home Health with the Power of Agentic AI​
Computer Software and OS of computer science of grade 11.pptx
System and Network Administraation Chapter 3
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Wondershare Filmora 15 Crack With Activation Key [2025
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Introduction Database Management System for Course Database

D-Bus Usage and Debug Introduction @ COSCUP 2024

  • 1. D-Bus Usage and Debug Introduction 潘建宏 Jian-Hong Pan (StarNight) @ COSCUP 2024
  • 2. Who am I 潘建宏 / Jian-Hong Pan (StarNight) Endless OS Foundation You can find me at ● http://www.slideshare.net/chienhungpan/ ● GitHub: starnight ● X: starnight_pan ● Email: jhp [AT] endlessos.org chienhung.pan [AT] gmail.com
  • 3. Agenda 1. How to implement Inter Proccess Communication (IPC) 2. What is D-Bus a. Resource Addressing b. Message Bus c. Data Types d. Message Types 3. Debug Tools 4. Write D-Bus Applications 5. Reference
  • 4. Inter Process Communication (IPC) A process communicates with another process for exchanging information. How to implement? ● Share memory between the processes ● The processes write and read the same file ● Pipeline ● Communicate with Sockets ● How about with a library, such as D-Bus library?
  • 5. Why D-Bus? ● Based on UNIX Domain socket ● Ecosystem uses it widely ○ systemd, Desktop Environment: GNOME, KDE … ● Server-client architecture ● Data serialization format ● Method call communication and broadcasting mechanism
  • 6. This slide is more like a note extracted from D-Bus Specification & D-Bus Tutorial
  • 7. D-Bus is ● A message bus system, a simple way for applications to talk to one another. ● A system for interprocess communication (IPC). Architecturally, it has several layers: ○ A library, libdbus, that allows two applications to connect to each other and exchange messages. ○ A message bus daemon executable, built on libdbus, that multiple applications can connect to. The daemon can route messages from one application to zero or more other applications. ○ Wrapper libraries or bindings based on particular application frameworks. Some reimplement by following D-Bus specification, such as GLib’s built-in D-Bus library GDBus. There are also bindings to languages such as Python, Go, Rust ...
  • 8. D-Bus Supplies Bus Types ● System daemon (for system related things) ○ NetworkManager, UPower, udisks … ● Per-user-login-session daemon (for general IPC needs among user applications) ○ GNOME Files, IBus … ● Some applications use both: ○ systemd, GNOME Control Center (Settings), GNOME Shell …
  • 9. Resource Addressing: Bus, Object, Interface ● Bus Name: When each application connects to the bus daemon, the daemon immediately assigns it a name, called the unique connection name. A unique name begins with a ':' (colon) character, for example, ‘:34.907’. The application may ask to own additional well-known names, for example ’com.example.foo’. Then, ’com.example.foo’ maps to ‘:34.907’. Just like DNS maps to IP. ● Object Path: The application should have an object at supporting interfaces. Here is an object path example: ’/com/example/foo’. ● Interface: Each object supports one or more interfaces. An interface holds some members: Methods, Signals, Properties … For example, ’com.example.foo.property1’. Note: The names and path should start like with the reversed DNS domain name.
  • 10. D-Bus Message Bus Process B Process A Interface com.example.foo: Method, Property1, Signal … Object: /com/example/foo Bus Name: com.example.foo maps to :34.907
  • 11. Example: Enumerate power devices $ dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.EnumerateDevices method return time=1719720362.974990 sender=:1.28 -> destination=:1.120 serial=333 reply_serial=2 array [ object path "/org/freedesktop/UPower/devices/battery_BAT0" object path "/org/freedesktop/UPower/devices/line_power_AC" object path "/org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001" ]
  • 12. $ dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.DBus.Properties.GetAll string:org.freedesktop.UPower.Device method return time=1719721654.476315 sender=:1.28 -> destination=:1.126 serial=432 reply_serial=2 array [ dict entry( string "NativePath" variant string "BAT0" ) … dict entry( string "Percentage" variant double 100 ) …
  • 13. $ dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.DBus.Properties.Get string:org.freedesktop.UPower.Device string:Percentage method return time=1719840496.847174 sender=:1.29 -> destination=:1.164 serial=154 reply_serial=2 variant double 100
  • 14. Message Bus ● The message bus accepts connections from one or more applications. Once connected, applications can exchange messages with other applications that are also connected to the bus. ● In order to route messages among connections, the message bus keeps a mapping from names to connections. ● The bus itself owns a special name, org.freedesktop.DBus, with an object located at /org/freedesktop/DBus that implements the org.freedesktop.DBus interface. This service allows applications to make administrative requests of the bus itself. For example, applications can ask the bus to assign a name to a connection. ● Message bus daemon: dbus-daemon, dbus-broker …
  • 15. Standard Interfaces There are some standard interfaces across various D-Bus applications: ● org.freedesktop.DBus.Introspectable ● org.freedesktop.DBus.Properties ● …
  • 16. org.freedesktop.DBus.Introspectable interface ● org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data) Objects instances may implement Introspect which returns an XML description of the object, including its interfaces (with signals and methods), objects below it in the object path tree, and its properties. The section “Introspection Data Format” describes the format of this XML string.
  • 18. org.freedesktop.DBus.Properties interface Many native APIs will have a concept of object properties or attributes. These can be exposed via this interface. ● org.freedesktop.DBus.Properties.Get (in STRING interface_name, in STRING property_name, out VARIANT value) ● org.freedesktop.DBus.Properties.Set (in STRING interface_name, in STRING property_name, in VARIANT value) ● org.freedesktop.DBus.Properties.GetAll (in STRING interface_name, out ARRAY of DICT_ENTRY<STRING,VARIANT> props) If one or more properties change on an object, the org.freedesktop.DBus.Properties.PropertiesChanged signal may be emitted: org.freedesktop.DBus.Properties.PropertiesChanged (STRING interface_name, ARRAY of DICT_ENTRY<STRING,VARIANT> changed_properties, ARRAY<STRING> invalidated_properties)
  • 19. Type System ● Basic types BYTE: ‘y’, BOOLEAN: ‘b’, INT16: ‘n’, UINT16: ‘q’, INT32: ‘i’, UINT32: ‘u’, INT64: ‘x’, UINT64: ‘t’, DOUBLE: ‘d’, UNIX_FD: ‘h’ ● String-like types STRING: ‘s’, OBJECT_PATH: ‘o’, SIGNATURE: ‘g’ ● Container types STRUCT: “(ii)”, Nested STRUCT “(i(ii))”, Array of INT32: “ai”, Array of STRUCT: “a(ii)”, Array of array of INT32: “aai”, VARIANT: ‘v’, DICT_ENTRY: “{<key type><value type>}”
  • 20. Big Conceptual Picture A particular method call on a particular object instance: Address -> [Bus Name] -> Object Path -> Interface -> Method Address: A D-Bus address specifies where a server will listen, and where a client will connect. For example, the address unix:path=/tmp/abcdef specifies that the server will listen on a UNIX domain socket at the path /tmp/abcdef and the client will connect to that socket. An address can also specify TCP/IP sockets, or any other transport defined in future iterations of the D-Bus specification.
  • 21. D-Bus’ UNIX Socket Domain Examples $ ss -a | grep dbus u_str ESTAB 0 0 /run/user/1000/.dbus-proxy/session-bus-proxy-Z5DOQ2 3576 * 19926 u_str ESTAB 0 0 /run/dbus/system_bus_socket 812 * 811 u_str ESTAB 0 0 /run/user/1000/.dbus-proxy/system-bus-proxy-N7DOQ2 20773 * 8687 u_str ESTAB 0 0 /run/dbus/system_bus_socket 815 * 5448 …
  • 22. Message Types ● METHOD_CALL ● METHOD_RETURN ● ERROR ● SIGNAL
  • 23. METHOD_CALL, METHOD_RETURN & ERROR ● METHOD_CALL messages ask to invoke a method on an object. ● METHOD_RETURN messages return the results of invoking a method. ● Or, ERROR messages return an exception caused by invoking a method. D-Bus client D-Bus server METHOD_CALL METHOD_RETURN, or ERROR
  • 24. SIGNALS SIGNAL messages are notifications that a given signal has been emitted (that an event has occurred). It is like an "event" message. D-Bus server D-Bus client A, B, C … broadcast SIGNAL
  • 25. D-Bus Message Bus Process B METHOD_CALL Process C Process X@# Process A Interface a: Methods, Signals, Properties … Interface b: Methods, Signals, Properties … . . . Interface c: Methods, Signals, Properties … Object #1 Object #N Bus Name Broadcast Signal Process D Interface: ,,. , Interface: … . Bus Name
  • 26. D-Bus Debug Tools ● dbus-monitor ● gdbus ● Bustle: Can be installed via flatpak ● D-Bus Spy ● D-Spy: Can be installed via flatpak
  • 27. dbus-monitor Monitors (Un)Plugging USB Storage $ sudo dbus-monitor --system "path='/org/freedesktop/UDisks2'" … signal time=1711795582.184807 sender=:1.62 -> destination=(null destination) serial=205 path=/org/freedesktop/UDisks2; interface=org.freedesktop.DBus.ObjectManager; member=InterfacesAdded object path "/org/freedesktop/UDisks2/drives/General_UDisk_General_UDisk_0_3a0" array [ dict entry( string "org.freedesktop.UDisks2.Drive" array [ … dict entry( string "Serial" variant string "General_UDisk-0:0" ...
  • 30. ChatDBus Room as an Example ● gdbus-server: https://github.com/starnight/gdbus-server ● gdbus-client: https://github.com/starnight/gdbus-client ● pydbus-client: https://github.com/starnight/pydbus-client
  • 31. Scenario D-Bus client #1 SendMsg method D-Bus client #2 D-Bus server MsgNotification Signal
  • 32. Some GDBus API (Server Side) ● g_bus_own_name (): Acquire "Bus Name" on the bus. ● g_dbus_node_info_new_for_xml (): Parses the introspection XML and returns a GDBusNodeInfo representing the data. ● g_dbus_connection_register_object (): Registers callbacks in the virtual table (↓) for exported objects at "Object Path" with the D-Bus interface that is described in interface information. ● struct GDBusInterfaceVTable { GDBusInterfaceMethodCallFunc method_call; GDBusInterfaceGetPropertyFunc get_property; GDBusInterfaceSetPropertyFunc set_property; } ● g_dbus_connection_emit_signal ()
  • 33. Some GDBus API (Client Side) ● g_dbus_proxy_new_for_bus_sync (): Creates a proxy for accessing the Interface on the remote Object owned by the Bus name. ● g_dbus_proxy_get_cached_property () ● g_dbus_proxy_set_cached_property () ● g_dbus_proxy_get_connection (): Gets the connection proxy is for. ● g_dbus_connection_call_sync (): Synchronously invokes the Method on the Interface on the remote Object owned by the Bus name. ● g_dbus_proxy_call_sync (): Synchronously invokes the Method on proxy. ● g_signal_connect (): Connects a GCallback function to a Signal for a particular object.
  • 34. Reference ● D-Bus ○ D-Bus Specification ■ Message Bus Starting Services (Activation) ○ D-Bus Overview ○ D-Bus Tutorial ● D-Bus API Design Guidelines ● GLib ● dbus-send, dbus-monitor, Bustle and D-Spy ● pydbus ● gdbus-codegen