* 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>
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>
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 construct/destruct order of mutex/data in AsnycCalls
Destroying a mutex which might still be owned leads to undefined behaviour.
It wasn't the case here but using the right order is more resistant to future bugs.
* proxy AsnycCalls: don't leave map in unspecified state
* fix 133: use thread-safe container for proxy interfaces list
* proxy callback payload uses concrete signalData
* proxy: revert adding the wrapper class InterfaceContainer
It's no longer required and simplifies the locking logic.
* Proxy: avoid additional lambda wrapper around signal callbacks
As proposed in
https://github.com/Kistler-Group/sdbus-cpp/pull/177#issuecomment-834439707
option 3.
Still TODO: Avoid relying on std::map's non-invalidatable by adding just
std::unique_ptr<Proxy::InterfaceData::SignalData> to the container.
* proxy: add missing underscore prefix
* proxy: put InterfaceData::SignalData into a unique_ptr
This ways, we avoid relying on std::map's non-invalidatable references.
* proxy: code style: get raw pointer directly
* style: fix code style
Co-authored-by: Stanislav Angelovic <stanislav.angelovic@siemens.com>
* Add API to get message path
* Add API to get message destination
* Handle NULL message fields interface and member
Functions sd_bus_message_get_interface() and sd_bus_message_get_member()
can return null in case the message does not use those fields or does
not have them set.
This provides access to the proxy's bus connection so code using
the proxy does not need to store an external reference to it.
A matching function is already available in IObject.
* 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>
This should not be required in C++17 because there is an appropriate
class template deduction rule [1] which infers that it's going to be a
weak_ptr<T> when constructing from a shared_ptr<T>. However, in
clang/LLVM's libcxx C++ STL implementation this only got implemented in
May 2020 [2].
[1] https://en.cppreference.com/w/cpp/memory/weak_ptr/deduction_guides
[2] https://reviews.llvm.org/D69603
* 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.