Commit Graph

86 Commits

Author SHA1 Message Date
Taras Zaporozhets
299e6940cd Improve ABI 2022-10-30 18:17:51 +01:00
Taras Zaporozhets
3f825ffb30 Force event loop to re-enter processing to handle queued messages 2022-09-04 23:26:14 +02:00
Stanislav Angelovic
2991fa4960 refactor: use pseudo D-Bus connection for plain messages 2022-08-09 08:55:29 +02:00
alivenets
0f2362d8c3 feat: add support for session bus connection at custom address (#273)
* Add methods to initiate custom session bus connection

The new function helper `createSessionBusConnectionWithAddress` allows to create connection to session bus with custom address.

Signed-off-by: Alexander Livenets <a.livenets@gmail.com>

* feat: add support for session bus connection at custom address

Co-authored-by: Stanislav Angelovic <stanislav.angelovic@siemens.com>
2022-08-08 13:54:09 +02:00
Stanislav Angelovic
e07c1f3981 chore: update doxygen header info 2022-07-05 18:10:05 +02:00
Stanislav Angelovic
4e105081c9 fix: remove executable flag from source files 2022-06-27 12:17:18 +02:00
Stanislav Angelovic
5ec6027d5f feat: add support for match rules 2022-06-27 12:14:57 +02:00
Stanislav Angelovic
d864e1dfa4 refactor: rename dont_request_slot tag to floating_slot 2022-06-27 12:05:06 +02:00
Stanislav Angelovic
b7f3d7c876 refactor: little fixes and reorganizations around Connection class 2022-06-22 18:12:42 +02:00
Michal Hučko
5caea3b72b fix: invalid assert on event fd (#243) 2022-02-13 18:48:50 +01:00
Stanislav Angelovič
b7a9c63ff0 refactor: add validity checks for names and paths (#242) 2022-02-11 21:53:37 +01:00
Stanislav Angelovic
b8eb0e8ceb fix: minor fixes for async timeout handling 2021-12-21 13:52:14 +01:00
Stanislav Angelovic
23fdd0ce8f fix: use non-mutating find in signal unregistration 2021-12-20 10:05:24 +01:00
Benjamin Kaufmann
bb0f3f0242 Fix #88: Timeout handling. (#91)
fix timeout handling

* Despite what is documented in sd_bus_get_timeout(3), the timeout
  returned is actually an absolute time point of Linux's CLOCK_MONOTONIC
  clock. Hence, we first have to subtract the current time from the
  timeout in order to get a relative time that can be passed to poll.

* For async call timeouts to reliably work, we need a way to notify the
  event loop of a connection that is currently blocked waiting in poll.
  I.e. assume the event loop thread entered poll with a timeout set to
  T1. Afterwards, the main thread starts an async call C with a timeout
  T2 < T1. In order for C to be canceled after its timeout T1 has
  elapsed, we have to be able to notify the event loop so that it can
  update its poll data.

Co-authored-by: Urs Ritzmann <ursritzmann@protonmail.ch>
Co-authored-by: Lukasz Marcul <lukasz.marcul@onemeter.com>
2021-12-20 10:00:29 +01:00
Osama Ghanem
41d33117cc Fix #214: Add means to unregister signal handler 2021-12-14 16:48:50 +01:00
Stanislav Angelovic
d77bb6b869 Fix potential race condition in Object destruction 2021-09-17 19:03:15 +02:00
Stanislav Angelovic
b4f5c0f46c Catch sdbus-c++ exceptions flying from Proxy callbacks to libsystemd 2021-07-29 12:37:15 +02:00
Stanislav Angelovic
a95fcf5693 Make resetting loop thread ID exception-safe 2021-07-22 13:48:43 +02:00
Stanislav Angelovic
e16ffb1288 Provide access to D-Bus message in high-level API 2021-06-22 11:31:08 +02:00
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 Ritzmann
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
alivenets
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
ChristianS99
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