Since synchronous D-Bus calls are simplified in v2.0 and no more implemented in terms of an async call, the issue reported in #362 is no more relevant, and we can return to the simple boolean flag for indicating a finished call.
Signatures of callbacks async_reply_handler, signal_handler, message_handler and property_set_callback were modified to take input message objects by value, as opposed to non-const ref.
The callee assumes ownership of the message. This API is more idiomatic, more expressive, cleaner and safer. Move semantics is used to pass messages to the callback handlers. In some cases, this also improves performance.
* fix: Use-after-return in synchronous calls
This bug was introduced by c39bc637b8 and can be reproduced by
configuring with
cmake -S . -B build -DBUILD_TESTS=yes -DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_FLAGS="-Wno-error=deprecated-copy -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope"
and running `cmake --buid build && cmake --build build -t test` or
`build/tests/sdbus-c++-integration-tests --gtest_filter=SdbusTestObject.HandlesCorrectlyABulkOfParallelServerSideAsyncMethods`
The issue is that `sdbus_async_reply_handler` can call `removeCall`, which
writes to `data->finished`, but `data` can point to the stack of
`sendMethodCallMessageAndWaitForReply`, which can return as soon as
`asyncCallData->callback` is called.
As a fix, I restored some of the logic removed in c39bc637b8.
Specifically, in `sdbus_async_reply_handler`, I make a copy of some data
from `asyncCallData` (a new `state` field instead of `slot`), and in the
`SCOPE_GUARD`, I don't call `removeCall` if the call was actually
synchronous.
* refactor: use enum class instead of int
---------
Co-authored-by: David Reiss <dreiss@meta.com>
Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
* chore: don't use systemd headers with elogind
In file included from src/VTableUtils.c:27:
src/VTableUtils.h:30:10: fatal error: 'systemd/sd-bus.h' file not found
#include <systemd/sd-bus.h>
^~~~~~~~~~~~~~~~~~
* chore: add basu support
Similar to elogind but also supported on non-Linux.
* chore(tests): permit /var/lib/machine-id on non-systemd
https://github.com/elogind/elogind/commit/84fdc0fc61c1https://git.sr.ht/~emersion/basu/commit/8324e6729231
* chore(ci): add simple freebsd job
Mainly to cover libc++ and basu.
* chore(ci): explicitly pass CMAKE_INSTALL_PREFIX
Some sdbus-cpp tests require configuring system bus. However, Linux
testing relies on writing outside of prefix in order to affect current
system bus instance instead of launching a dedicated one.
* chore(tests): respect CMAKE_INSTALL_PREFIX for system bus config
DBus isn't part of base system on BSDs, so may not use /etc for configs.
Also, testing installation failed as non-root:
$ cmake -DBUILD_TESTS=1 -DCMAKE_INSTALL_PREFIX=/tmp/sdbus-cpp_prefix -DTESTS_INSTALL_PATH=/tmp/sdbus-cpp_prefix/tests
$ cmake --build .
$ cmake --install .
[...]
CMake Error at tests/cmake_install.cmake:105 (file):
file cannot create directory: /etc/dbus-1/system.d. Maybe need
administrative privileges.
* chore(tests): temporarily skip 1 test on FreeBSD to keep CI happy
* chore(ci): run tests in freebsd job
* 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>
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.