91 Commits

Author SHA1 Message Date
Stanislav Angelovič
48ea775531 feat: add createLightWeightProxy overload for convenience (#474) 2025-01-08 13:55:38 +01:00
Stanislav Angelovič
02ca7212d1 feat: introduce support for struct-as-dict serialization (#459)
This extends the functionality of SDBUSCPP_REGISTER_STRUCT macro.

It now provides functionality for serializing a user-defined struct as an a{sv} dictionary, and for deserializing an a{sv} dictionary into a user-defined struct. The former one is achieved by decorating the struct with sdbus::as_dictionary(struct), the latter one is an automatic behavior -- when sdbus-c++ is asked to deserialize into a struct but the data in the message is of type a{sv}, then the dict-to-struct deserialization is performed automatically.

There are some aspects of behavior in the serialization/deserialization functionality that can be customized by the client. Newly introduced SDBUSCPP_ENABLE_NESTED_STRUCT2DICT_SERIALIZATION and SDBUSCPP_ENABLE_RELAXED_DICT2STRUCT_DESERIALIZATION macros serve the purpose.
2024-11-20 23:25:13 +01:00
Stanislav Angelovič
1b7acaa735 fix: cleanup for older libsystemd versions (#454)
Fix inconsistencies in documentation and CMake files regarding minimum required libsystemd version (which is v238 for sdbus-c++ v2.0). Also fix compiler error bug in sdbus-c++ code when compiled against older libsystemd versions. Plus some extra related cleanups.
2024-09-15 14:13:49 +02:00
Laurence Crestani Tasca
e6b87b106c docs: fix examples in using-sdbus-c++.md (#441)
Update in using documentation to version v2.0 syntax making examples work out of the box
2024-05-13 23:51:59 +02:00
Stanislav Angelovič
14942db075 feat: add macro to teach sdbus-c++ about user-defined structs (#440)
This introduces SDBUSCPP_REGISTER_STRUCT macro that helps clients conveniently, in one line, teach sdbus-c++ to recognize and accept their custom C++ struct types wherever D-Bus structs are expected in a D-Bus API.

The macro saves some boilerplate that would otherwise be needed on client side for every registered struct.
2024-05-06 20:14:32 +02:00
Stanislav Angelovič
e62472b210 chore: fix partially renamed BUILD_DOXYGEN_DOC CMake option 2024-04-25 01:23:15 +02:00
Stanislav Angelovič
798eaf8626 refactor: remove floating_slot_t tag and use return_slot_t instead (#439)
Make all the API consistent by using return_slot_t-based overloads for returning the slots to clients, and overloads without that tag for "floating" slots. floating_slot_t tag was previously added for API backwards compatibility reasons, but now is a (counter-)duplicate to the return_slot_t.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
2bc9d3ebb3 refactor: object manager API (#438)
This makes the signature of addObjectManager() function overloads consistent with common API design of the library.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
0c75ad2b71 docs: fix generated class examples in the tutorial (#436) 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
84a6fbbf86 fix: disable move in generated adaptor and proxy classes (#435)
Moving adaptor or proxy instances changes their `this` pointer. But `this` is captured by value in closures used by those instances, and this remains unchanged on move, leading to accessing an invalid instance when a lambda expression executes. Supporting move semantics would require unsubscribing/unregistering vtable, handlers, etc. and re-subscribing and re-registering all that, which is too complicated and may have side effects. Hence it has been decided that these classes are not moveable. One may use an indirection with e.g. `std::unique_ptr` to get move semantics.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
83ece48ab0 feat: add Slot-returning overloads of async method calls (#433) 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
310161207a refactor: improve and make more efficient some Message API (#432) 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
7894cda577 perf: provide also const char* overloads for convenience functions 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
d856969051 refactor: enable compile-time D-Bus signature generation (#425)
Since sdbus-c++ knows types of D-Bus call/signal/property input/output parameters at compile time, why not assemble the D-Bus signature strings at compile time, too, instead of assembling them at run time as std::string with likely cost of (unnecessary) heap allocations...

std::array is well supported constexpr type in C++20, so we harness it to build the D-Bus signature string and store it into the binary at compile time.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
32a97f214f fix: make Variant conversion operator explicit (#428)
Having explicit conversion operator is a good practice according to the C++ core guidelines, as it makes the code safer and better follows the principle of least astonishment. Also, it is consistent with the standard library style, where wrappers like std::variant, std::any, std::optional... also do not provide an implicit conversion to the underlying type. Last but not least, it paves the way for the upcoming std::variant <-> sdbus::Variant implicit conversions without surprising behavior in some edge cases.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
42f0bd07c0 refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.

What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.

These types are:
  * `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
  * `InterfaceName` type for D-Bus interface names,
  * `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
  * `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
  * `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
  * `Error::Name` type for D-Bus error names.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
c433d26176 chore(cmake): implement more flexible searching for sd-bus libs (#409)
A new CMake configuration variable SDBUSCPP_SDBUS_LIB has been introduced that enables clients to specify which sd-bus implementation library shall be used by sdbus-c++.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
87500ad9ad docs: add v2 migration notes to the tutorial (#407) 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
9a5616a87a 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).

The integration tests were modified to use createBusConnection().
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
c205178fc0 chore: rename COMPONENTs in CMake (#402) 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
0074c79e7f 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-04-24 20:20:29 +02:00
Stanislav Angelovič
3de2812a60 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-04-24 20:20:29 +02:00
Stanislav Angelovic
dc0c2562b8 refactor: rename request_slot tag to return_slot 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
84932a6985 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.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
bdf313bc60 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.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
6f35f00fcf 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.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
b9aa770f58 feat: introduce sd-event integration 2024-04-24 20:20:29 +02:00
Stanislav Angelovic
3e20fc639e refactor: simplify async D-Bus connection handling 2024-04-24 20:20:29 +02:00
Anthony Brandon
a73eb9b8c1 feat: add support for std::variant as D-Bus variant representation (#415)
Signed-off-by: Anthony Brandon <anthony@amarulasolutions.com>
Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2024-04-01 13:23:08 +02: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č
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č
aac7e590ea docs: add recommendation on destroying direct D-Bus connections 2023-10-10 19:15:21 +02:00
Maksim Fedyarov
cfb71bd6cf feat: add support for direct connections (#350)
* feat: add support for direct connections

* refactor: simplify a bit, change comments, extend tests

* fix: compiler warning about unused variable

* docs: add section on direct connections to the tutorial

---------

Co-authored-by: Maksim Fedyarov <m.fedyarov@omp.ru>
Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2023-09-25 20:12:34 +02:00
Stanislav Angelovič
290078d6af feat: add support for async property get/set on client-side (#354)
* feat: add async property get/set convenience support classes

* feat: add no-reply and async overloads to Properties_proxy

* feat: add convenience functions for GetAll functionality

* test: add tests for new functionality

* add codegen IDL support and documentation
2023-09-14 10:54:57 +02:00
Stanislav Angelovič
3717e63c64 feat: support std::future-based async methods in codegen tool (#353) 2023-08-19 20:57:32 +02:00
Stanislav Angelovič
6620a447d1 docs: add tutorial on extending sdbus-c++ types (#346) 2023-08-09 12:13:47 +02:00
Marcel Hellwig
dcd9d46b9c style: remove trailing whitespace (#345)
* style: restore correct 644 file permission

* style: remove trailing whitespace
2023-08-04 13:26:45 +02:00
Stanislav Angelovič
fb61420bf0 feat: support serialization of array, span and unordered_map (#342)
* feat: support serialization of array, span and unordered_map

* fix some spelling mistakes

* docs: update table of valid c++ types

---------

Co-authored-by: Marcel Hellwig <github@cookiesoft.de>
2023-08-03 13:55:37 +02:00
Stanislav Angelovič
737f04abc7 feat: add support for std::future-based async calls 2023-02-07 12:31:31 +01:00
Stanislav Angelovic
55c306ce05 docs: strip absolute paths from doxygen documentation 2023-01-04 21:51:28 +01:00
Stanislav Angelovic
aeae79003a refactor: support move semantics in generated adaptor and proxy classes 2022-09-20 17:05:59 +02:00
Stanislav Angelovic
74d849d933 feat: add support for proxy with no event loop thread 2022-09-05 17:25:37 +02:00
b-s-e
f336811fc7 docs: add section on D-Bus types to C++ types mapping (#285)
* Added D-Bus type C++ type table

* docs: do corrections and rewordings in the proposed chapter

Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2022-09-05 13:51:05 +02:00
b-s-e
e33a890ce7 docs: fix send_destination property (#284) 2022-08-26 16:49:51 +02:00
Stanislav Angelovic
5ec6027d5f feat: add support for match rules 2022-06-27 12:14:57 +02:00
Stanislav Angelovic
2a4c241303 docs: add more info on D-Bus security policy file 2022-06-22 18:12:13 +02:00
Sergey Bobrenok
b5aee6d019 docs: add information about Buildroot package (#252) 2022-06-07 08:45:34 +02:00
Lukasz Marcul
442670ec18 codegen: Support chrono literal timeout by ProxyGenerator
Allow to use human readable chrono literals to specify method call
timeout. The change is backward compatbile - if no unit is provided,
the fallback is "us".

Example:
<annotation name="org.freedesktop.DBus.Method.Timeout" value="500ms"/>
2021-12-14 16:47:01 +01:00