463 Commits

Author SHA1 Message Date
Stanislav Angelovič
c2bb343f8a feat: add support for dumping variant to string (#526)
This allows Message and Variant contents serialization to a string -- based on `sd_bus_message_dump` sd-bus API function.
2026-01-15 23:24:54 +01:00
Stanislav Angelovič
9f3e89eb6a feat: use clang-tidy for static analysis (#495) 2026-01-15 14:38:33 +01:00
Michael Nosthoff
6f694e3fd3 fix: add deduction guides for Struct from std::tuple (#525)
* Types.h: add deduction guides for Struct from std::tuple

C++23 changed the generation of implicit deduction guides. This causes
the compiler to also see deduction guides for std::tuple as candidates
for sdbus::Struct.
Because of the competing guides the compiler doesn't know which one to pick.

This seems to be implemented from gcc 15 on and is thus causing breakage there.

To fix this we need to add explicit deduction guides when std::tuple is passed
to sdbus::Struct.

fixes https://github.com/Kistler-Group/sdbus-cpp/issues/524

* refactor: remove std::decay_t wrapper

We need to be able to create sdbus::Structs
with element types being references.

---------

Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2026-01-15 12:39:22 +01:00
Robert Adam
44aa4f080f feat(cmake): add export support (#523)
* feat: add export support

This makes sdbus-c++ consumable from the build tree without the need for
an explicit installation. This can be very handy for e.g. testing
purposes. Crucially, downstream projects will depend on upstream to
properly export everything. Otherwise, they can't be built as static
libraries, even if sdbus-c++ is only a private dependency.

See also https://runebook.dev/en/docs/cmake/command/export

* fix(cmake): avoid possibly empty EXPORT_SET

EXPORT_SET is empty when SDBUSCPP_INSTALL is OFF,
which leads to targets file with no targets.

---------

Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2026-01-06 20:11:05 +01:00
Robert Adam
6715ef1fc3 feat: create cmake alias for consistent downstream usage (#522)
At the moment, downstream projects will have to differentiate based off the way the obtained sdbus-c++ in CMake. If they use `find_package`, the target they have to use is `SDBusCpp::sdbus-c++`, whereas the target is merely `sdbus-c++` if they use `FetchContent` (i.e. use without installation).

By creating an alias target, it is now always possible to use the `DBusCpp::sdbus-c++` target regardless of how the library was obtained.
2025-12-31 12:48:26 +01:00
Stanislav Angelovič
28b78822cf chore: release version v2.2.1 v2.2.1 2025-11-21 18:14:15 +01:00
Alexey
70750e4557 fix: invalid cpack configuration inside CMakeLists.txt (#521)
* Change CPACK_COMPONENTS_ALL variable in CMakeLists.txt according to components names referenced in install function call
* Remove redundant sdbus-c++ from Debian packages

---------

Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2025-11-21 18:08:32 +01:00
Stanislav Angelovič
2f3a10a73c chore: release version v2.2.0 v2.2.0 2025-11-19 22:00:11 +01:00
Stanislav Angelovič
071c595717 fix: disable invalid errno test for basu backend (#519) 2025-11-19 21:47:48 +01:00
Stanislav Angelovič
91f0d3fca7 fix: create sdbus::Error correctly when errno is 0 (#517) 2025-11-12 22:43:44 +01:00
SimonBraunschmidtIBA
126ac9ffbe fix: add signature_of specialization for r-value references (#515)
* test: add Variant move test

* fix: provide signature_of<_T&&>

Provide signature_of specialization for rvalue references resp.
allow when forwarding references resolve to rvalue references

signature_of<_T&&> is needed e.g. for std::map::try_emplace() when the
emplaced sdbus:: type is passed as rvalue reference, otherwise the
static_assert "Unsupported D-Bus type ..." would trigger

See https://github.com/Kistler-Group/sdbus-cpp/issues/513#issuecomment-3429733769
for an elaborate explanation

Signed-off-by: Simon Braunschmidt <simon.braunschmidt@iba-group.com>

---------

Signed-off-by: Simon Braunschmidt <simon.braunschmidt@iba-group.com>
Co-authored-by: Stanislav Angelovic <stanislav.angelovic.ext@siemens.com>
2025-10-23 21:08:25 +02:00
Joel Winarske
7fbfcec455 feat: add async overloads of GetManagedObjects() (#480)
This implements three variants of `GetManagedObjectsAsync()` API into the standard `ObjectManager` client interface.

---------

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2025-05-05 13:31:44 +02:00
Stanislav Angelovič
0430ae0ad9 fix: fix the return type of the slot-returning overloads (#494) 2025-05-05 11:18:00 +02:00
Dylan Howey
6212b12159 feat: add cookie-related API to Message (#491)
Add `Message::getCookie()` and `MethodReply::getReplyCookie()` functions, based on underlying sd-bus cookie functions. They can be useful when pairing method call messages and method call reply messages.

---------

Co-authored-by: Dylan Howey <dylan.howey@evgo.com>
Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2025-05-05 08:04:20 +02:00
Stanislav Angelovič
4389ea39bf chore(ci): do necessary updates and adjustments (#493)
* Bump to latest versions of upload-artifact and checkout GitHub scripts
* Remove obsolete Ubuntu-20.04 image
* Introduce Ubuntu-24.04 image
* Other related updates and fixes in the CI
2025-05-05 07:51:21 +02:00
Stanislav Angelovič
48ea775531 feat: add createLightWeightProxy overload for convenience (#474) 2025-01-08 13:55:38 +01:00
sgiurgiu
fafe8487ff fix(codegen): generate correct annotation code (#473)
Before the patch, generating an adaptor from https://gitlab.freedesktop.org/hadess/mpris-spec/-/blob/master/spec/org.mpris.MediaPlayer2.xml
would produce incorrect code like this:
```
        m_object.addVTable( sdbus::setInterfaceFlags().withPropertyUpdateBehavior(sdbus::Flags::EMITS_CHANGE_SIGNAL);
                          , sdbus::registerMethod("Raise").implementedAs([this](){ return this->Raise(); })
                          , sdbus::registerMethod("Quit").implementedAs([this](){ return this->Quit(); })
...

```

With this patch, the code produced is:
```
        m_object.addVTable( sdbus::setInterfaceFlags().withPropertyUpdateBehavior(sdbus::Flags::EMITS_CHANGE_SIGNAL)
                          , sdbus::registerMethod("Raise").implementedAs([this](){ return this->Raise(); })
                          , sdbus::registerMethod("Quit").implementedAs([this](){ return this->Quit(); })
...

```
2025-01-02 17:48:48 +01:00
Stanislav Angelovič
0261d0ec60 chore: release version v2.1.0 v2.1.0 2024-11-20 23:47:56 +01:00
Stanislav Angelovič
a1419ee45d fix: add missing c-tor for nesting Variants (#467)
This allows nesting variants, i.e. allows a variant to contain another variant as its value. Until now, there was no such possibility, since the default generated copy constructor would be invoked which would create a copy of source variant instead of embed the source variant as a value in the destination variant. The default generated copy constructor is kept, for it makes sense too, but a new tag-based overload is added for embedding the source variant into the destination variant.
2024-11-20 23:40:30 +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
Brian
8a117f8b42 feat: add version parameter to xml2cpp codegen tool (#463)
* Added -v, --version xml2cpp command line tool options

* Update tools/xml2cpp-codegen/xml2cpp.cpp

Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>

* Updated tools/CMakeLists.txt

---------

Co-authored-by: Stanislav Angelovič <stanislav.angelovic@protonmail.com>
2024-11-20 19:54:49 +01:00
Karl Ljungkvist
84130b1406 fix(codegen): check fstream status and report in case of failure (#462) 2024-10-31 12:48:19 +01:00
Stanislav Angelovič
c55907069b refactor: send larger messages properly (#455)
Until now, the solution to ensure that even large messages are fully sent out has been to flush the connection queues after each sending of a message, which is likely an unnecessary call (with unnecessary cost) in vast majority of cases, and which may block the connection from doing other work until the large message is fully sent out. This was a rather quick, hacky workaround.

Now, after the sending the message we check whether it has been sent out fully or not. If not (outbound queues are non-empty), then we send a wake-up signal to the connection event loop. The event loop thread then fetches new sd-bus timeouts and events and will see that there are pending outbound messages to process, and will process them together with any other prospective pending events, until there is nothing to process (i.e., the outbound message has been fully dispatched).
2024-10-10 20:01:22 +02:00
Stanislav Angelovič
107c6a1a97 refactor: invert dependency between Message and Connection (#457)
This reorganizes the layers of abstraction in the sense how `Message` depends on `Connection` and vice versa. Now, `Message` has a link to the `Connection`. This replaces the shortcut link to the low-level `SdBus` interface that the `Message` kept. The interactions from `Message` now go through `Connection` which forwards them to `SdBus`. `Connection` is now a sole owner of the low-level `SdBus` interface. This allows for future changes around `SdBus` (e.g. a change from virtual functions back to non-virtual functions) without affecting the rest of the library. `Proxy`s and `Object`s can now send messages directly without having to go through `Connection`. The `Connection` no more depends on `Message` business-logic methods; it serves only as a factory for messages.

The flow for creating messages: `Proxy`/`Object` -> `Connection` -> `SdBus`
The flow for sending messages: (`Proxy`/`Object` ->) `Message` -> `Connection` -> `SdBus`

This also better reflects how dependencies are managed in the underlying sd-bus library.

Additionally, `getSdBusInterface()` methods are removed which was anyway planned, and improves the design by "Tell, don't ask" principle.

This refactoring is the necessary enabler for other upcoming improvements (regarding sending long messages, or creds refactoring, for example).
2024-10-02 21:22:02 +02: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
Stanislav Angelovič
b7a038f11f refactor: make createPlainMessage public (#448)
Library clients may need to manually create plain sdbus-c++ message to be able to unit test their code.
2024-08-18 10:09:53 +02:00
Stanislav Angelovič
c6705faf2f fix: const enum signature_of ambiguity error (#444)
This fixes the template specialization ambiguity error when a signature_of applied upon a const (and/or volatile) enum type would render the const specialization and the enum specialization as two equally-ranked candidates.
2024-05-15 15:46:24 +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
Marcel Hellwig
50cc636058 fix: make REGISTER_STRUCT functions inline
This makes that you can use these macros in headers as well as
source files.
Else you will get a warning about multiple definitions of the same
function.
2024-05-13 23:47:53 +02:00
Marcel Hellwig
3d3aa26255 chore: update gtest default version to 1.14.0
this prevents compiler errors on newer compilers
2024-05-13 23:47:53 +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č
b7d85f936d chore: release version v2.0.0 v2.0.0 2024-04-24 21:00:02 +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č
26c6da11be refactor: reorganize public API of main abstract classes (#437) 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č
ef552ec089 chore: update years in header comments 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č
d41a176c2a refactor: use string_view in Property convenience classes 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
f15c260750 feat: add support for string_view as D-Bus type 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č
fe21ee9656 fix(tests): fix intermittently failing integration tests (#412) 2024-04-24 20:20:29 +02:00
Stanislav Angelovič
0dc0c87cc9 chore: use C++20 standard (#410)
As of now sdbus-c++ supports C++20 but does not require it, and the used C++20 features are conditionally compiled depending on whether they are available or not.
2024-04-24 20:20:29 +02:00
Stanislav Angelovič
29e94c3b68 fix(cmake): rename forgotten CMake variables 2024-04-24 20:20:29 +02:00