Commit Graph
67 Commits
Author SHA1 Message Date
David Leeds 75ea127374 connection: add createDefaultBusConnection()
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).
2021-06-21 15:55:23 +02:00
Benjamin Kaufmann a5e94f07bf Fix issue #135: Segfault in Message::peekType()
* 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.
2021-06-15 15:26:10 +02:00
Urs RitzmannandStanislav Angelovic fa9569fdd9 Issue 133 race in proxy destruct (#177)
* 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>
2021-06-03 18:53:38 +02:00
Marek Blaha 118faa58f6 Add API to get message path and message destination (#167)
* 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.
2021-05-07 15:24:21 +02:00
David Leeds 6df67469ad proxy: add IProxy::getConnection() (#179)
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.
2021-05-06 16:52:02 +02:00
Stanislav Angelovic b0a72cbe92 Make Message's setDestination() thread safe 2021-04-29 15:30:56 +00:00
Marek Blaha 5ee4c61a1b Add API to set signal destination (#168)
With this patch it is possible to create unicast signals.
2021-04-29 17:18:04 +02:00
riuriuriu 3f54b5e762 comment sd_bus_match_signal() requires libsystemd v237 2021-04-13 15:59:35 +02:00
riuriuriu d47e9d1834 fix issue 145, signals are not filtered by sender 2021-04-13 15:59:35 +02:00
alivenetsandStanislav Angelovič 5e03e78451 feat: add API to get message credentials (#151)
* 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>
2021-03-12 14:14:23 +01:00
Stanislav Angelovic d5867e1197 Fix unused variable warning for release builds 2020-07-21 15:32:31 +02:00
Stanislav Angelovic c137dfa213 Fix potential data race in Proxy's condition variable 2020-06-17 09:13:30 +02:00
Jan Kundrát 0d010440c5 Fix build with clang 9.0.1 and libcxx
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
2020-06-16 16:51:53 +02:00
ChristianS99andChristian Schneider ae8849e545 Implement #104: add getObjectPath() for classes (#105)
* Implement #104: add getObjectPath() for classes

* Implement #104: changes requested in review

Co-authored-by: Christian Schneider <cschneider@radiodata.biz>
2020-05-28 15:36:58 +02:00
sangelovic 00d0837d98 Introduce support for cancellable async calls 2020-04-04 16:30:56 +02:00
sangelovic e91bedd4cb Fix #92: CallData race condition in Proxy::callMethod 2020-04-02 20:46:38 +02:00
Oliver Tappe dc66efbbcb Fix #93: Get signals working for multiple proxies.
* 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.
2020-03-26 21:19:18 +01:00
sangelovic 3a4f343fb9 Provide better names to event loop-related IConnection methods 2020-02-02 22:22:26 +01:00
sangelovic 975f1bf07f Switch to fully supported C++17 2020-02-01 22:58:34 +01:00
sangelovic eade6a0e44 Add support for method and signal parameter names in introspection 2020-02-01 12:38:39 +01:00
sangelovic 75709e31f1 Fix sporadic race condition between Variant and underlying bus
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.
2020-01-25 22:31:41 +01:00
sangelovic b25534013f Fix lock_guard variable declaration (don't yet use newer C++17 features) 2020-01-19 19:17:04 +01:00
sangelovic 4310a3bd17 Little fix of order of destruction in stress tests 2020-01-19 18:57:14 +01:00
sangelovic f41d9bc395 Fix issue of event loop thread and synchronous method call thread polling on the same D-Bus connection
Synchronous D-Bus method calls are now done in terms of blocking asynchronous calls.
2020-01-19 18:51:19 +01:00
sangelovic 839bc13625 Make Connection const-correct and fix integration tests build error 2019-11-10 17:40:33 +01:00
Bruno Marchand 5fe0f503ca Add a method to retrieve the unique name of a connection 2019-11-10 17:34:57 +01:00
sangelovic d50a15b2a2 Move C++17 uncaught_exceptions to public API 2019-11-10 17:31:58 +01:00
sangelovic 304b69dd8b Use tag dispatching to construct various types of Connection, refactor Connection unit tests 2019-11-03 20:30:52 +01:00
Jay 099bc857ad Add support for opening a connection to a remote system bus using ssh (#77) 2019-11-03 20:21:39 +01:00
lubo-svk c139110112 Add support for custom timeout value for D-Bus method calls (#72) 2019-11-03 13:54:13 +01:00
sangelovic 0f7de608ac Little code cleanup 2019-10-11 16:04:37 +02:00
hogliux 0440dcb15b Added ability to integrate with foreign event loops 2019-10-08 22:09:05 +02:00
sangelovic e30ce194ab Add getSenderName method to Message 2019-10-06 11:28:16 +02:00
Stanislav Angelovič a09362f79a Switch from plain UnixFd to owning UnixFd (#69) 2019-07-08 09:53:53 +02:00
Stanislav Angelovic ab34b0ae50 Update header doxy comments in source files 2019-06-11 20:18:37 +02:00
sangelovic 236c10ff56 Resolve a few clang-tidy suggestions and warnings (thanks to @ardazishvili)
Fixes part of #52.
2019-06-10 21:54:02 +02:00
Stanislav Angelovič dcad208ffe Redesign inheritance from Message (#62)
... so that the code is more idiomatic, clear and expressive about its intended use
2019-06-10 21:38:30 +02:00
sangelovic 57c840637c Add support for Unix fd D-Bus type 2019-06-10 21:19:56 +02:00
sangelovic 38b51bddc6 Add support for ObjectManager's InterfaceAdded/Removed signals on server side 2019-06-03 23:47:27 +02:00
Stanislav Angelovič 01e2a7a570 Add support for PropertyChanged signal on server side 2019-06-03 22:02:15 +02:00
Stanislav Angelovič 91fa35140b Add support for ObjectManager and other standard D-Bus interfaces (#55)
Fixes #50
2019-05-29 22:28:15 +02:00
Stanislav Angelovič 4b0c23204d Add object manager support to IConnection interface (#54) 2019-05-27 20:51:42 +02:00
sangelovic b87b0c9dd9 Fix the way of handling thread-local system bus 2019-05-12 10:23:26 +02:00
Stanislav Angelovic 7763c66513 Add support for libsystemd versions up to the newest 242, and set 242 as default version 2019-05-09 19:16:16 +02:00
sangelovic e3a74a3ff2 Add unregister function to IObject and IProxy API 2019-04-13 21:17:37 +02:00
sangelovic 99160156fe Fix all gcc warnings 2019-04-12 22:39:14 +02:00
sangelovic 93b6e5237a Clean up some names (rename classes, methods, files)
* ConvenienceClasses.h/.inl/.cpp -> ConvenienceApiClasses.h/.inl/.cpp
  * IObjectProxy class -> IProxy
  * Interfaces class -> AdaptorInterfaces
  * Interfaces.h -> split into AdaptorInterfaces.h and ProxyInterfaces.h
  * createObjectProxy() method -> createProxy()
2019-04-09 21:28:07 +02:00
Stanislav Angelovic 94fd3c88d8 Add getConnection() method to IObject so we ask Object about its connection 2019-04-04 20:39:03 +02:00
sangelovic 08945acbc4 Simplify and unify callback design for both sync and async methods 2019-04-03 00:05:20 +02:00
Stanislav Angelovic 1c4abab3e4 Remove executable bit erroneously set on source files 2019-03-27 17:53:31 +01:00