Examples using the sdbus-cpp library to communicate with the system bus.
This approach uses XML interface files to create proxy classes. All members, signals, and properties are available. No introspection is used at runtime.
The basics
- AVAHI - query for services and get state changes
- BlueZ - discover devices and dump all properties
- GeoClue2 - start a location session and print updates
- hostname1 - get the current hostname and get runtime updates
- locale1 - get the current locale and get runtime updates
- login1 - access the login1 interface and get runtime updates
- NetworkManager - access objects and properties
- resolve1 - resolve a hostname to an IP address
- timedate1 - get the current time and get runtime updates
- UPower - get the current battery status and get runtime updates
- UDisks2 - get all disk info and runtime updates
https://github.com/jwinarske/sdbus-cpp-examples.git
git submodule update --init --recursive
mkdir build && cd build
cmake .. -GNinja
ninja
The proxy classes in src/proxy/ are generated ahead of time from the XML in
interfaces/ and committed to the repository. To regenerate them, build the
regenerate-proxies target — it builds the sdbus-c++-xml2cpp tool as needed:
cmake -B build -GNinja
cmake --build build --target regenerate-proxies
Regeneration is intentionally not part of the default build (it rewrites tracked
source files). The interface-to-proxy mapping lives in cmake/GenerateProxies.cmake;
add a new interface by appending a pair there.
If you re-generate against a different version of sdbus-cpp, likely you will need to make source code changes. This is the primary reason for using sdbus-cpp as a submodule.
Share unix socket of remote device
sudo ssh -nNT -L /root/dbus_on_local:/run/dbus/system_bus_socket root@raspberrypi5.lan
Install d-spy, run as root
sudo d-spy
Select Bus Names v Connect to Other Bus adding
unix:path=/root/dbus_on_local