Commit Graph

403 Commits

Author SHA1 Message Date
Stanislav Angelovič
bce1da5a2e fix(ci): rename cmake parameters 2024-02-16 19:05:37 +01:00
Stanislav Angelovič
c8fb8caeb9 docs: add v2 migration notes to the tutorial 2024-02-16 18:59:19 +01:00
Stanislav Angelovič
fbb4a23e62 refactor: rename connection creation methods (#406)
This PR makes things around connection factories a little more consistent and more intuitive:

    * createConnection() has been removed. One shall call more expressive createSystemConnection() instead to get a connection to the system bus.
    * createDefaultBusConnection() has been renamed to createBusConnection(), so as not to be confused with libsystemd's default_bus, which is a different thing (a reusable thread-local bus).

Proxies still by default call createBusConnection() to get a connection when the connection is not provided explicitly by the caller, but now createBusConnection() does a different thing, so now the proxies connect to either session bus or system bus depending on the context (as opposed to always to system bus like before).
2024-02-16 18:57:51 +01:00
Stanislav Angelovič
341a1f3aee chore: update ChangeLog for v2.0.0 (#405) 2024-02-16 09:28:16 +01:00
Stanislav Angelovič
e62525ca4f chore: reorder some API functions (#404)
In sdbus-c++ v1, new virtual functions (e.g. overloads of existing virtual functions) were always placed at the end of the class to keep backwards ABI compatibility. Now, with v2, these functions are reordered and functions forming a logical group are together.
2024-02-16 09:27:45 +01:00
Stanislav Angelovič
e50ce7c37f chore: rename COMPONENTs in CMake (#402) 2024-02-10 20:30:22 +01:00
Stanislav Angelovič
2ff5a09432 refactor: remove deprecated API stuff (#403) 2024-02-10 20:27:14 +01:00
Stanislav Angelovič
10f701df74 refactor: rename and re-organize CMake options (#401)
This improves usability of sdbus-c++ in downstream CMake projects. CMake options now have `SDBUSCPP_` prefix so potential conflicts with downstream options/variables are minimized. Also, all configurable options and variables are placed in a single place in the root CMake file.
2024-02-10 20:20:42 +01:00
Stanislav Angelovič
94b8058dc5 refactor: use optional for passing potential call errors (#396)
This switches from a raw pointer to std::optional type to pass prospective call errors to the client (using std::optional was not possible years back when sdbus-c++ was based on C++14). This makes the API a little clearer, safer, idiomatically more expressive, and removes potential confusion associated with raw pointers (like ownership, lifetime questions, etc.).
2024-01-10 15:43:37 +01:00
Stanislav Angelovič
cda14c9702 refactor: add nodiscard attribute for more functions 2024-01-10 15:07:30 +01:00
Stanislav Angelovič
4b6fa20491 refactor: use correct header include order 2024-01-10 15:07:30 +01:00
Stanislav Angelovič
7c402b5ba9 refactor: add Async suffix to async callMethod functions (#394)
This makes naming consistent, so all asynchronously working functions have Async suffix
2024-01-08 09:28:19 +01:00
Stanislav Angelovic
f7afe3d1b1 refactor: add nodiscard attribute for some functions 2023-12-30 21:11:02 +01:00
Stanislav Angelovic
18aece04d5 chore: remove legacy comments 2023-12-30 21:11:02 +01:00
Stanislav Angelovic
9092bbd44c refactor: remove deprecated dont_request_slot_t tag 2023-12-30 21:11:02 +01:00
Stanislav Angelovic
fe773958d1 refactor: rename request_slot tag to return_slot 2023-12-30 21:11:02 +01:00
Stanislav Angelovič
bdd0bc2c27 refactor: improve Proxy signal subscription (#389)
This makes D-Bus proxy signal registration more flexible, more dynamic, and less error-prone since no `finishRegistration()` call is needed. A proxy can register to a signal at any time during its lifetime, and can unregister freely by simply destroying the associated slot.
2023-12-30 21:11:02 +01:00
Stanislav Angelovič
e3040c0998 refactor: improve Object vtable registration (#388)
This improves the D-Bus object API registration/unregistration by making it more flexible, more dynamic, closer to sd-bus API design but still on high abstraction level, and -- most importantly -- less error-prone since no `finishRegistration()` call is needed anymore.
2023-12-30 21:11:02 +01:00
Stanislav Angelovič
29bae0aaa8 fix: add missing header to ScopeGuard.h 2023-12-30 21:11:02 +01:00
Stanislav Angelovič
8affda1678 refactor: use sd_bus_match_signal() for signal registration (#372)
sd_bus_match_signal() is more convenient than more general sd_bus_add_match() for signal registration, and requires less code on our side. Plus, systemd of at least v238 is required for sdbus-c++ v2, and this version already ships with sd_bus_match_signal().
2023-12-30 21:11:02 +01:00
Stanislav Angelovič
58358eefa1 refactor: make Variant constructor explicit (#370)
This makes the library more robust and prone to user's errors when the user writes an extension for their custom type. In case they forget to implement a serialization function for that type and yet insert an object of that type into sdbus::Message, the current behavior is that, surprisingly, the library masks the error as it resolves the call to the Variant overload, because Variant provides an implicit template converting constructor, so the library tries to construct first the Variant object from the object of custom type, and then inserting into the message that Variant object. Variant constructor serializes the underlying object into its internal message object, which resolves to the same message insertion overload, creating an infinite recursion and ultimately the stack overflow. This is undesired and plain wrong. Marking this Variant converting constructor solves these problems, plus in overall it makes the code a little safer and more verbose. With explicit Variant constructor, when the user forgets to implement a serialization function for their type, the call of such function will fail with an expressive compilation error, and will produce no undesired, surprising results.
2023-12-30 21:11:02 +01:00
Stanislav Angelovič
8c8e40dc9d fix(tests): enable skipped test for Clang and FreeBSD (#369)
The test now works with Clang, libc++ and -O2 optimization, since the underlying implementation has been completely re-designed and doesn't suffer from that problem anymore.
2023-12-30 21:11:02 +01:00
Stanislav Angelovič
f38d578478 refactor: simplify async call state flag (#368)
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.
2023-12-30 21:11:02 +01:00
Stanislav Angelovič
071e38c9de refactor: let callbacks take message objects by value (#367)
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.
2023-12-30 21:11:02 +01:00
Stanislav Angelovic
21dd77ba6c refactor: use sd-bus API to get current message 2023-12-30 21:11:02 +01:00
Marcel Hellwig
2ef0e78ad2 fix: update cmake version for library to 2.0.0
This will also install the library as `libsdbus-c++.so.2.0.0`, which
represents the actual version of this library
2023-12-30 21:11:02 +01:00
Marcel Hellwig
ab2032592b fix: prevent installing a time event, when there's no need for a timeout
See #324 for discussion
2023-12-30 21:11:02 +01:00
Stanislav Angelovič
a7ae2ef79f chore: require cmake v3.14 and use FetchContent_MakeAvailable 2023-12-30 21:11:02 +01:00
Stanislav Angelovič
e87a252493 test: support new googletest git tags 2023-12-30 21:11:02 +01:00
Stanislav Angelovič
37a7b311d6 ci: build googletest manually on older ubuntus 2023-12-30 21:11:02 +01:00
Stanislav Angelovič
e95024192c feat: introduce sd-event integration 2023-12-30 21:11:02 +01:00
Stanislav Angelovic
8d24b2826e chore: enable actions on release/v2.0 branch 2023-12-30 21:11:02 +01:00
Stanislav Angelovic
0f99724449 refactor: simplify async D-Bus connection handling 2023-12-30 21:10:51 +01:00
Stanislav Angelovič
28921ad424 fix: request name signal handling issue (#392)
In case a signal arrives during the `RequestName` or `ReleaseName` D-Bus call (which is a synchronous call), the signal may not be processed immediately, which is a bug. This is solved now by waking up the event loop.
2023-12-30 17:37:00 +01:00
Stanislav Angelovič
721f583db1 refactor: handle exceptions correctly also in match callback handlers (#386)
This is a follow-up to #375. It covers match callback handlers that were missed in #375.
2023-12-05 19:06:41 +01:00
Stanislav Angelovič
47a84ab889 feat: implement Overload pattern in utils (#385) 2023-12-05 18:16:59 +01:00
Stanislav Angelovič
d80483cdc0 feat: extend ScopeGuard with success and failure overloads (#384) 2023-12-05 18:16:45 +01:00
Stanislav Angelovič
934d51fa8a chore: add INSTALL_TESTS CMake option (#382)
* Change default test installation path to tests/sdbus-c++ , while also respecting CMAKE_INSTALL_PREFIX
* Introduce INSTALL_TESTS CMake option, so BUILD_TESTS is now split into BUILD_TESTS just for building and INSTALL_TESTS for installing the test binaries

Per discussion in #358 (comment), the change in the default settings is fine a for a minor release.
2023-11-23 21:05:44 +01:00
FuchtelJockel
fb9e4ae371 fix: correctly add libsystemd dependency to pkgconfig (#378)
* fix: correctly add libsystemd dependency to pkgconfig

* refactor: solve sd-bus dependencies uniformly

---------

Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2023-11-20 14:41:59 +01:00
David Reiss
6e348f3910 refactor: minor UnixFd cleanups (#376)
* chore: Use std::exchange in UnixFd

This was suggested in code review for #376 .

* fix: Protect against UnixFd self-assignment

While self-assignment is rare, it is expected to be safe.  Add a check
to prevent putting the object in an invalid state.

* fix: Improve hygiene around dup system call

- Don't try to call dup on a negative value.
- Check dup return code and throw if it fails, rather than returning an
  empty UnixFd object.

* chore: Move UnixFd::close to Types.cpp

Minor convenience for applications: unistd.h doesn't have to be included
in the public header.

---------

Co-authored-by: David Reiss <dreiss@meta.com>
2023-11-18 18:11:00 +01:00
Alfred Wingate
f50e4676fe fix: add missing algorithm header include (#380)
* https://gcc.gnu.org/gcc-14/porting_to.html

Using gcc 14 uncovers a missing include in Message.h

Signed-off-by: Alfred Wingate <parona@protonmail.com>
2023-11-16 22:26:42 +01:00
Jan Beich
1aa30e3a20 chore(ci): run freebsd job on ubuntu 2023-11-10 16:01:33 +01:00
Stanislav Angelovič
e2b3e98374 refactor: improve handling of exceptions from callback handlers (#375)
* Catch and process all exceptions (not just sdbus::Error) from callback handlers
* Unify handling of exceptions from all types of callbacks -- always set sd_bus_error and return a negative result number in case of exception

Although libsystemd logs (with DEBUG severity) all errors from such callback handlers (except method callback handler), it seems to be out of our control. One of handy sdbus-c++ features could be the ability for clients to install a log callback, which sdbus-c++ would call in case of exceptions flying from callback handlers. In case something doesn't work for clients (especially novices), they can first look into these logs.

This may be handy in common situations like ignored signals on client side because of the inadvertent mismatch between real signal signature and signal handler signature. Like here: #373. (Although in this specific case of signals, there is a solution with an additional const sdbus::Error* argument that would reveal such an error.)
2023-11-03 18:03:01 +01:00
Stanislav Angelovič
9490b3351f feat: add support for async registration of matches (#374) 2023-11-03 17:57:52 +01:00
Stanislav Angelovič
9da18aec25 chore: remove obsolete TODO comments 2023-10-31 15:54:49 +01:00
Stanislav Angelovič
b7b454ba38 doc: add section on bus connection factories 2023-10-16 19:28:27 +02:00
Stanislav Angelovič
f420b216aa docs: update documentation 2023-10-16 15:30:23 +02:00
Stanislav Angelovič
b482cd6d08 chore: version 1.4.0 v1.4.0 2023-10-10 19:26:21 +02:00
Stanislav Angelovič
aac7e590ea docs: add recommendation on destroying direct D-Bus connections 2023-10-10 19:15:21 +02:00
David Reiss
0ad2553417 fix: use-after-return in synchronous calls (#362)
* 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>
2023-10-09 20:01:45 +02:00