#include <dbus.hpp>
Classes | |
| struct | PortalResult |
| Reply value for an xdg-desktop-portal request: the response code (0 = success, 1 = user cancelled, 2 = other) plus any returned URIs. More... | |
| class | Reader |
| Reads basic + container values out of an incoming message's argument list. More... | |
| class | Writer |
| Appends values to an outgoing message (reply or signal). More... | |
| class | CallContext |
| Context for one incoming method call against a registered object. More... | |
Public Types | |
| using | IncomingHandler = std::function<bool(CallContext& ctx)> |
| Handler for incoming method calls on a registered object path. | |
| using | SignalHandler |
| Handler invoked for each matching signal. | |
Public Member Functions | |
| DBus () | |
| ~DBus () | |
| bool | connect_session () |
| Connect to the session bus. | |
| bool | connect_system () |
| Connect to the SYSTEM bus. | |
| bool | connected () const |
| bool | connect_a11y_bus () |
| Switch this DBus over to the desktop accessibility ("a11y") bus. | |
| bool | a11y_connected () const |
| True iff this DBus is currently backed by the a11y bus connection (i.e. | |
| std::string | unique_name () const |
| This connection's unique bus name (e.g. | |
| std::optional< PortalResult > | file_chooser (const std::string &method, const std::string &title, const std::map< std::string, std::string > &options, const std::map< std::string, bool > &bool_options, int timeout_ms=120000) |
| Invoke org.freedesktop.portal.FileChooser. | |
| bool | register_object (const std::string &path, IncomingHandler handler) |
| Export an object at path; handler answers method calls routed to it. | |
| bool | unregister_object (const std::string &path) |
| Remove a previously registered object. Returns false if not registered. | |
| bool | emit_signal (const std::string &path, const std::string &interface, const std::string &member, const std::function< void(Writer &)> &build_args) |
| Emit a signal from path/interface/member. | |
| bool | dispatch (int timeout_ms=0) |
| Run the libdbus dispatcher once so registered object handlers fire and outgoing traffic flushes. | |
| bool | call_method (const std::string &destination, const std::string &path, const std::string &interface, const std::string &member, const std::function< void(Writer &)> &build_args, const std::function< void(Reader &)> &read_reply, int timeout_ms=5000) |
| Generic blocking method call (object-server companion to register_object). | |
| unsigned | add_signal_handler (const std::string &interface, const std::string &member, SignalHandler handler) |
| Subscribe to signals matching interface+member (member empty = any member of the interface). | |
| bool | remove_signal_handler (unsigned token) |
| Remove a signal handler previously returned by add_signal_handler(). | |
| bool | get_managed_objects (const std::string &destination, const std::string &path, const std::function< void(const std::string &obj_path, const std::string &interface)> &per_object, int timeout_ms=5000) |
| Call org.freedesktop.DBus.ObjectManager.GetManagedObjects on destination/path and invoke per_object(object_path, interface_name) for every (object, interface) pair discovered. | |
| DBus (const DBus &)=delete | |
| DBus & | operator= (const DBus &)=delete |
Static Public Member Functions | |
| static bool | library_available () |
| True iff libdbus-1 can be loaded right now (Linux dlopen probe). | |
| using pulp::platform::DBus::IncomingHandler = std::function<bool(CallContext& ctx)> |
Handler for incoming method calls on a registered object path.
Return true if the call was recognized + answered (via ctx.reply()/error()), false to decline — the server then replies UnknownMethod. A call is NEVER dropped silently.
Handler invoked for each matching signal.
args is a Reader positioned at the signal body; it is valid only for the duration of the call.
| pulp::platform::DBus::DBus | ( | ) |
| pulp::platform::DBus::~DBus | ( | ) |
|
delete |
| bool pulp::platform::DBus::a11y_connected | ( | ) | const |
True iff this DBus is currently backed by the a11y bus connection (i.e.
connect_a11y_bus() succeeded). False on the plain session connection.
| unsigned pulp::platform::DBus::add_signal_handler | ( | const std::string & | interface, |
| const std::string & | member, | ||
| SignalHandler | handler ) |
Subscribe to signals matching interface+member (member empty = any member of the interface).
Adds the org.freedesktop.DBus match rule and routes matching signals to handler during dispatch(). Returns a token (>0) to pass to remove_signal_handler(); returns 0 off Linux / without a connection.
| bool pulp::platform::DBus::call_method | ( | const std::string & | destination, |
| const std::string & | path, | ||
| const std::string & | interface, | ||
| const std::string & | member, | ||
| const std::function< void(Writer &)> & | build_args, | ||
| const std::function< void(Reader &)> & | read_reply, | ||
| int | timeout_ms = 5000 ) |
Generic blocking method call (object-server companion to register_object).
Sends member on destination/path/interface, marshalling the body via build_args, and blocks up to timeout_ms for the reply; the reply arguments are handed to read_reply (may be null to ignore the body). Returns false off Linux / without a connection / on transport or D-Bus error (e.g. the peer returned an error reply). This is the call needed to drive a handshake such as AT-SPI's Socket.Embed where the app both exports objects AND calls out to a registry.
| bool pulp::platform::DBus::connect_a11y_bus | ( | ) |
Switch this DBus over to the desktop accessibility ("a11y") bus.
The a11y bus is a SECOND D-Bus daemon, separate from the session bus: its address is discovered by calling org.a11y.Bus.GetAddress on the session bus, then a fresh private connection is opened to that address. AT-SPI (Orca and friends) lives entirely on this bus — the registry, the app's exported accessible objects, and the event traffic all flow over it, never the session bus.
After this returns true, the connection backing register_object / unregister_object / emit_signal / dispatch / unique_name is the a11y connection (the session connection used to discover the address is closed). connect_session() must have succeeded first.
Returns false off Linux, without libdbus, when there is no session bus, when org.a11y.Bus is absent (a headless host with no a11y daemon), or when the returned address cannot be opened — i.e. honest-fail, so a non-accessibility desktop simply yields a no-op provider.
| bool pulp::platform::DBus::connect_session | ( | ) |
Connect to the session bus.
Returns false off Linux, without libdbus, or when no session bus is reachable. Idempotent (returns true if already connected).
| bool pulp::platform::DBus::connect_system | ( | ) |
Connect to the SYSTEM bus.
System services (BlueZ / org.bluez, UPower, NetworkManager, …) live on the system bus, not the per-login session bus, so a client that needs to talk to them connects here instead of connect_session(). Returns false off Linux, without libdbus, or when no system bus is reachable. Idempotent (returns true if already connected). A given DBus connects to exactly one bus — call this XOR connect_session().
| bool pulp::platform::DBus::connected | ( | ) | const |
| bool pulp::platform::DBus::dispatch | ( | int | timeout_ms = 0 | ) |
Run the libdbus dispatcher once so registered object handlers fire and outgoing traffic flushes.
Blocks up to timeout_ms waiting for I/O (0 = non-blocking poll). Returns false off Linux / without a connection. This is the object-server consumption model; do NOT interleave it with the portal file_chooser pop_message pump on the same pending traffic.
| bool pulp::platform::DBus::emit_signal | ( | const std::string & | path, |
| const std::string & | interface, | ||
| const std::string & | member, | ||
| const std::function< void(Writer &)> & | build_args ) |
Emit a signal from path/interface/member.
build_args appends the signal body via the Writer. Returns false off Linux / without a connection / on marshalling or send failure.
| std::optional< PortalResult > pulp::platform::DBus::file_chooser | ( | const std::string & | method, |
| const std::string & | title, | ||
| const std::map< std::string, std::string > & | options, | ||
| const std::map< std::string, bool > & | bool_options, | ||
| int | timeout_ms = 120000 ) |
Invoke org.freedesktop.portal.FileChooser.
<method> ("OpenFile" or "SaveFile") and block until the portal's Response signal arrives (or timeout_ms elapses). options are string→string entries marshalled as the portal's a{sv} with string variants; bool_options are marshalled as boolean variants (e.g. {"multiple", true} / {"directory", true}). Returns std::nullopt on any transport error (no portal, disconnect, …).
| bool pulp::platform::DBus::get_managed_objects | ( | const std::string & | destination, |
| const std::string & | path, | ||
| const std::function< void(const std::string &obj_path, const std::string &interface)> & | per_object, | ||
| int | timeout_ms = 5000 ) |
Call org.freedesktop.DBus.ObjectManager.GetManagedObjects on destination/path and invoke per_object(object_path, interface_name) for every (object, interface) pair discovered.
Property values are skipped (callers re-query specific props via call_method as needed). Returns false off Linux / on transport error.
|
static |
True iff libdbus-1 can be loaded right now (Linux dlopen probe).
Always false off Linux. Cheap; does not connect.
| bool pulp::platform::DBus::register_object | ( | const std::string & | path, |
| IncomingHandler | handler ) |
Export an object at path; handler answers method calls routed to it.
Re-registering a path replaces its handler. Returns false off Linux / without a connection / if libdbus rejects the path.
| bool pulp::platform::DBus::remove_signal_handler | ( | unsigned | token | ) |
Remove a signal handler previously returned by add_signal_handler().
Returns false off Linux / for an unknown token. The match rule is left in place (harmless extra delivery; removing it precisely would require reference-counting identical rules across tokens).
| std::string pulp::platform::DBus::unique_name | ( | ) | const |
This connection's unique bus name (e.g.
":1.42"), assigned by the broker at connect time. Empty when not connected / off Linux. Needed so a peer (or this same process, in a loopback test) can address method calls at us.
| bool pulp::platform::DBus::unregister_object | ( | const std::string & | path | ) |
Remove a previously registered object. Returns false if not registered.