* Add methods to initiate custom session bus connection
The new function helper `createSessionBusConnectionWithAddress` allows to create connection to session bus with custom address.
Signed-off-by: Alexander Livenets <a.livenets@gmail.com>
* feat: add support for session bus connection at custom address
Co-authored-by: Stanislav Angelovic <stanislav.angelovic@siemens.com>
* Since ObjectPath and Signature have a user-declared copy-ctor and copy
assignment operator the implicit declaration of corresponding move
operations is disabled. Explicitly add defaulted versions so that
move operations actually move instead of copy.
* See: https://github.com/Kistler-Group/sdbus-cpp/issues/230
fix timeout handling
* Despite what is documented in sd_bus_get_timeout(3), the timeout
returned is actually an absolute time point of Linux's CLOCK_MONOTONIC
clock. Hence, we first have to subtract the current time from the
timeout in order to get a relative time that can be passed to poll.
* For async call timeouts to reliably work, we need a way to notify the
event loop of a connection that is currently blocked waiting in poll.
I.e. assume the event loop thread entered poll with a timeout set to
T1. Afterwards, the main thread starts an async call C with a timeout
T2 < T1. In order for C to be canceled after its timeout T1 has
elapsed, we have to be able to notify the event loop so that it can
update its poll data.
Co-authored-by: Urs Ritzmann <ursritzmann@protonmail.ch>
Co-authored-by: Lukasz Marcul <lukasz.marcul@onemeter.com>
Even though they have the same value, they are something fundamentally different.
Therefore it is extremely confusing if the constant INTERFACE_NAME is passed
where actually a well-known BUS_NAME (destination) should go.
This internally calls sd_bus_open(), which automatically selects the
system or session bus connection based on the presence and
content of a DBUS_STARTER_BUS_TYPE environment variable and
whether the calling process has root privileges.
This option is very helpful when creating services and clients that will use the system bus in production, but connect to a session
for testing.
Additional changes:
* Removed assertions null-checking make_unique() return values.
make_unique() calls new, and new is expected to throw or abort
on failure, making the assertions unhelpful.
* Corrected a typo in the ClosesAndUnrefsBusWhenDestructed
unit test for the system bus (tested the wrong function).
* Add missing nullptr check in Message::peekType().
* According to its specification, sd_bus_message_peek_type() sets a
given contents parameter to NULL if the next element in a message is
not a container. Since assigning a nullptr to a std::string has
undefined behaviour (typically resulting in an invalid memory access),
Message::peekType() must not assign contentsSig unconditionally.
* fix: minor documentation and test improvements
* doc: add link to tests in standard interfaces tutorial secion
* Update README.md
Co-authored-by: Urs Ritzmann <urs.ritzmann@kistler.com>
* Update docs/using-sdbus-c++.md
Co-authored-by: Urs Ritzmann <urs.ritzmann@kistler.com>
* Use cmake instead of make in build instructions
Co-authored-by: Stanislav Angelovic <stanislav.angelovic@siemens.com>
Co-authored-by: Urs Ritzmann <urs.ritzmann@kistler.com>
* sdbus-cpp: Add API to get message credentials
Signed-off-by: Alexander Livenets <a.livenets@gmail.com>
* fix: add <sys/types.h> include for gid_t and other types
Co-authored-by: Stanislav Angelovič <angelovic.s@gmail.com>
* Proxy::sdbus_signal_handler() needs to return 0 instead of 1 in
order to allow multiple proxies listening to a signal all being
triggered.
* Add test for emitting a signal to multiple proxies on same
connection.
The underlying bus was thread_local, but the design assumption that Variants built on top of that instance won't outlive the thread was incorrect. In stress tests, Variants were moved (and this is completely legal) to a different thread.