Compare commits

...

9 Commits

Author SHA1 Message Date
133ffa4b0f chore(ci): add new clang-tidy job 2025-05-06 10:54:28 +02:00
55e6232b50 fix: address clang-tidy warnings in stress tests 2025-05-05 21:52:05 +02:00
5fdb2f7f13 fix: address clang-tidy warnings 2025-05-05 19:28:25 +02:00
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
0430ae0ad9 fix: fix the return type of the slot-returning overloads (#494) 2025-05-05 11:18:00 +02:00
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
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
48ea775531 feat: add createLightWeightProxy overload for convenience (#474) 2025-01-08 13:55:38 +01:00
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
24 changed files with 599 additions and 319 deletions

76
.clang-tidy Normal file
View File

@ -0,0 +1,76 @@
---
#Checks: "*,\
# -modernize-use-trailing-return-type,\
# -google-readability-braces-around-statements,\
# -google-readability-todo,\
# -hicpp-braces-around-statements,\
# -readability-braces-around-statements,\
# -hicpp-no-array-decay,\
# -cppcoreguidelines-pro-type-vararg,\
# -cppcoreguidelines-pro-bounds-constant-array-index,\
# -cppcoreguidelines-pro-bounds-array-to-pointer-decay,\
# -hicpp-vararg,\
# -hicpp-signed-bitwise,\
# -llvm-header-guard,\
# -llvmlibc-*,\
# -google-runtime-references,\
# -readability-redundant-access-specifiers,\
# -cppcoreguidelines-avoid-magic-numbers,\
# -readability-magic-numbers,\
# -altera-*,\
# -fuchsia-*"
# TODO: enable -llvm-include-order in the end, after clang-format
Checks: "*,\
-llvmlibc-*,\
-altera-*,\
-fuchsia-*,
-cert-err58-cpp,\
-modernize-use-trailing-return-type,\
-cppcoreguidelines-avoid-magic-numbers,\
-readability-magic-numbers,\
-readability-braces-around-statements,\
-google-readability-braces-around-statements,\
-hicpp-braces-around-statements,\
-hicpp-signed-bitwise,\
-llvm-include-order,\
-google-runtime-int,\
-hicpp-named-parameter,\
-readability-named-parameter,\
-bugprone-macro-parentheses,\
-google-readability-todo,\
-cppcoreguidelines-pro-type-reinterpret-cast,\
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,\
-hicpp-no-array-decay,\
-cppcoreguidelines-avoid-c-arrays,\
-hicpp-avoid-c-arrays,\
-modernize-avoid-c-arrays"
#TODO: Add readability-implicit-bool-conversion and remove // NOLINT(readability-implicit-bool-conversion) from code
HeaderFilterRegex: 'src|sdbus-c++'
FormatStyle: file
WarningsAsErrors: "*"
CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: '1'
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
value: '1'
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: '1'
- key: hicpp-special-member-functions.AllowSoleDefaultDtor
value: '1'
- key: readability-identifier-length.IgnoredVariableNames
value: 'r|fd|id|ok|it'
- key: readability-identifier-length.IgnoredParameterNames
value: 'fd|id|b'
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: '0'
- key: hicpp-move-const-arg.CheckTriviallyCopyableMove
value: '0'
# - key: bugprone-easily-swappable-parameters.MinimumLength
# value: '3'
# - key: readability-braces-around-statements.ShortStatementLines
# value: '3'

View File

@ -14,15 +14,11 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-22.04, ubuntu-24.04]
compiler: [g++, clang]
build: [shared-libsystemd, embedded-static-libsystemd]
include:
- os: ubuntu-20.04
compiler: gcc
build: shared-libsystemd
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: install-libsystemd-toolchain
if: matrix.build == 'embedded-static-libsystemd'
run: |
@ -36,7 +32,7 @@ jobs:
- name: install-clang
if: matrix.compiler == 'clang'
run: |
sudo apt-get install -y clang
sudo apt-get install -y clang libc++-dev
sudo update-alternatives --remove-all cc
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 10
sudo update-alternatives --remove-all c++
@ -45,65 +41,67 @@ jobs:
echo "SDBUSCPP_EXTRA_CXX_FLAGS=-stdlib=libc++" >> $GITHUB_ENV
# We don't install googletest but we let it be built within sdbus-c++ builds below, since it needs to be built against libc++ for Clang jobs to pass
# - name: install-googletest
# if: matrix.os == 'ubuntu-22.04'
# run: |
# sudo apt-get install -y libgmock-dev
# - name: install-googletest
# if: matrix.os == 'ubuntu-20.04' # On older ubuntus the libgmock-dev package is either unavailable or has faulty pkg-config file, so we build & install manually
# run: |
# git clone https://github.com/google/googletest.git
# cd googletest
# mkdir build
# cd build
# cmake .. -DCMAKE_CXX_FLAGS="$SDBUSCPP_EXTRA_CXX_FLAGS"
# cmake --build . -j4
# sudo cmake --build . --target install
- name: configure-debug-gcc11 # For gcc 11, turn off the annoying deprecated-copy warning
if: matrix.build == 'shared-libsystemd' && matrix.compiler == 'g++' && matrix.os == 'ubuntu-22.04'
run: |
cmake -B _build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O0 -g -W -Wextra -Wall -Wnon-virtual-dtor -Wno-deprecated-copy -Werror $SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_GOOGLETEST_VERSION=1.14.0
- name: configure-debug
if: matrix.build == 'shared-libsystemd' && matrix.os == 'ubuntu-22.04'
if: matrix.build == 'shared-libsystemd' && (matrix.compiler != 'g++' || matrix.os != 'ubuntu-22.04')
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O0 -g -W -Wextra -Wall -Wnon-virtual-dtor -Werror $SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_GOOGLETEST_VERSION=1.14.0 ..
- name: configure-debug-no-tests
if: matrix.os == 'ubuntu-20.04'
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O0 -g -W -Wextra -Wall -Wnon-virtual-dtor -Werror $SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=OFF -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON ..
cmake -B _build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="-O0 -g -W -Wextra -Wall -Wnon-virtual-dtor -Werror $SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_GOOGLETEST_VERSION=1.14.0
- name: configure-release-with-embedded-libsystemd
if: matrix.build == 'embedded-static-libsystemd'
run: |
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="$SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_BUILD_LIBSYSTEMD=ON -DSDBUSCPP_LIBSYSTEMD_VERSION=252 -DSDBUSCPP_GOOGLETEST_VERSION=1.14.0 ..
cmake -B _build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_CXX_FLAGS="$SDBUSCPP_EXTRA_CXX_FLAGS" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_INSTALL=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON -DSDBUSCPP_BUILD_CODEGEN=ON -DSDBUSCPP_BUILD_LIBSYSTEMD=ON -DSDBUSCPP_LIBSYSTEMD_VERSION=252 -DSDBUSCPP_GOOGLETEST_VERSION=1.14.0
- name: make
run: |
cd build
cmake --build . -j4
cmake --build _build -j4
- name: verify
run: |
cd build
sudo cmake --build . --target install
sudo cmake --build _build --target install
ctest --output-on-failure
- name: pack
if: matrix.build == 'shared-libsystemd' && matrix.os == 'ubuntu-20.04'
if: matrix.build == 'shared-libsystemd'
run: |
cd build
cd _build
cpack -G DEB
- name: 'Upload Artifact'
if: matrix.build == 'shared-libsystemd' && matrix.os == 'ubuntu-22.04' && matrix.compiler == 'g++'
uses: actions/upload-artifact@v3
if: matrix.build == 'shared-libsystemd' && matrix.compiler == 'g++'
uses: actions/upload-artifact@v4
with:
name: "debian-packages-${{ matrix.os }}-${{ matrix.compiler }}"
path: |
build/sdbus-c++*.deb
build/sdbus-c++*.ddeb
_build/sdbus-c++*.deb
_build/sdbus-c++*.ddeb
retention-days: 10
static-analysis:
name: static-analysis (ubuntu-24.04, clang-tidy, shared-libsystemd)
runs-on: ubuntu-24.04
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: install-deps
run: |
sudo apt-get update -y
sudo apt-get install -y libsystemd-dev libgmock-dev clang
sudo update-alternatives --remove-all cc
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 10
sudo update-alternatives --remove-all c++
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 10
- name: configure
run: |
cmake -B _build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-O0 -g" -DCMAKE_VERBOSE_MAKEFILE=ON -DSDBUSCPP_CLANG_TIDY=ON -DSDBUSCPP_BUILD_TESTS=ON -DSDBUSCPP_BUILD_PERF_TESTS=ON -DSDBUSCPP_BUILD_STRESS_TESTS=ON
- name: make
run: |
cmake --build _build -j4
freebsd-build:
name: build (freebsd, clang/libc++, basu)
runs-on: ubuntu-22.04 # until https://github.com/actions/runner/issues/385
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Test in FreeBSD VM
uses: vmactions/freebsd-vm@v1
with:

View File

@ -35,7 +35,7 @@ option(SDBUSCPP_BUILD_DOCS "Build documentation for sdbus-c++" ON)
if(SDBUSCPP_BUILD_DOCS)
option(SDBUSCPP_BUILD_DOXYGEN_DOCS "Build doxygen documentation for sdbus-c++ API" OFF)
endif()
#option(SDBUSCPP_CLANG_TIDY "Co-compile with clang-tidy static analyzer" OFF)
option(SDBUSCPP_CLANG_TIDY "Co-compile with clang-tidy static analyzer" OFF)
#option(SDBUSCPP_COVERAGE "Build sdbus-c++ with code coverage instrumentation" OFF)
# We promote the BUILD_SHARED_LIBS flag to a (global) option only if we are the main project
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
@ -262,6 +262,26 @@ if(SDBUSCPP_BUILD_DOCS)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/docs")
endif()
#----------------------------------
# STATIC ANALYSIS
#----------------------------------
if(SDBUSCPP_CLANG_TIDY)
message(STATUS "Building with static analysis")
#set(CLANG_TIDY "/home/one/CLion2/clion-2024.3.5/bin/clang/linux/x64/bin/clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy)
if(NOT CLANG_TIDY)
message(WARNING "clang-tidy not found")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY}")
set_target_properties(sdbus-c++-objlib PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
set_target_properties(sdbus-c++ PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
#set_target_properties(sdbus-c++-unit-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
#set_target_properties(sdbus-c++-integration-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
set_target_properties(sdbus-c++-stress-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
endif()
endif()
#----------------------------------
# CMAKE CONFIG & PACKAGE CONFIG
#----------------------------------

View File

@ -466,18 +466,18 @@ On the **client** side we likewise need a connection -- just that unlike on the
* Pass an already existing connection as a reference. This is the typical approach when the application already maintains a D-Bus connection (maybe it provide D-Bus API on it, and/or it already has some proxies hooked on it). The proxy will share the connection with others. With this approach we must of course ensure that the connection exists as long as the proxy exists. For discussion on options for running an event loop on that connection, see above section [Using D-Bus connections on the server side](#using-d-bus-connections-on-the-server-side).
* Or -- and this is a simpler approach for simple D-Bus client applications -- we have another option: we let the proxy maintain its own connection (and potentially an associated event loop thread, see below). We have two options here:
* Or -- and this is a simpler approach for simple D-Bus client applications -- we have another option: we let the proxy maintain its own connection (and potentially an associated event loop thread, see below). We have two options here:
* We either create the connection ourselves and `std::move` it to the proxy object factory. The proxy becomes an owner of this connection, and it will be his dedicated connection. This has the advantage that we may choose the type of connection (system, session, remote). Additionally,
* when created **without** `dont_run_event_loop_thread_t` tag, the proxy **will start** a dedicated event loop thread on that connection;
* or, when created **with** `dont_run_event_loop_thread_t` tag, the proxy will start **no** event loop thread on that connection.
* Or we don't care about connnections at all (proxy factory overloads with no connection parameter). Under the hood, the proxy creates its own connection, to either the session bus (when in a user context) or the system bus otherwise. Additionally:
* Or we don't care about connections at all (proxy factory overloads with no connection parameter). Under the hood, the proxy creates its own connection, to either the session bus (when in a user context) or the system bus otherwise. Additionally:
* when created **without** `dont_run_event_loop_thread_t` tag, the proxy **will start** a dedicated event loop thread on that connection;
* or, when created **with** `dont_run_event_loop_thread_t` tag, the proxy will start **no** event loop thread on that connection.
A proxy needs an event loop if it's a "**long-lived**" proxy that listens on incoming messages like signals, async call replies, atc. Sharing one connection with its one event loop is more scalable. Starting a dedicated event loop in a proxy is simpler from API perspective, but comes at a performance and resource cost for each proxy creation/destruction, and it hurts scalability. A simple and scalable option are "**short-lived, light-weight**" proxies. Quite a typical use case is that we occasionally need to carry out one or a few D-Bus calls and that's it. We may create a proxy, do the calls, and let go of proxy. Such a light-weight proxy is created when `dont_run_event_loop_thread_t` tag is passed to the proxy factory. Such a proxy **does not spawn** an event loop thread. It only support synchronous D-Bus calls (no signals, no async calls...), and is meant to be created, used right away, and then destroyed immediately.
A proxy needs an event loop if it's a "**long-lived**" proxy that listens on incoming messages like signals, async call replies, atc. Sharing one connection with its one event loop is more scalable. Starting a dedicated event loop in a proxy is simpler from API perspective, but comes at a performance and resource cost for each proxy creation/destruction, and it hurts scalability. A simple and scalable option are "**short-lived, light-weight**" proxies. Quite a typical use case is that we occasionally need to carry out one or a few D-Bus calls and that's it. We may create a proxy, do the calls, and let go of proxy. Such a light-weight proxy is created when `dont_run_event_loop_thread_t` tag is passed to the proxy factory (or with `createLightWeightProxy()`). Such a proxy **does not spawn** an event loop thread. It only support synchronous D-Bus calls (no signals, no async calls...), and is meant to be created, used right away, and then destroyed immediately.
#### Stopping internal I/O event loops graciously

View File

@ -385,7 +385,7 @@ namespace sdbus {
* callMethod() function overload, which does not block the bus connection, or do the synchronous
* call from another Proxy instance created just before the call and then destroyed (which is
* anyway quite a typical approach in D-Bus implementations). Such proxy instance must have
* its own bus connection. So-called light-weight proxies (ones created with `dont_run_event_loop_thread`
* its own bus connection. So-called light-weight proxies (ones running without an event loop thread)
* tag are designed for exactly that purpose.
*
* The default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
@ -416,7 +416,7 @@ namespace sdbus {
* callMethod() function overload, which does not block the bus connection, or do the synchronous
* call from another Proxy instance created just before the call and then destroyed (which is
* anyway quite a typical approach in D-Bus implementations). Such proxy instance must have
* its own bus connection. So-called light-weight proxies (ones created with `dont_run_event_loop_thread`
* its own bus connection. So-called light-weight proxies (ones running without an event loop thread)
* tag are designed for exactly that purpose.
*
* If timeout is zero, the default D-Bus method call timeout is used. See IConnection::getMethodCallTimeout().
@ -889,7 +889,7 @@ namespace sdbus {
, ObjectPath objectPath );
/*!
* @brief Creates a proxy object for a specific remote D-Bus object
* @brief Creates a light-weight proxy object for a specific remote D-Bus object
*
* @param[in] connection D-Bus connection to be used by the proxy object
* @param[in] destination Bus name that provides the remote D-Bus object
@ -916,6 +916,15 @@ namespace sdbus {
, ObjectPath objectPath
, dont_run_event_loop_thread_t );
/*!
* @brief Creates a light-weight proxy object for a specific remote D-Bus object
*
* Does the same thing as createProxy(std::unique_ptr<sdbus::IConnection>&&, ServiceName, ObjectPath, dont_run_event_loop_thread_t);
*/
[[nodiscard]] std::unique_ptr<sdbus::IProxy> createLightWeightProxy( std::unique_ptr<sdbus::IConnection>&& connection
, ServiceName destination
, ObjectPath objectPath );
/*!
* @brief Creates a proxy object for a specific remote D-Bus object
*
@ -937,7 +946,7 @@ namespace sdbus {
, ObjectPath objectPath );
/*!
* @brief Creates a proxy object for a specific remote D-Bus object
* @brief Creates a light-weight proxy object for a specific remote D-Bus object
*
* @param[in] destination Bus name that provides the remote D-Bus object
* @param[in] objectPath Path of the remote D-Bus object
@ -958,6 +967,13 @@ namespace sdbus {
, ObjectPath objectPath
, dont_run_event_loop_thread_t );
/*!
* @brief Creates a light-weight proxy object for a specific remote D-Bus object
*
* Does the same thing as createProxy(ServiceName, ObjectPath, dont_run_event_loop_thread_t);
*/
[[nodiscard]] std::unique_ptr<sdbus::IProxy> createLightWeightProxy(ServiceName destination, ObjectPath objectPath);
}
#include <sdbus-c++/ConvenienceApiClasses.inl>

View File

@ -215,6 +215,7 @@ namespace sdbus {
const char* getSender() const;
const char* getPath() const;
const char* getDestination() const;
uint64_t getCookie() const;
// TODO: short docs in whole Message API
std::pair<char, const char*> peekType() const;
bool isValid() const;
@ -296,6 +297,7 @@ namespace sdbus {
public:
MethodReply() = default;
void send() const;
uint64_t getReplyCookie() const;
};
class Signal : public Message

View File

@ -168,6 +168,11 @@ namespace sdbus {
return m_proxy.getPropertyAsync(propertyName).onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
}
std::future<sdbus::Variant> GetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, with_future_t)
{
return m_proxy.getPropertyAsync(propertyName).onInterface(interfaceName).getResultAsFuture();
}
template <typename _Function>
PendingAsyncCall GetAsync(std::string_view interfaceName, std::string_view propertyName, _Function&& callback)
{
@ -180,11 +185,6 @@ namespace sdbus {
return m_proxy.getPropertyAsync(propertyName).onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
}
std::future<sdbus::Variant> GetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, with_future_t)
{
return m_proxy.getPropertyAsync(propertyName).onInterface(interfaceName).getResultAsFuture();
}
std::future<sdbus::Variant> GetAsync(std::string_view interfaceName, std::string_view propertyName, with_future_t)
{
return m_proxy.getPropertyAsync(propertyName).onInterface(interfaceName).getResultAsFuture();
@ -217,11 +217,16 @@ namespace sdbus {
}
template <typename _Function>
PendingAsyncCall SetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
[[nodiscard]] Slot SetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
{
return m_proxy.setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
}
std::future<void> SetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, const sdbus::Variant& value, with_future_t)
{
return m_proxy.setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).getResultAsFuture();
}
template <typename _Function>
PendingAsyncCall SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, _Function&& callback)
{
@ -229,16 +234,11 @@ namespace sdbus {
}
template <typename _Function>
PendingAsyncCall SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
[[nodiscard]] Slot SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, _Function&& callback, return_slot_t)
{
return m_proxy.setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
}
std::future<void> SetAsync(const InterfaceName& interfaceName, const PropertyName& propertyName, const sdbus::Variant& value, with_future_t)
{
return m_proxy.setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).getResultAsFuture();
}
std::future<void> SetAsync(std::string_view interfaceName, std::string_view propertyName, const sdbus::Variant& value, with_future_t)
{
return m_proxy.setPropertyAsync(propertyName).onInterface(interfaceName).toValue(value).getResultAsFuture();
@ -261,11 +261,16 @@ namespace sdbus {
}
template <typename _Function>
PendingAsyncCall GetAllAsync(const InterfaceName& interfaceName, _Function&& callback, return_slot_t)
[[nodiscard]] Slot GetAllAsync(const InterfaceName& interfaceName, _Function&& callback, return_slot_t)
{
return m_proxy.getAllPropertiesAsync().onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
}
std::future<std::map<PropertyName, sdbus::Variant>> GetAllAsync(const InterfaceName& interfaceName, with_future_t)
{
return m_proxy.getAllPropertiesAsync().onInterface(interfaceName).getResultAsFuture();
}
template <typename _Function>
PendingAsyncCall GetAllAsync(std::string_view interfaceName, _Function&& callback)
{
@ -273,16 +278,11 @@ namespace sdbus {
}
template <typename _Function>
PendingAsyncCall GetAllAsync(std::string_view interfaceName, _Function&& callback, return_slot_t)
[[nodiscard]] Slot GetAllAsync(std::string_view interfaceName, _Function&& callback, return_slot_t)
{
return m_proxy.getAllPropertiesAsync().onInterface(interfaceName).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
}
std::future<std::map<PropertyName, sdbus::Variant>> GetAllAsync(const InterfaceName& interfaceName, with_future_t)
{
return m_proxy.getAllPropertiesAsync().onInterface(interfaceName).getResultAsFuture();
}
std::future<std::map<PropertyName, sdbus::Variant>> GetAllAsync(std::string_view interfaceName, with_future_t)
{
return m_proxy.getAllPropertiesAsync().onInterface(interfaceName).getResultAsFuture();
@ -344,6 +344,23 @@ namespace sdbus {
return objectsInterfacesAndProperties;
}
template <typename _Function>
PendingAsyncCall GetManagedObjectsAsync(_Function&& callback)
{
return m_proxy.callMethodAsync("GetManagedObjects").onInterface(INTERFACE_NAME).uponReplyInvoke(std::forward<_Function>(callback));
}
template <typename _Function>
[[nodiscard]] Slot GetManagedObjectsAsync(_Function&& callback, return_slot_t)
{
return m_proxy.callMethodAsync("GetManagedObjects").onInterface(INTERFACE_NAME).uponReplyInvoke(std::forward<_Function>(callback), return_slot);
}
std::future<std::map<sdbus::ObjectPath, std::map<sdbus::InterfaceName, std::map<PropertyName, sdbus::Variant>>>> GetManagedObjectsAsync(with_future_t)
{
return m_proxy.callMethodAsync("GetManagedObjects").onInterface(INTERFACE_NAME).getResultAsFuture<std::map<sdbus::ObjectPath, std::map<sdbus::InterfaceName, std::map<PropertyName, sdbus::Variant>>>>();
}
private:
sdbus::IProxy& m_proxy;
};

View File

@ -105,9 +105,19 @@ Connection::Connection(std::unique_ptr<ISdBus>&& interface, pseudo_bus_t)
}
Connection::~Connection()
try
{
Connection::leaveEventLoop();
}
catch (...)
{
// Theoretically, we can fail to notify the event fd or join with the joinable thread...
// What to do now here in the destructor? That is the question:
// 1. Report the problem... but how, where?
// 2. Terminate immediately... too harsh?
// 3. Ignore and go on... even when some resources may be lingering?
// Since the failure here is expected to be very unlikely, we choose the defensive approach of (3).
}
void Connection::requestName(const ServiceName& name)
{
@ -194,7 +204,7 @@ Slot Connection::addObjectManager(const ObjectPath& objectPath, return_slot_t)
SDBUS_THROW_ERROR_IF(r < 0, "Failed to add object manager", -r);
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref((sd_bus_slot*)slot); }};
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref(static_cast<sd_bus_slot*>(slot)); }};
}
void Connection::setMethodCallTimeout(uint64_t timeout)
@ -206,7 +216,7 @@ void Connection::setMethodCallTimeout(uint64_t timeout)
uint64_t Connection::getMethodCallTimeout() const
{
uint64_t timeout;
uint64_t timeout{};
auto r = sdbus_->sd_bus_get_method_call_timeout(bus_.get(), &timeout);
@ -230,9 +240,9 @@ Slot Connection::addMatch(const std::string& match, message_handler callback, re
auto r = sdbus_->sd_bus_add_match(bus_.get(), &slot, match.c_str(), &Connection::sdbus_match_callback, matchInfo.get());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to add match", -r);
matchInfo->slot = {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref((sd_bus_slot*)slot); }};
matchInfo->slot = {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref(static_cast<sd_bus_slot*>(slot)); }};
return {matchInfo.release(), [](void *ptr){ delete static_cast<MatchInfo*>(ptr); }};
return {matchInfo.release(), [](void *ptr){ delete static_cast<MatchInfo*>(ptr); }}; // NOLINT(cppcoreguidelines-owning-memory)
}
void Connection::addMatchAsync(const std::string& match, message_handler callback, message_handler installCallback)
@ -259,9 +269,9 @@ Slot Connection::addMatchAsync( const std::string& match
, matchInfo.get());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to add match", -r);
matchInfo->slot = {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref((sd_bus_slot*)slot); }};
matchInfo->slot = {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref(static_cast<sd_bus_slot*>(slot)); }};
return {matchInfo.release(), [](void *ptr){ delete static_cast<MatchInfo*>(ptr); }};
return {matchInfo.release(), [](void *ptr){ delete static_cast<MatchInfo*>(ptr); }}; // NOLINT(cppcoreguidelines-owning-memory)
}
void Connection::attachSdEventLoop(sd_event *event, int priority)
@ -306,7 +316,7 @@ Slot Connection::createSdEventSlot(sd_event *event)
(void)sd_event_default(&event);
SDBUS_THROW_ERROR_IF(!event, "Invalid sd_event handle", EINVAL);
return Slot{event, [](void* event){ sd_event_unref((sd_event*)event); }};
return Slot{event, [](void* event){ sd_event_unref(static_cast<sd_event*>(event)); }};
}
Slot Connection::createSdTimeEventSourceSlot(sd_event *event, int priority)
@ -314,7 +324,7 @@ Slot Connection::createSdTimeEventSourceSlot(sd_event *event, int priority)
sd_event_source *timeEventSource{};
auto r = sd_event_add_time(event, &timeEventSource, CLOCK_MONOTONIC, 0, 0, onSdTimerEvent, this);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to add timer event", -r);
Slot sdTimeEventSource{timeEventSource, [](void* source){ deleteSdEventSource((sd_event_source*)source); }};
Slot sdTimeEventSource{timeEventSource, [](void* source){ deleteSdEventSource(static_cast<sd_event_source*>(source)); }};
r = sd_event_source_set_priority(timeEventSource, priority);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to set time event priority", -r);
@ -325,12 +335,12 @@ Slot Connection::createSdTimeEventSourceSlot(sd_event *event, int priority)
return sdTimeEventSource;
}
Slot Connection::createSdIoEventSourceSlot(sd_event *event, int fd, int priority)
Slot Connection::createSdIoEventSourceSlot(sd_event *event, int fd, int priority) // NOLINT(bugprone-easily-swappable-parameters)
{
sd_event_source *ioEventSource{};
auto r = sd_event_add_io(event, &ioEventSource, fd, 0, onSdIoEvent, this);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to add io event", -r);
Slot sdIoEventSource{ioEventSource, [](void* source){ deleteSdEventSource((sd_event_source*)source); }};
Slot sdIoEventSource{ioEventSource, [](void* source){ deleteSdEventSource(static_cast<sd_event_source*>(source)); }};
r = sd_event_source_set_prepare(ioEventSource, onSdEventPrepare);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to set prepare callback for IO event", -r);
@ -344,12 +354,12 @@ Slot Connection::createSdIoEventSourceSlot(sd_event *event, int fd, int priority
return sdIoEventSource;
}
Slot Connection::createSdInternalEventSourceSlot(sd_event *event, int fd, int priority)
Slot Connection::createSdInternalEventSourceSlot(sd_event *event, int fd, int priority) // NOLINT(bugprone-easily-swappable-parameters)
{
sd_event_source *internalEventSource{};
auto r = sd_event_add_io(event, &internalEventSource, fd, 0, onSdInternalEvent, this);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to add internal event", -r);
Slot sdInternalEventSource{internalEventSource, [](void* source){ deleteSdEventSource((sd_event_source*)source); }};
Slot sdInternalEventSource{internalEventSource, [](void* source){ deleteSdEventSource(static_cast<sd_event_source*>(source)); }};
// sd-event loop calls prepare callbacks for all event sources, not just for the one that fired now.
// So since onSdEventPrepare is already registered on ioEventSource, we don't need to duplicate it here.
@ -367,7 +377,7 @@ Slot Connection::createSdInternalEventSourceSlot(sd_event *event, int fd, int pr
int Connection::onSdTimerEvent(sd_event_source */*s*/, uint64_t /*usec*/, void *userdata)
{
auto connection = static_cast<Connection*>(userdata);
auto *connection = static_cast<Connection*>(userdata);
assert(connection != nullptr);
(void)connection->processPendingEvent();
@ -377,7 +387,7 @@ int Connection::onSdTimerEvent(sd_event_source */*s*/, uint64_t /*usec*/, void *
int Connection::onSdIoEvent(sd_event_source */*s*/, int /*fd*/, uint32_t /*revents*/, void *userdata)
{
auto connection = static_cast<Connection*>(userdata);
auto *connection = static_cast<Connection*>(userdata);
assert(connection != nullptr);
(void)connection->processPendingEvent();
@ -387,7 +397,7 @@ int Connection::onSdIoEvent(sd_event_source */*s*/, int /*fd*/, uint32_t /*reven
int Connection::onSdInternalEvent(sd_event_source */*s*/, int /*fd*/, uint32_t /*revents*/, void *userdata)
{
auto connection = static_cast<Connection*>(userdata);
auto *connection = static_cast<Connection*>(userdata);
assert(connection != nullptr);
// It's not really necessary to processPendingEvent() here. We just clear the event fd.
@ -410,7 +420,7 @@ int Connection::onSdInternalEvent(sd_event_source */*s*/, int /*fd*/, uint32_t /
int Connection::onSdEventPrepare(sd_event_source */*s*/, void *userdata)
{
auto connection = static_cast<Connection*>(userdata);
auto *connection = static_cast<Connection*>(userdata);
assert(connection != nullptr);
auto sdbusPollData = connection->getEventLoopPollData();
@ -432,16 +442,16 @@ int Connection::onSdEventPrepare(sd_event_source */*s*/, void *userdata)
// In case the timeout is infinite, we disable the timer in the sd_event loop.
// This prevents a syscall error, where `timerfd_settime` returns `EINVAL`,
// because the value is too big. See #324 for details
r = sd_event_source_set_enabled(sdTimeEventSource, sdbusPollData.timeout != sdbusPollData.timeout.max() ? SD_EVENT_ONESHOT : SD_EVENT_OFF);
r = sd_event_source_set_enabled(sdTimeEventSource, sdbusPollData.timeout != std::chrono::microseconds::max() ? SD_EVENT_ONESHOT : SD_EVENT_OFF);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to enable time event source", -r);
return 1;
}
void Connection::deleteSdEventSource(sd_event_source *s)
void Connection::deleteSdEventSource(sd_event_source *source)
{
#if LIBSYSTEMD_VERSION>=243
sd_event_source_disable_unref(s);
sd_event_source_disable_unref(source);
#else
sd_event_source_set_enabled(s, SD_EVENT_OFF);
sd_event_source_unref(s);
@ -467,7 +477,7 @@ Slot Connection::addObjectVTable( const ObjectPath& objectPath
SDBUS_THROW_ERROR_IF(r < 0, "Failed to register object vtable", -r);
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref((sd_bus_slot*)slot); }};
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref(static_cast<sd_bus_slot*>(slot)); }};
}
PlainMessage Connection::createPlainMessage() const
@ -478,6 +488,8 @@ PlainMessage Connection::createPlainMessage() const
SDBUS_THROW_ERROR_IF(r < 0, "Failed to create a plain message", -r);
// TODO: const_cast..? Finish the const correctness design
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return Message::Factory::create<PlainMessage>(sdbusMsg, const_cast<Connection*>(this), adopt_message);
}
@ -498,13 +510,15 @@ MethodCall Connection::createMethodCall( const char* destination
auto r = sdbus_->sd_bus_message_new_method_call( bus_.get()
, &sdbusMsg
, !*destination ? nullptr : destination
, *destination == '\0' ? nullptr : destination
, objectPath
, interfaceName
, methodName);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to create method call", -r);
// TODO: const_cast..? Finish the const correctness design
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return Message::Factory::create<MethodCall>(sdbusMsg, const_cast<Connection*>(this), adopt_message);
}
@ -525,6 +539,8 @@ Signal Connection::createSignal( const char* objectPath
SDBUS_THROW_ERROR_IF(r < 0, "Failed to create signal", -r);
// TODO: const_cast..? Finish the const correctness design
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return Message::Factory::create<Signal>(sdbusMsg, const_cast<Connection*>(this), adopt_message);
}
@ -544,7 +560,7 @@ void Connection::emitPropertiesChangedSignal( const char* objectPath
auto r = sdbus_->sd_bus_emit_properties_changed_strv( bus_.get()
, objectPath
, interfaceName
, propNames.empty() ? nullptr : &names[0] );
, propNames.empty() ? nullptr : names.data() );
SDBUS_THROW_ERROR_IF(r < 0, "Failed to emit PropertiesChanged signal", -r);
}
@ -563,7 +579,7 @@ void Connection::emitInterfacesAddedSignal( const ObjectPath& objectPath
auto r = sdbus_->sd_bus_emit_interfaces_added_strv( bus_.get()
, objectPath.c_str()
, interfaces.empty() ? nullptr : &names[0] );
, interfaces.empty() ? nullptr : names.data() );
SDBUS_THROW_ERROR_IF(r < 0, "Failed to emit InterfacesAdded signal", -r);
}
@ -582,7 +598,7 @@ void Connection::emitInterfacesRemovedSignal( const ObjectPath& objectPath
auto r = sdbus_->sd_bus_emit_interfaces_removed_strv( bus_.get()
, objectPath.c_str()
, interfaces.empty() ? nullptr : &names[0] );
, interfaces.empty() ? nullptr : names.data() );
SDBUS_THROW_ERROR_IF(r < 0, "Failed to emit InterfacesRemoved signal", -r);
}
@ -599,16 +615,16 @@ Slot Connection::registerSignalHandler( const char* sender
auto r = sdbus_->sd_bus_match_signal( bus_.get()
, &slot
, !*sender ? nullptr : sender
, !*objectPath ? nullptr : objectPath
, !*interfaceName ? nullptr : interfaceName
, !*signalName ? nullptr : signalName
, *sender == '\0' ? nullptr : sender
, *objectPath == '\0' ? nullptr : objectPath
, *interfaceName == '\0' ? nullptr : interfaceName
, *signalName == '\0' ? nullptr : signalName
, callback
, userData );
SDBUS_THROW_ERROR_IF(r < 0, "Failed to register signal handler", -r);
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref((sd_bus_slot*)slot); }};
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref(static_cast<sd_bus_slot*>(slot)); }};
}
sd_bus_message* Connection::incrementMessageRefCount(sd_bus_message* sdbusMsg)
@ -646,7 +662,7 @@ sd_bus_message* Connection::callMethod(sd_bus_message* sdbusMsg, uint64_t timeou
sd_bus_message* sdbusReply{};
auto r = sdbus_->sd_bus_call(nullptr, sdbusMsg, timeout, &sdbusError, &sdbusReply);
if (sd_bus_error_is_set(&sdbusError))
if (sd_bus_error_is_set(&sdbusError)) // NOLINT(readability-implicit-bool-conversion)
throw Error(Error::Name{sdbusError.name}, sdbusError.message);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to call method", -r);
@ -664,7 +680,7 @@ Slot Connection::callMethodAsync(sd_bus_message* sdbusMsg, sd_bus_message_handle
// TODO: Think of ways of optimizing these three locking/unlocking of sdbus mutex (merge into one call?)
auto timeoutBefore = getEventLoopPollData().timeout;
auto r = sdbus_->sd_bus_call_async(nullptr, &slot, sdbusMsg, (sd_bus_message_handler_t)callback, userData, timeout);
auto r = sdbus_->sd_bus_call_async(nullptr, &slot, sdbusMsg, callback, userData, timeout);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to call method asynchronously", -r);
auto timeoutAfter = getEventLoopPollData().timeout;
@ -674,7 +690,7 @@ Slot Connection::callMethodAsync(sd_bus_message* sdbusMsg, sd_bus_message_handle
if (timeoutAfter < timeoutBefore || arePendingMessagesInQueues())
notifyEventLoopToWakeUpFromPoll();
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref((sd_bus_slot*)slot); }};
return {slot, [this](void *slot){ sdbus_->sd_bus_slot_unref(static_cast<sd_bus_slot*>(slot)); }};
}
void Connection::sendMessage(sd_bus_message* sdbusMsg)
@ -783,7 +799,7 @@ void Connection::joinWithEventLoop()
bool Connection::processPendingEvent()
{
auto bus = bus_.get();
auto *bus = bus_.get();
assert(bus != nullptr);
int r = sdbus_->sd_bus_process(bus, nullptr);
@ -798,7 +814,7 @@ bool Connection::processPendingEvent()
return r > 0;
}
bool Connection::waitForNextEvent()
bool Connection::waitForNextEvent() // NOLINT(misc-no-recursion)
{
assert(bus_ != nullptr);
assert(loopExitFd_.fd >= 0);
@ -821,7 +837,7 @@ bool Connection::waitForNextEvent()
SDBUS_THROW_ERROR_IF(r < 0, "Failed to wait on the bus", -errno);
// Wake up notification, in order that we re-enter poll with freshly read PollData (namely, new poll timeout thereof)
if (fds[1].revents & POLLIN)
if (fds[1].revents & POLLIN) // NOLINT(readability-implicit-bool-conversion)
{
auto cleared = eventFd_.clear();
SDBUS_THROW_ERROR_IF(!cleared, "Failed to read from the event descriptor", -errno);
@ -829,7 +845,7 @@ bool Connection::waitForNextEvent()
return waitForNextEvent();
}
// Loop exit notification
if (fds[2].revents & POLLIN)
if (fds[2].revents & POLLIN) // NOLINT(readability-implicit-bool-conversion)
{
auto cleared = loopExitFd_.clear();
SDBUS_THROW_ERROR_IF(!cleared, "Failed to read from the loop exit descriptor", -errno);
@ -854,6 +870,8 @@ Message Connection::getCurrentlyProcessedMessage() const
{
auto* sdbusMsg = sdbus_->sd_bus_get_current_message(bus_.get());
// TODO: const_cast..? Finish the const correctness design
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return Message::Factory::create<Message>(sdbusMsg, const_cast<Connection*>(this));
}
@ -861,8 +879,9 @@ template <typename StringBasedType>
std::vector</*const */char*> Connection::to_strv(const std::vector<StringBasedType>& strings)
{
std::vector</*const */char*> strv;
strv.reserve(strings.size());
for (auto& str : strings)
strv.push_back(const_cast<char*>(str.c_str()));
strv.push_back(const_cast<char*>(str.c_str())); // NOLINT(cppcoreguidelines-pro-type-const-cast)
strv.push_back(nullptr);
return strv;
}
@ -894,8 +913,8 @@ int Connection::sdbus_match_install_callback(sd_bus_message *sdbusMessage, void
}
Connection::EventFd::EventFd()
: fd(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK))
{
fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
SDBUS_THROW_ERROR_IF(fd < 0, "Failed to create event object", -errno);
}
@ -905,14 +924,14 @@ Connection::EventFd::~EventFd()
close(fd);
}
void Connection::EventFd::notify()
void Connection::EventFd::notify() const
{
assert(fd >= 0);
auto r = eventfd_write(fd, 1);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to notify event descriptor", -errno);
}
bool Connection::EventFd::clear()
bool Connection::EventFd::clear() const
{
assert(fd >= 0);
@ -933,10 +952,10 @@ std::chrono::microseconds IConnection::PollData::getRelativeTimeout() const
if (timeout == zero)
return zero;
else if (timeout == max)
if (timeout == max)
return max;
else
return std::max(std::chrono::duration_cast<std::chrono::microseconds>(timeout - now()), zero);
return std::max(std::chrono::duration_cast<std::chrono::microseconds>(timeout - now()), zero);
}
int IConnection::PollData::getPollTimeout() const
@ -945,8 +964,8 @@ int IConnection::PollData::getPollTimeout() const
if (relativeTimeout == decltype(relativeTimeout)::max())
return -1;
else
return static_cast<int>(std::chrono::ceil<std::chrono::milliseconds>(relativeTimeout).count());
return static_cast<int>(std::chrono::ceil<std::chrono::milliseconds>(relativeTimeout).count());
}
} // namespace sdbus

View File

@ -202,24 +202,24 @@ namespace sdbus::internal {
private:
#ifndef SDBUS_basu // sd_event integration is not supported if instead of libsystemd we are based on basu
Slot createSdEventSlot(sd_event *event);
static Slot createSdEventSlot(sd_event *event);
Slot createSdTimeEventSourceSlot(sd_event *event, int priority);
Slot createSdIoEventSourceSlot(sd_event *event, int fd, int priority);
Slot createSdInternalEventSourceSlot(sd_event *event, int fd, int priority);
static void deleteSdEventSource(sd_event_source *s);
static void deleteSdEventSource(sd_event_source *source);
static int onSdTimerEvent(sd_event_source *s, uint64_t usec, void *userdata);
static int onSdIoEvent(sd_event_source *s, int fd, uint32_t revents, void *userdata);
static int onSdInternalEvent(sd_event_source *s, int fd, uint32_t revents, void *userdata);
static int onSdEventPrepare(sd_event_source *s, void *userdata);
static int onSdTimerEvent(sd_event_source *source, uint64_t usec, void *userdata);
static int onSdIoEvent(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static int onSdInternalEvent(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static int onSdEventPrepare(sd_event_source *source, void *userdata);
#endif
struct EventFd
{
EventFd();
~EventFd();
void notify();
bool clear();
void notify() const;
bool clear() const;
int fd{-1};
};

View File

@ -44,6 +44,6 @@ namespace sdbus
message.append(sdbusError.message);
message.append(")");
return Error(std::move(name), std::move(message));
return {std::move(name), std::move(message)};
}
} // namespace sdbus

View File

@ -33,7 +33,6 @@ namespace sdbus
{
uint64_t sdbusFlags{};
using namespace sdbus;
if (flags_.test(Flags::DEPRECATED))
sdbusFlags |= SD_BUS_VTABLE_DEPRECATED;
if (!flags_.test(Flags::PRIVILEGED))
@ -55,7 +54,6 @@ namespace sdbus
{
uint64_t sdbusFlags{};
using namespace sdbus;
if (flags_.test(Flags::DEPRECATED))
sdbusFlags |= SD_BUS_VTABLE_DEPRECATED;
if (!flags_.test(Flags::PRIVILEGED))
@ -70,7 +68,6 @@ namespace sdbus
{
uint64_t sdbusFlags{};
using namespace sdbus;
if (flags_.test(Flags::DEPRECATED))
sdbusFlags |= SD_BUS_VTABLE_DEPRECATED;
@ -81,7 +78,6 @@ namespace sdbus
{
uint64_t sdbusFlags{};
using namespace sdbus;
if (flags_.test(Flags::DEPRECATED))
sdbusFlags |= SD_BUS_VTABLE_DEPRECATED;
//if (!flags_.test(Flags::PRIVILEGED))
@ -103,10 +99,9 @@ namespace sdbus
{
auto sdbusFlags = toSdBusPropertyFlags();
using namespace sdbus;
if (!flags_.test(Flags::PRIVILEGED))
sdbusFlags |= SD_BUS_VTABLE_UNPRIVILEGED;
return sdbusFlags;
}
}
} // namespace sdbus

View File

@ -35,6 +35,7 @@
#include <cassert>
#include <cstring>
#include <tuple> // std::ignore
#include SDBUS_HEADER
namespace sdbus {
@ -51,7 +52,7 @@ Message::Message(void *msg, internal::IConnection* connection) noexcept
{
assert(msg_ != nullptr);
assert(connection_ != nullptr);
connection_->incrementMessageRefCount((sd_bus_message*)msg_);
connection_->incrementMessageRefCount(static_cast<sd_bus_message*>(msg_));
}
Message::Message(void *msg, internal::IConnection* connection, adopt_message_t) noexcept
@ -69,14 +70,17 @@ Message::Message(const Message& other) noexcept
Message& Message::operator=(const Message& other) noexcept
{
if (this == &other)
return *this;
if (msg_)
connection_->decrementMessageRefCount((sd_bus_message*)msg_);
connection_->decrementMessageRefCount(static_cast<sd_bus_message*>(msg_));
msg_ = other.msg_;
connection_ = other.connection_;
ok_ = other.ok_;
connection_->incrementMessageRefCount((sd_bus_message*)msg_);
connection_->incrementMessageRefCount(static_cast<sd_bus_message*>(msg_));
return *this;
}
@ -89,7 +93,7 @@ Message::Message(Message&& other) noexcept
Message& Message::operator=(Message&& other) noexcept
{
if (msg_)
connection_->decrementMessageRefCount((sd_bus_message*)msg_);
connection_->decrementMessageRefCount(static_cast<sd_bus_message*>(msg_));
msg_ = other.msg_;
other.msg_ = nullptr;
@ -104,18 +108,18 @@ Message& Message::operator=(Message&& other) noexcept
Message::~Message()
{
if (msg_)
connection_->decrementMessageRefCount((sd_bus_message*)msg_);
connection_->decrementMessageRefCount(static_cast<sd_bus_message*>(msg_));
}
Message& Message::operator<<(bool item)
{
int intItem = item;
int intItem = item; // NOLINT(readability-implicit-bool-conversion)
// Direct sd-bus method, bypassing SdBus mutex, are called here, since Message serialization/deserialization,
// as well as getter/setter methods are not thread safe by design. Additionally, they are called frequently,
// so some overhead is spared. What is thread-safe in Message class is Message constructors, copy/move operations
// and the destructor, so the Message instance can be passed from one thread to another safely.
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_BOOLEAN, &intItem);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_BOOLEAN, &intItem);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a bool value", -r);
return *this;
@ -123,7 +127,7 @@ Message& Message::operator<<(bool item)
Message& Message::operator<<(int16_t item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_INT16, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_INT16, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a int16_t value", -r);
return *this;
@ -131,7 +135,7 @@ Message& Message::operator<<(int16_t item)
Message& Message::operator<<(int32_t item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_INT32, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_INT32, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a int32_t value", -r);
return *this;
@ -139,7 +143,7 @@ Message& Message::operator<<(int32_t item)
Message& Message::operator<<(int64_t item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_INT64, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_INT64, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a int64_t value", -r);
return *this;
@ -147,7 +151,7 @@ Message& Message::operator<<(int64_t item)
Message& Message::operator<<(uint8_t item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_BYTE, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_BYTE, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a byte value", -r);
return *this;
@ -155,7 +159,7 @@ Message& Message::operator<<(uint8_t item)
Message& Message::operator<<(uint16_t item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UINT16, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UINT16, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a uint16_t value", -r);
return *this;
@ -163,7 +167,7 @@ Message& Message::operator<<(uint16_t item)
Message& Message::operator<<(uint32_t item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UINT32, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UINT32, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a uint32_t value", -r);
return *this;
@ -171,7 +175,7 @@ Message& Message::operator<<(uint32_t item)
Message& Message::operator<<(uint64_t item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UINT64, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UINT64, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a uint64_t value", -r);
return *this;
@ -179,7 +183,7 @@ Message& Message::operator<<(uint64_t item)
Message& Message::operator<<(double item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_DOUBLE, &item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_DOUBLE, &item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a double value", -r);
return *this;
@ -187,7 +191,7 @@ Message& Message::operator<<(double item)
Message& Message::operator<<(const char* item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_STRING, item);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_STRING, item);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a C-string value", -r);
return *this;
@ -195,7 +199,7 @@ Message& Message::operator<<(const char* item)
Message& Message::operator<<(const std::string& item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_STRING, item.c_str());
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_STRING, item.c_str());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a string value", -r);
return *this;
@ -204,7 +208,7 @@ Message& Message::operator<<(const std::string& item)
Message& Message::operator<<(std::string_view item)
{
char* destPtr{};
auto r = sd_bus_message_append_string_space((sd_bus_message*)msg_, item.length(), &destPtr);
auto r = sd_bus_message_append_string_space(static_cast<sd_bus_message*>(msg_), item.length(), &destPtr);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a string_view value", -r);
std::memcpy(destPtr, item.data(), item.length());
@ -221,7 +225,7 @@ Message& Message::operator<<(const Variant &item)
Message& Message::operator<<(const ObjectPath &item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_OBJECT_PATH, item.c_str());
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_OBJECT_PATH, item.c_str());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize an ObjectPath value", -r);
return *this;
@ -229,7 +233,7 @@ Message& Message::operator<<(const ObjectPath &item)
Message& Message::operator<<(const Signature &item)
{
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_SIGNATURE, item.c_str());
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_SIGNATURE, item.c_str());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a Signature value", -r);
return *this;
@ -238,7 +242,7 @@ Message& Message::operator<<(const Signature &item)
Message& Message::operator<<(const UnixFd &item)
{
auto fd = item.get();
auto r = sd_bus_message_append_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UNIX_FD, &fd);
auto r = sd_bus_message_append_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UNIX_FD, &fd);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize a UnixFd value", -r);
return *this;
@ -246,7 +250,7 @@ Message& Message::operator<<(const UnixFd &item)
Message& Message::appendArray(char type, const void *ptr, size_t size)
{
auto r = sd_bus_message_append_array((sd_bus_message*)msg_, type, ptr, size);
auto r = sd_bus_message_append_array(static_cast<sd_bus_message*>(msg_), type, ptr, size);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to serialize an array", -r);
return *this;
@ -254,8 +258,8 @@ Message& Message::appendArray(char type, const void *ptr, size_t size)
Message& Message::operator>>(bool& item)
{
int intItem;
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_BOOLEAN, &intItem);
int intItem{};
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_BOOLEAN, &intItem);
if (r == 0)
ok_ = false;
@ -268,7 +272,7 @@ Message& Message::operator>>(bool& item)
Message& Message::operator>>(int16_t& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_INT16, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_INT16, &item);
if (r == 0)
ok_ = false;
@ -279,7 +283,7 @@ Message& Message::operator>>(int16_t& item)
Message& Message::operator>>(int32_t& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_INT32, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_INT32, &item);
if (r == 0)
ok_ = false;
@ -290,7 +294,7 @@ Message& Message::operator>>(int32_t& item)
Message& Message::operator>>(int64_t& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_INT64, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_INT64, &item);
if (r == 0)
ok_ = false;
@ -301,7 +305,7 @@ Message& Message::operator>>(int64_t& item)
Message& Message::operator>>(uint8_t& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_BYTE, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_BYTE, &item);
if (r == 0)
ok_ = false;
@ -312,7 +316,7 @@ Message& Message::operator>>(uint8_t& item)
Message& Message::operator>>(uint16_t& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UINT16, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UINT16, &item);
if (r == 0)
ok_ = false;
@ -323,7 +327,7 @@ Message& Message::operator>>(uint16_t& item)
Message& Message::operator>>(uint32_t& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UINT32, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UINT32, &item);
if (r == 0)
ok_ = false;
@ -334,7 +338,7 @@ Message& Message::operator>>(uint32_t& item)
Message& Message::operator>>(uint64_t& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UINT64, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UINT64, &item);
if (r == 0)
ok_ = false;
@ -345,7 +349,7 @@ Message& Message::operator>>(uint64_t& item)
Message& Message::readArray(char type, const void **ptr, size_t *size)
{
auto r = sd_bus_message_read_array((sd_bus_message*)msg_, type, ptr, size);
auto r = sd_bus_message_read_array(static_cast<sd_bus_message*>(msg_), type, ptr, size);
if (r == 0)
ok_ = false;
@ -356,7 +360,7 @@ Message& Message::readArray(char type, const void **ptr, size_t *size)
Message& Message::operator>>(double& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_DOUBLE, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_DOUBLE, &item);
if (r == 0)
ok_ = false;
@ -367,7 +371,7 @@ Message& Message::operator>>(double& item)
Message& Message::operator>>(char*& item)
{
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_STRING, &item);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_STRING, &item);
if (r == 0)
ok_ = false;
@ -403,7 +407,7 @@ Message& Message::operator>>(Variant &item)
Message& Message::operator>>(ObjectPath &item)
{
char* str{};
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_OBJECT_PATH, &str);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_OBJECT_PATH, &str);
if (r == 0)
ok_ = false;
@ -418,7 +422,7 @@ Message& Message::operator>>(ObjectPath &item)
Message& Message::operator>>(Signature &item)
{
char* str{};
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_SIGNATURE, &str);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_SIGNATURE, &str);
if (r == 0)
ok_ = false;
@ -433,7 +437,7 @@ Message& Message::operator>>(Signature &item)
Message& Message::operator>>(UnixFd &item)
{
int fd = -1;
auto r = sd_bus_message_read_basic((sd_bus_message*)msg_, SD_BUS_TYPE_UNIX_FD, &fd);
auto r = sd_bus_message_read_basic(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_UNIX_FD, &fd);
if (r == 0)
ok_ = false;
@ -446,7 +450,7 @@ Message& Message::operator>>(UnixFd &item)
Message& Message::openContainer(const char* signature)
{
auto r = sd_bus_message_open_container((sd_bus_message*)msg_, SD_BUS_TYPE_ARRAY, signature);
auto r = sd_bus_message_open_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_ARRAY, signature);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to open a container", -r);
return *this;
@ -454,7 +458,7 @@ Message& Message::openContainer(const char* signature)
Message& Message::closeContainer()
{
auto r = sd_bus_message_close_container((sd_bus_message*)msg_);
auto r = sd_bus_message_close_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to close a container", -r);
return *this;
@ -462,7 +466,7 @@ Message& Message::closeContainer()
Message& Message::openDictEntry(const char* signature)
{
auto r = sd_bus_message_open_container((sd_bus_message*)msg_, SD_BUS_TYPE_DICT_ENTRY, signature);
auto r = sd_bus_message_open_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_DICT_ENTRY, signature);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to open a dictionary entry", -r);
return *this;
@ -470,7 +474,7 @@ Message& Message::openDictEntry(const char* signature)
Message& Message::closeDictEntry()
{
auto r = sd_bus_message_close_container((sd_bus_message*)msg_);
auto r = sd_bus_message_close_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to close a dictionary entry", -r);
return *this;
@ -478,7 +482,7 @@ Message& Message::closeDictEntry()
Message& Message::openVariant(const char* signature)
{
auto r = sd_bus_message_open_container((sd_bus_message*)msg_, SD_BUS_TYPE_VARIANT, signature);
auto r = sd_bus_message_open_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_VARIANT, signature);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to open a variant", -r);
return *this;
@ -486,7 +490,7 @@ Message& Message::openVariant(const char* signature)
Message& Message::closeVariant()
{
auto r = sd_bus_message_close_container((sd_bus_message*)msg_);
auto r = sd_bus_message_close_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to close a variant", -r);
return *this;
@ -494,7 +498,7 @@ Message& Message::closeVariant()
Message& Message::openStruct(const char* signature)
{
auto r = sd_bus_message_open_container((sd_bus_message*)msg_, SD_BUS_TYPE_STRUCT, signature);
auto r = sd_bus_message_open_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_STRUCT, signature);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to open a struct", -r);
return *this;
@ -502,7 +506,7 @@ Message& Message::openStruct(const char* signature)
Message& Message::closeStruct()
{
auto r = sd_bus_message_close_container((sd_bus_message*)msg_);
auto r = sd_bus_message_close_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to close a struct", -r);
return *this;
@ -510,7 +514,7 @@ Message& Message::closeStruct()
Message& Message::enterContainer(const char* signature)
{
auto r = sd_bus_message_enter_container((sd_bus_message*)msg_, SD_BUS_TYPE_ARRAY, signature);
auto r = sd_bus_message_enter_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_ARRAY, signature);
if (r == 0)
ok_ = false;
@ -521,7 +525,7 @@ Message& Message::enterContainer(const char* signature)
Message& Message::exitContainer()
{
auto r = sd_bus_message_exit_container((sd_bus_message*)msg_);
auto r = sd_bus_message_exit_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to exit a container", -r);
return *this;
@ -529,7 +533,7 @@ Message& Message::exitContainer()
Message& Message::enterDictEntry(const char* signature)
{
auto r = sd_bus_message_enter_container((sd_bus_message*)msg_, SD_BUS_TYPE_DICT_ENTRY, signature);
auto r = sd_bus_message_enter_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_DICT_ENTRY, signature);
if (r == 0)
ok_ = false;
@ -540,7 +544,7 @@ Message& Message::enterDictEntry(const char* signature)
Message& Message::exitDictEntry()
{
auto r = sd_bus_message_exit_container((sd_bus_message*)msg_);
auto r = sd_bus_message_exit_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to exit a dictionary entry", -r);
return *this;
@ -548,7 +552,7 @@ Message& Message::exitDictEntry()
Message& Message::enterVariant(const char* signature)
{
auto r = sd_bus_message_enter_container((sd_bus_message*)msg_, SD_BUS_TYPE_VARIANT, signature);
auto r = sd_bus_message_enter_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_VARIANT, signature);
if (r == 0)
ok_ = false;
@ -559,7 +563,7 @@ Message& Message::enterVariant(const char* signature)
Message& Message::exitVariant()
{
auto r = sd_bus_message_exit_container((sd_bus_message*)msg_);
auto r = sd_bus_message_exit_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to exit a variant", -r);
return *this;
@ -567,7 +571,7 @@ Message& Message::exitVariant()
Message& Message::enterStruct(const char* signature)
{
auto r = sd_bus_message_enter_container((sd_bus_message*)msg_, SD_BUS_TYPE_STRUCT, signature);
auto r = sd_bus_message_enter_container(static_cast<sd_bus_message*>(msg_), SD_BUS_TYPE_STRUCT, signature);
if (r == 0)
ok_ = false;
@ -578,7 +582,7 @@ Message& Message::enterStruct(const char* signature)
Message& Message::exitStruct()
{
auto r = sd_bus_message_exit_container((sd_bus_message*)msg_);
auto r = sd_bus_message_exit_container(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to exit a struct", -r);
return *this;
@ -597,7 +601,7 @@ void Message::clearFlags()
void Message::copyTo(Message& destination, bool complete) const
{
auto r = sd_bus_message_copy((sd_bus_message*)destination.msg_, (sd_bus_message*)msg_, complete);
auto r = sd_bus_message_copy(static_cast<sd_bus_message*>(destination.msg_), static_cast<sd_bus_message*>(msg_), complete); // NOLINT(readability-implicit-bool-conversion)
SDBUS_THROW_ERROR_IF(r < 0, "Failed to copy the message", -r);
}
@ -605,46 +609,54 @@ void Message::seal()
{
const auto messageCookie = 1;
const auto sealTimeout = 0;
auto r = sd_bus_message_seal((sd_bus_message*)msg_, messageCookie, sealTimeout);
auto r = sd_bus_message_seal(static_cast<sd_bus_message*>(msg_), messageCookie, sealTimeout);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to seal the message", -r);
}
void Message::rewind(bool complete)
{
auto r = sd_bus_message_rewind((sd_bus_message*)msg_, complete);
auto r = sd_bus_message_rewind(static_cast<sd_bus_message*>(msg_), complete); // NOLINT(readability-implicit-bool-conversion)
SDBUS_THROW_ERROR_IF(r < 0, "Failed to rewind the message", -r);
}
const char* Message::getInterfaceName() const
{
return sd_bus_message_get_interface((sd_bus_message*)msg_);
return sd_bus_message_get_interface(static_cast<sd_bus_message*>(msg_));
}
const char* Message::getMemberName() const
{
return sd_bus_message_get_member((sd_bus_message*)msg_);
return sd_bus_message_get_member(static_cast<sd_bus_message*>(msg_));
}
const char* Message::getSender() const
{
return sd_bus_message_get_sender((sd_bus_message*)msg_);
return sd_bus_message_get_sender(static_cast<sd_bus_message*>(msg_));
}
const char* Message::getPath() const
{
return sd_bus_message_get_path((sd_bus_message*)msg_);
return sd_bus_message_get_path(static_cast<sd_bus_message*>(msg_));
}
const char* Message::getDestination() const
{
return sd_bus_message_get_destination((sd_bus_message*)msg_);
return sd_bus_message_get_destination(static_cast<sd_bus_message*>(msg_));
}
uint64_t Message::getCookie() const
{
uint64_t cookie{};
auto r = sd_bus_message_get_cookie(static_cast<sd_bus_message*>(msg_), &cookie);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get cookie", -r);
return cookie;
}
std::pair<char, const char*> Message::peekType() const
{
char typeSignature{};
const char* contentsSignature{};
auto r = sd_bus_message_peek_type((sd_bus_message*)msg_, &typeSignature, &contentsSignature);
auto r = sd_bus_message_peek_type(static_cast<sd_bus_message*>(msg_), &typeSignature, &contentsSignature);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to peek message type", -r);
return {typeSignature, contentsSignature};
}
@ -656,12 +668,12 @@ bool Message::isValid() const
bool Message::isEmpty() const
{
return sd_bus_message_is_empty((sd_bus_message*)msg_) != 0;
return sd_bus_message_is_empty(static_cast<sd_bus_message*>(msg_)) != 0;
}
bool Message::isAtEnd(bool complete) const
{
return sd_bus_message_at_end((sd_bus_message*)msg_, complete) > 0;
return sd_bus_message_at_end(static_cast<sd_bus_message*>(msg_), complete) > 0; // NOLINT(readability-implicit-bool-conversion)
}
// TODO: Create a RAII ownership class for creds with copy&move semantics, doing ref()/unref() under the hood.
@ -673,7 +685,7 @@ pid_t Message::getCredsPid() const
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ connection_->decrementCredsRefCount(creds); };
int r = connection_->querySenderCredentials((sd_bus_message*)msg_, mask, &creds);
int r = connection_->querySenderCredentials(static_cast<sd_bus_message*>(msg_), mask, &creds);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus creds", -r);
pid_t pid = 0;
@ -687,10 +699,10 @@ uid_t Message::getCredsUid() const
uint64_t mask = SD_BUS_CREDS_UID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ connection_->decrementCredsRefCount(creds); };
int r = connection_->querySenderCredentials((sd_bus_message*)msg_, mask, &creds);
int r = connection_->querySenderCredentials(static_cast<sd_bus_message*>(msg_), mask, &creds);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus creds", -r);
uid_t uid = (uid_t)-1;
auto uid = static_cast<uid_t>(-1);
r = sd_bus_creds_get_uid(creds, &uid);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus cred uid", -r);
return uid;
@ -701,10 +713,10 @@ uid_t Message::getCredsEuid() const
uint64_t mask = SD_BUS_CREDS_EUID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ connection_->decrementCredsRefCount(creds); };
int r = connection_->querySenderCredentials((sd_bus_message*)msg_, mask, &creds);
int r = connection_->querySenderCredentials(static_cast<sd_bus_message*>(msg_), mask, &creds);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus creds", -r);
uid_t euid = (uid_t)-1;
auto euid = static_cast<uid_t>(-1);
r = sd_bus_creds_get_euid(creds, &euid);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus cred euid", -r);
return euid;
@ -715,10 +727,10 @@ gid_t Message::getCredsGid() const
uint64_t mask = SD_BUS_CREDS_GID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ connection_->decrementCredsRefCount(creds); };
int r = connection_->querySenderCredentials((sd_bus_message*)msg_, mask, &creds);
int r = connection_->querySenderCredentials(static_cast<sd_bus_message*>(msg_), mask, &creds);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus creds", -r);
gid_t gid = (gid_t)-1;
auto gid = static_cast<gid_t>(-1);
r = sd_bus_creds_get_gid(creds, &gid);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus cred gid", -r);
return gid;
@ -729,10 +741,10 @@ gid_t Message::getCredsEgid() const
uint64_t mask = SD_BUS_CREDS_EGID | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ connection_->decrementCredsRefCount(creds); };
int r = connection_->querySenderCredentials((sd_bus_message*)msg_, mask, &creds);
int r = connection_->querySenderCredentials(static_cast<sd_bus_message*>(msg_), mask, &creds);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus creds", -r);
gid_t egid = (gid_t)-1;
auto egid = static_cast<gid_t>(-1);
r = sd_bus_creds_get_egid(creds, &egid);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus cred egid", -r);
return egid;
@ -743,7 +755,7 @@ std::vector<gid_t> Message::getCredsSupplementaryGids() const
uint64_t mask = SD_BUS_CREDS_SUPPLEMENTARY_GIDS | SD_BUS_CREDS_AUGMENT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ connection_->decrementCredsRefCount(creds); };
int r = connection_->querySenderCredentials((sd_bus_message*)msg_, mask, &creds);
int r = connection_->querySenderCredentials(static_cast<sd_bus_message*>(msg_), mask, &creds);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus creds", -r);
const gid_t *cGids = nullptr;
@ -754,7 +766,7 @@ std::vector<gid_t> Message::getCredsSupplementaryGids() const
if (cGids != nullptr)
{
for (int i = 0; i < r; i++)
gids.push_back(cGids[i]);
gids.push_back(cGids[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
return gids;
@ -765,7 +777,7 @@ std::string Message::getSELinuxContext() const
uint64_t mask = SD_BUS_CREDS_AUGMENT | SD_BUS_CREDS_SELINUX_CONTEXT;
sd_bus_creds *creds = nullptr;
SCOPE_EXIT{ connection_->decrementCredsRefCount(creds); };
int r = connection_->querySenderCredentials((sd_bus_message*)msg_, mask, &creds);
int r = connection_->querySenderCredentials(static_cast<sd_bus_message*>(msg_), mask, &creds);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get bus creds", -r);
const char *cLabel = nullptr;
@ -784,13 +796,13 @@ MethodCall::MethodCall( void *msg
void MethodCall::dontExpectReply()
{
auto r = sd_bus_message_set_expect_reply((sd_bus_message*)msg_, 0);
auto r = sd_bus_message_set_expect_reply(static_cast<sd_bus_message*>(msg_), 0);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to set the dont-expect-reply flag", -r);
}
bool MethodCall::doesntExpectReply() const
{
auto r = sd_bus_message_get_expect_reply((sd_bus_message*)msg_);
auto r = sd_bus_message_get_expect_reply(static_cast<sd_bus_message*>(msg_));
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get the dont-expect-reply flag", -r);
return r == 0;
}
@ -799,51 +811,59 @@ MethodReply MethodCall::send(uint64_t timeout) const
{
if (!doesntExpectReply())
return sendWithReply(timeout);
else
return sendWithNoReply();
return sendWithNoReply();
}
MethodReply MethodCall::sendWithReply(uint64_t timeout) const
{
auto* sdbusReply = connection_->callMethod((sd_bus_message*)msg_, timeout);
auto* sdbusReply = connection_->callMethod(static_cast<sd_bus_message*>(msg_), timeout);
return Factory::create<MethodReply>(sdbusReply, connection_, adopt_message);
}
MethodReply MethodCall::sendWithNoReply() const
{
connection_->sendMessage((sd_bus_message*)msg_);
connection_->sendMessage(static_cast<sd_bus_message*>(msg_));
return Factory::create<MethodReply>(); // No reply
}
Slot MethodCall::send(void* callback, void* userData, uint64_t timeout, return_slot_t) const
Slot MethodCall::send(void* callback, void* userData, uint64_t timeout, return_slot_t) const // NOLINT(bugprone-easily-swappable-parameters)
{
return connection_->callMethodAsync((sd_bus_message*)msg_, (sd_bus_message_handler_t)callback, userData, timeout, return_slot);
return connection_->callMethodAsync(static_cast<sd_bus_message*>(msg_), reinterpret_cast<sd_bus_message_handler_t>(callback), userData, timeout, return_slot);
}
MethodReply MethodCall::createReply() const
{
auto* sdbusReply = connection_->createMethodReply((sd_bus_message*)msg_);
auto* sdbusReply = connection_->createMethodReply(static_cast<sd_bus_message*>(msg_));
return Factory::create<MethodReply>(sdbusReply, connection_, adopt_message);
}
MethodReply MethodCall::createErrorReply(const Error& error) const
{
sd_bus_message* sdbusErrorReply = connection_->createErrorReplyMessage((sd_bus_message*)msg_, error);
sd_bus_message* sdbusErrorReply = connection_->createErrorReplyMessage(static_cast<sd_bus_message*>(msg_), error);
return Factory::create<MethodReply>(sdbusErrorReply, connection_, adopt_message);
}
void MethodReply::send() const
{
connection_->sendMessage((sd_bus_message*)msg_);
connection_->sendMessage(static_cast<sd_bus_message*>(msg_));
}
uint64_t MethodReply::getReplyCookie() const
{
uint64_t cookie{};
auto r = sd_bus_message_get_reply_cookie(static_cast<sd_bus_message*>(msg_), &cookie);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get cookie", -r);
return cookie;
}
void Signal::send() const
{
connection_->sendMessage((sd_bus_message*)msg_);
connection_->sendMessage(static_cast<sd_bus_message*>(msg_));
}
void Signal::setDestination(const std::string& destination)
@ -853,7 +873,7 @@ void Signal::setDestination(const std::string& destination)
void Signal::setDestination(const char* destination)
{
auto r = sd_bus_message_set_destination((sd_bus_message*)msg_, destination);
auto r = sd_bus_message_set_destination(static_cast<sd_bus_message*>(msg_), destination);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to set signal destination", -r);
}
@ -870,16 +890,16 @@ namespace {
// Another common solution is global sdbus-c++ startup/shutdown functions, but that would be an intrusive change.
#ifdef __cpp_constinit
constinit static bool pseudoConnectionDestroyed{};
constinit bool pseudoConnectionDestroyed{}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
#else
static bool pseudoConnectionDestroyed{};
bool pseudoConnectionDestroyed{}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
#endif
std::unique_ptr<sdbus::internal::IConnection, void(*)(sdbus::internal::IConnection*)> createPseudoConnection()
{
auto deleter = [](sdbus::internal::IConnection* con)
{
delete con;
delete con; // NOLINT(cppcoreguidelines-owning-memory)
pseudoConnectionDestroyed = true;
};
@ -893,7 +913,7 @@ sdbus::internal::IConnection& getPseudoConnectionInstance()
if (pseudoConnectionDestroyed)
{
connection = createPseudoConnection(); // Phoenix rising from the ashes
atexit([](){ connection.~unique_ptr(); }); // We have to manually take care of deleting the phoenix
std::ignore = atexit([](){ connection.~unique_ptr(); }); // We have to manually take care of deleting the phoenix
pseudoConnectionDestroyed = false;
}
@ -902,7 +922,7 @@ sdbus::internal::IConnection& getPseudoConnectionInstance()
return *connection;
}
}
} // namespace
PlainMessage createPlainMessage()
{
@ -914,4 +934,4 @@ PlainMessage createPlainMessage()
return connection.createPlainMessage();
}
}
} // namespace sdbus

View File

@ -69,12 +69,12 @@ Slot Object::addVTable(InterfaceName interfaceName, std::vector<VTableItem> vtab
// 3rd step -- register the vtable with sd-bus
internalVTable->slot = connection_.addObjectVTable( objectPath_
, internalVTable->interfaceName
, &internalVTable->sdbusVTable[0]
, internalVTable->sdbusVTable.data()
, internalVTable.get()
, return_slot );
// Return vtable wrapped in a Slot object
return {internalVTable.release(), [](void *ptr){ delete static_cast<VTable*>(ptr); }};
return {internalVTable.release(), [](void *ptr){ delete static_cast<VTable*>(ptr); }}; // NOLINT(cppcoreguidelines-owning-memory)
}
void Object::unregister()
@ -181,9 +181,9 @@ Object::VTable Object::createInternalVTable(InterfaceName interfaceName, std::ve
}
// Sort arrays so we can do fast searching for an item in sd-bus callback handlers
std::sort(internalVTable.methods.begin(), internalVTable.methods.end(), [](const auto& a, const auto& b){ return a.name < b.name; });
std::sort(internalVTable.signals.begin(), internalVTable.signals.end(), [](const auto& a, const auto& b){ return a.name < b.name; });
std::sort(internalVTable.properties.begin(), internalVTable.properties.end(), [](const auto& a, const auto& b){ return a.name < b.name; });
std::sort(internalVTable.methods.begin(), internalVTable.methods.end(), [](const auto& lhs, const auto& rhs){ return lhs.name < rhs.name; });
std::sort(internalVTable.signals.begin(), internalVTable.signals.end(), [](const auto& lhs, const auto& rhs){ return lhs.name < rhs.name; });
std::sort(internalVTable.properties.begin(), internalVTable.properties.end(), [](const auto& lhs, const auto& rhs){ return lhs.name < rhs.name; });
internalVTable.object = this;
@ -389,7 +389,7 @@ int Object::sdbus_property_set_callback( sd_bus */*bus*/
return ok ? 1 : -1;
}
}
} // namespace sdbus::internal
namespace sdbus {
@ -401,4 +401,4 @@ std::unique_ptr<sdbus::IObject> createObject(sdbus::IConnection& connection, Obj
return std::make_unique<sdbus::internal::Object>(*sdbusConnection, std::move(objectPath));
}
}
} // namespace sdbus

View File

@ -126,12 +126,12 @@ namespace sdbus::internal {
};
VTable createInternalVTable(InterfaceName interfaceName, std::vector<VTableItem> vtable);
void writeInterfaceFlagsToVTable(InterfaceFlagsVTableItem flags, VTable& vtable);
void writeMethodRecordToVTable(MethodVTableItem method, VTable& vtable);
void writeSignalRecordToVTable(SignalVTableItem signal, VTable& vtable);
void writePropertyRecordToVTable(PropertyVTableItem property, VTable& vtable);
static void writeInterfaceFlagsToVTable(InterfaceFlagsVTableItem flags, VTable& vtable);
static void writeMethodRecordToVTable(MethodVTableItem method, VTable& vtable);
static void writeSignalRecordToVTable(SignalVTableItem signal, VTable& vtable);
static void writePropertyRecordToVTable(PropertyVTableItem property, VTable& vtable);
std::vector<sd_bus_vtable> createInternalSdBusVTable(const VTable& vtable);
static std::vector<sd_bus_vtable> createInternalSdBusVTable(const VTable& vtable);
static void startSdBusVTable(const Flags& interfaceFlags, std::vector<sd_bus_vtable>& vtable);
static void writeMethodRecordToSdBusVTable(const VTable::MethodItem& method, std::vector<sd_bus_vtable>& vtable);
static void writeSignalRecordToSdBusVTable(const VTable::SignalItem& signal, std::vector<sd_bus_vtable>& vtable);

View File

@ -124,7 +124,7 @@ PendingAsyncCall Proxy::callMethodAsync(const MethodCall& message, async_reply_h
, .proxy = *this
, .floating = false });
asyncCallInfo->slot = message.send((void*)&Proxy::sdbus_async_reply_handler, asyncCallInfo.get(), timeout, return_slot);
asyncCallInfo->slot = message.send(reinterpret_cast<void*>(&Proxy::sdbus_async_reply_handler), asyncCallInfo.get(), timeout, return_slot);
auto asyncCallInfoWeakPtr = std::weak_ptr{asyncCallInfo};
@ -141,9 +141,9 @@ Slot Proxy::callMethodAsync(const MethodCall& message, async_reply_handler async
, .proxy = *this
, .floating = true });
asyncCallInfo->slot = message.send((void*)&Proxy::sdbus_async_reply_handler, asyncCallInfo.get(), timeout, return_slot);
asyncCallInfo->slot = message.send(reinterpret_cast<void*>(&Proxy::sdbus_async_reply_handler), asyncCallInfo.get(), timeout, return_slot);
return {asyncCallInfo.release(), [](void *ptr){ delete static_cast<AsyncCallInfo*>(ptr); }};
return {asyncCallInfo.release(), [](void *ptr){ delete static_cast<AsyncCallInfo*>(ptr); }}; // NOLINT(cppcoreguidelines-owning-memory)
}
std::future<MethodReply> Proxy::callMethodAsync(const MethodCall& message, with_future_t)
@ -212,7 +212,7 @@ Slot Proxy::registerSignalHandler( const char* interfaceName
, signalInfo.get()
, return_slot );
return {signalInfo.release(), [](void *ptr){ delete static_cast<SignalInfo*>(ptr); }};
return {signalInfo.release(), [](void *ptr){ delete static_cast<SignalInfo*>(ptr); }}; // NOLINT(cppcoreguidelines-owning-memory)
}
void Proxy::unregister()
@ -326,7 +326,7 @@ void Proxy::FloatingAsyncCallSlots::clear()
// mutex) is in progress in a different thread, we get double-mutex deadlock.
}
}
} // namespace sdbus::internal
namespace sdbus {
@ -354,7 +354,7 @@ bool PendingAsyncCall::isPending() const
return !callInfo_.expired();
}
}
} // namespace sdbus
namespace sdbus {
@ -374,11 +374,9 @@ std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<IConnection>&& conne
, ServiceName destination
, ObjectPath objectPath )
{
auto* sdbusConnection = dynamic_cast<sdbus::internal::IConnection*>(connection.get());
auto* sdbusConnection = dynamic_cast<sdbus::internal::IConnection*>(connection.release());
SDBUS_THROW_ERROR_IF(!sdbusConnection, "Connection is not a real sdbus-c++ connection", EINVAL);
connection.release();
return std::make_unique<sdbus::internal::Proxy>( std::unique_ptr<sdbus::internal::IConnection>(sdbusConnection)
, std::move(destination)
, std::move(objectPath) );
@ -389,17 +387,22 @@ std::unique_ptr<sdbus::IProxy> createProxy( std::unique_ptr<IConnection>&& conne
, ObjectPath objectPath
, dont_run_event_loop_thread_t )
{
auto* sdbusConnection = dynamic_cast<sdbus::internal::IConnection*>(connection.get());
auto* sdbusConnection = dynamic_cast<sdbus::internal::IConnection*>(connection.release());
SDBUS_THROW_ERROR_IF(!sdbusConnection, "Connection is not a real sdbus-c++ connection", EINVAL);
connection.release();
return std::make_unique<sdbus::internal::Proxy>( std::unique_ptr<sdbus::internal::IConnection>(sdbusConnection)
, std::move(destination)
, std::move(objectPath)
, dont_run_event_loop_thread );
}
std::unique_ptr<sdbus::IProxy> createLightWeightProxy( std::unique_ptr<IConnection>&& connection
, ServiceName destination
, ObjectPath objectPath )
{
return createProxy(std::move(connection), std::move(destination), std::move(objectPath), dont_run_event_loop_thread);
}
std::unique_ptr<sdbus::IProxy> createProxy( ServiceName destination
, ObjectPath objectPath )
{
@ -428,4 +431,9 @@ std::unique_ptr<sdbus::IProxy> createProxy( ServiceName destination
, dont_run_event_loop_thread );
}
std::unique_ptr<sdbus::IProxy> createLightWeightProxy(ServiceName destination, ObjectPath objectPath)
{
return createProxy(std::move(destination), std::move(objectPath), dont_run_event_loop_thread);
}
} // namespace sdbus

View File

@ -26,87 +26,87 @@
*/
#include "SdBus.h"
#include <sdbus-c++/Error.h>
#include "sdbus-c++/Error.h"
#include <algorithm>
namespace sdbus::internal {
sd_bus_message* SdBus::sd_bus_message_ref(sd_bus_message *m)
sd_bus_message* SdBus::sd_bus_message_ref(sd_bus_message *msg)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_ref(m);
return ::sd_bus_message_ref(msg);
}
sd_bus_message* SdBus::sd_bus_message_unref(sd_bus_message *m)
sd_bus_message* SdBus::sd_bus_message_unref(sd_bus_message *msg)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_unref(m);
return ::sd_bus_message_unref(msg);
}
int SdBus::sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *cookie)
int SdBus::sd_bus_send(sd_bus *bus, sd_bus_message *msg, uint64_t *cookie)
{
std::lock_guard lock(sdbusMutex_);
auto r = ::sd_bus_send(bus, m, cookie);
auto r = ::sd_bus_send(bus, msg, cookie);
if (r < 0)
return r;
return r;
}
int SdBus::sd_bus_call(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *ret_error, sd_bus_message **reply)
int SdBus::sd_bus_call(sd_bus *bus, sd_bus_message *msg, uint64_t usec, sd_bus_error *ret_error, sd_bus_message **reply)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_call(bus, m, usec, ret_error, reply);
return ::sd_bus_call(bus, msg, usec, ret_error, reply);
}
int SdBus::sd_bus_call_async(sd_bus *bus, sd_bus_slot **slot, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec)
int SdBus::sd_bus_call_async(sd_bus *bus, sd_bus_slot **slot, sd_bus_message *msg, sd_bus_message_handler_t callback, void *userdata, uint64_t usec)
{
std::lock_guard lock(sdbusMutex_);
auto r = ::sd_bus_call_async(bus, slot, m, callback, userdata, usec);
auto r = ::sd_bus_call_async(bus, slot, msg, callback, userdata, usec);
if (r < 0)
return r;
return r;
}
int SdBus::sd_bus_message_new(sd_bus *bus, sd_bus_message **m, uint8_t type)
int SdBus::sd_bus_message_new(sd_bus *bus, sd_bus_message **msg, uint8_t type)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_new(bus, m, type);
return ::sd_bus_message_new(bus, msg, type);
}
int SdBus::sd_bus_message_new_method_call(sd_bus *bus, sd_bus_message **m, const char *destination, const char *path, const char *interface, const char *member)
int SdBus::sd_bus_message_new_method_call(sd_bus *bus, sd_bus_message **msg, const char *destination, const char *path, const char *interface, const char *member)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_new_method_call(bus, m, destination, path, interface, member);
return ::sd_bus_message_new_method_call(bus, msg, destination, path, interface, member);
}
int SdBus::sd_bus_message_new_signal(sd_bus *bus, sd_bus_message **m, const char *path, const char *interface, const char *member)
int SdBus::sd_bus_message_new_signal(sd_bus *bus, sd_bus_message **msg, const char *path, const char *interface, const char *member)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_new_signal(bus, m, path, interface, member);
return ::sd_bus_message_new_signal(bus, msg, path, interface, member);
}
int SdBus::sd_bus_message_new_method_return(sd_bus_message *call, sd_bus_message **m)
int SdBus::sd_bus_message_new_method_return(sd_bus_message *call, sd_bus_message **msg)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_new_method_return(call, m);
return ::sd_bus_message_new_method_return(call, msg);
}
int SdBus::sd_bus_message_new_method_error(sd_bus_message *call, sd_bus_message **m, const sd_bus_error *e)
int SdBus::sd_bus_message_new_method_error(sd_bus_message *call, sd_bus_message **msg, const sd_bus_error *err)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_new_method_error(call, m, e);
return ::sd_bus_message_new_method_error(call, msg, err);
}
int SdBus::sd_bus_set_method_call_timeout(sd_bus *bus, uint64_t usec)
@ -197,14 +197,14 @@ int SdBus::sd_bus_open_user_with_address(sd_bus **ret, const char* address)
if (r < 0)
return r;
r = ::sd_bus_set_bus_client(bus, true);
r = ::sd_bus_set_bus_client(bus, true); // NOLINT(readability-implicit-bool-conversion)
if (r < 0)
return r;
// Copying behavior from
// https://github.com/systemd/systemd/blob/fee6441601c979165ebcbb35472036439f8dad5f/src/libsystemd/sd-bus/sd-bus.c#L1381
// Here, we make the bus as trusted
r = ::sd_bus_set_trusted(bus, true);
r = ::sd_bus_set_trusted(bus, true); // NOLINT(readability-implicit-bool-conversion)
if (r < 0)
return r;
@ -276,7 +276,7 @@ int SdBus::sd_bus_open_server(sd_bus **ret, int fd)
if (r < 0)
return r;
r = ::sd_bus_set_server(bus, true, id);
r = ::sd_bus_set_server(bus, true, id); // NOLINT(readability-implicit-bool-conversion)
if (r < 0)
return r;
@ -373,11 +373,11 @@ int SdBus::sd_bus_start(sd_bus *bus)
return ::sd_bus_start(bus);
}
int SdBus::sd_bus_process(sd_bus *bus, sd_bus_message **r)
int SdBus::sd_bus_process(sd_bus *bus, sd_bus_message **msg)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_process(bus, r);
return ::sd_bus_process(bus, msg);
}
sd_bus_message* SdBus::sd_bus_get_current_message(sd_bus *bus)
@ -404,7 +404,7 @@ int SdBus::sd_bus_get_poll_data(sd_bus *bus, PollData* data)
return r;
}
int SdBus::sd_bus_get_n_queued(sd_bus *bus, uint64_t *read, uint64_t* write)
int SdBus::sd_bus_get_n_queued(sd_bus *bus, uint64_t *read, uint64_t* write) // NOLINT(bugprone-easily-swappable-parameters)
{
std::lock_guard lock(sdbusMutex_);
@ -434,81 +434,81 @@ sd_bus* SdBus::sd_bus_close_unref(sd_bus *bus)
#endif
}
int SdBus::sd_bus_message_set_destination(sd_bus_message *m, const char *destination)
int SdBus::sd_bus_message_set_destination(sd_bus_message *msg, const char *destination)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_message_set_destination(m, destination);
return ::sd_bus_message_set_destination(msg, destination);
}
int SdBus::sd_bus_query_sender_creds(sd_bus_message *m, uint64_t mask, sd_bus_creds **c)
int SdBus::sd_bus_query_sender_creds(sd_bus_message *msg, uint64_t mask, sd_bus_creds **creds)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_query_sender_creds(m, mask, c);
return ::sd_bus_query_sender_creds(msg, mask, creds);
}
sd_bus_creds* SdBus::sd_bus_creds_ref(sd_bus_creds *c)
sd_bus_creds* SdBus::sd_bus_creds_ref(sd_bus_creds *creds)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_ref(c);
return ::sd_bus_creds_ref(creds);
}
sd_bus_creds* SdBus::sd_bus_creds_unref(sd_bus_creds *c)
sd_bus_creds* SdBus::sd_bus_creds_unref(sd_bus_creds *creds)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_unref(c);
return ::sd_bus_creds_unref(creds);
}
int SdBus::sd_bus_creds_get_pid(sd_bus_creds *c, pid_t *pid)
int SdBus::sd_bus_creds_get_pid(sd_bus_creds *creds, pid_t *pid)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_get_pid(c, pid);
return ::sd_bus_creds_get_pid(creds, pid);
}
int SdBus::sd_bus_creds_get_uid(sd_bus_creds *c, uid_t *uid)
int SdBus::sd_bus_creds_get_uid(sd_bus_creds *creds, uid_t *uid)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_get_uid(c, uid);
return ::sd_bus_creds_get_uid(creds, uid);
}
int SdBus::sd_bus_creds_get_euid(sd_bus_creds *c, uid_t *euid)
int SdBus::sd_bus_creds_get_euid(sd_bus_creds *creds, uid_t *euid)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_get_euid(c, euid);
return ::sd_bus_creds_get_euid(creds, euid);
}
int SdBus::sd_bus_creds_get_gid(sd_bus_creds *c, gid_t *gid)
int SdBus::sd_bus_creds_get_gid(sd_bus_creds *creds, gid_t *gid)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_get_gid(c, gid);
return ::sd_bus_creds_get_gid(creds, gid);
}
int SdBus::sd_bus_creds_get_egid(sd_bus_creds *c, uid_t *egid)
int SdBus::sd_bus_creds_get_egid(sd_bus_creds *creds, uid_t *egid)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_get_egid(c, egid);
return ::sd_bus_creds_get_egid(creds, egid);
}
int SdBus::sd_bus_creds_get_supplementary_gids(sd_bus_creds *c, const gid_t **gids)
int SdBus::sd_bus_creds_get_supplementary_gids(sd_bus_creds *creds, const gid_t **gids)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_get_supplementary_gids(c, gids);
return ::sd_bus_creds_get_supplementary_gids(creds, gids);
}
int SdBus::sd_bus_creds_get_selinux_context(sd_bus_creds *c, const char **label)
int SdBus::sd_bus_creds_get_selinux_context(sd_bus_creds *creds, const char **label)
{
std::lock_guard lock(sdbusMutex_);
return ::sd_bus_creds_get_selinux_context(c, label);
return ::sd_bus_creds_get_selinux_context(creds, label);
}
}
} // namespace sdbus::internal

View File

@ -62,7 +62,7 @@ public:
virtual int sd_bus_open_system(sd_bus **ret) override;
virtual int sd_bus_open_user(sd_bus **ret) override;
virtual int sd_bus_open_user_with_address(sd_bus **ret, const char* address) override;
virtual int sd_bus_open_system_remote(sd_bus **ret, const char* hsot) override;
virtual int sd_bus_open_system_remote(sd_bus **ret, const char* host) override;
virtual int sd_bus_open_direct(sd_bus **ret, const char* address) override;
virtual int sd_bus_open_direct(sd_bus **ret, int fd) override;
virtual int sd_bus_open_server(sd_bus **ret, int fd) override;
@ -79,7 +79,7 @@ public:
virtual int sd_bus_new(sd_bus **ret) override;
virtual int sd_bus_start(sd_bus *bus) override;
virtual int sd_bus_process(sd_bus *bus, sd_bus_message **r) override;
virtual int sd_bus_process(sd_bus *bus, sd_bus_message **msg) override;
virtual sd_bus_message* sd_bus_get_current_message(sd_bus *bus) override;
virtual int sd_bus_get_poll_data(sd_bus *bus, PollData* data) override;
virtual int sd_bus_get_n_queued(sd_bus *bus, uint64_t *read, uint64_t* write) override;

View File

@ -286,6 +286,14 @@ TYPED_TEST(SdbusTestObject, CanAccessAssociatedMethodCallMessageInMethodCallHand
ASSERT_THAT(this->m_adaptor->m_methodName, Eq("doOperation"));
}
TYPED_TEST(SdbusTestObject, ProvidesSerialInMethodCallAndMethodReplyMessage)
{
auto reply = this->m_proxy->doOperationOnBasicAPILevel(ANY_UNSIGNED_NUMBER);
ASSERT_THAT(this->m_proxy->m_methodCallMsg->getCookie(), Gt(0));
ASSERT_THAT(reply.getReplyCookie(), Eq(this->m_proxy->m_methodCallMsg->getCookie())); // Pairing method reply with method call message
}
TYPED_TEST(SdbusTestObject, CanAccessAssociatedMethodCallMessageInAsyncMethodCallHandler)
{
this->m_proxy->doOperationAsync(10); // This will save pointer to method call message on server side
@ -351,7 +359,7 @@ TYPED_TEST(SdbusTestObject, CanRegisterAdditionalVTableDynamicallyAtAnyTime)
, sdbus::return_slot );
// The new remote vtable is registered as long as we keep vtableSlot, so remote method calls now should pass
auto proxy = sdbus::createProxy(SERVICE_NAME, OBJECT_PATH, sdbus::dont_run_event_loop_thread);
auto proxy = sdbus::createLightWeightProxy(SERVICE_NAME, OBJECT_PATH);
int result{};
proxy->callMethod("subtract").onInterface(interfaceName).withArguments(10, 2).storeResultsTo(result);
@ -370,6 +378,6 @@ TYPED_TEST(SdbusTestObject, CanUnregisterAdditionallyRegisteredVTableAtAnyTime)
vtableSlot.reset(); // Letting the slot go means letting go the associated vtable registration
// No such remote D-Bus method under given interface exists anymore...
auto proxy = sdbus::createProxy(SERVICE_NAME, OBJECT_PATH, sdbus::dont_run_event_loop_thread);
auto proxy = sdbus::createLightWeightProxy(SERVICE_NAME, OBJECT_PATH);
ASSERT_THROW(proxy->callMethod("subtract").onInterface(interfaceName).withArguments(10, 2), sdbus::Error);
}

View File

@ -127,6 +127,26 @@ TYPED_TEST(SdbusTestObject, SetsPropertyAsynchronouslyViaPropertiesInterface)
ASSERT_THAT(this->m_proxy->action(), Eq(newActionValue));
}
TYPED_TEST(SdbusTestObject, CancelsAsynchronousPropertySettingViaPropertiesInterface)
{
uint32_t newActionValue = 2346;
std::promise<void> promise;
auto future = promise.get_future();
{
auto slot = this->m_proxy->SetAsync(INTERFACE_NAME, "action", sdbus::Variant{newActionValue}, [&](std::optional<sdbus::Error> err)
{
if (!err)
promise.set_value();
else
promise.set_exception(std::make_exception_ptr(*std::move(err)));
}, sdbus::return_slot);
// Now the slot is destroyed, cancelling the async call
}
ASSERT_THAT(future.wait_for(300ms), Eq(std::future_status::timeout));
}
TYPED_TEST(SdbusTestObject, SetsPropertyAsynchronouslyViaPropertiesInterfaceWithFuture)
{
uint32_t newActionValue = 2347;
@ -244,6 +264,43 @@ TYPED_TEST(SdbusTestObject, GetsManagedObjectsSuccessfully)
.at(ACTION_PROPERTY).template get<uint32_t>(), Eq(DEFAULT_ACTION_VALUE));
}
TYPED_TEST(SdbusTestObject, GetsManagedObjectsAsynchronously)
{
std::promise<size_t> promise;
auto future = promise.get_future();
auto adaptor2 = std::make_unique<TestAdaptor>(*this->s_adaptorConnection, OBJECT_PATH_2);
this->m_objectManagerProxy->GetManagedObjectsAsync([&](std::optional<sdbus::Error> /*err*/, const std::map<sdbus::ObjectPath, std::map<sdbus::InterfaceName, std::map<sdbus::PropertyName, sdbus::Variant>>>& objectsInterfacesAndProperties)
{
promise.set_value(objectsInterfacesAndProperties.size());
});
ASSERT_THAT(future.get(), Eq(2));
}
TYPED_TEST(SdbusTestObject, GetsManagedObjectsAsynchronouslyViaSlotReturningOverload)
{
std::promise<size_t> promise;
auto future = promise.get_future();
auto adaptor2 = std::make_unique<TestAdaptor>(*this->s_adaptorConnection, OBJECT_PATH_2);
auto slot = this->m_objectManagerProxy->GetManagedObjectsAsync([&](std::optional<sdbus::Error> /*err*/, const std::map<sdbus::ObjectPath, std::map<sdbus::InterfaceName, std::map<sdbus::PropertyName, sdbus::Variant>>>& objectsInterfacesAndProperties)
{
promise.set_value(objectsInterfacesAndProperties.size());
}, sdbus::return_slot);
ASSERT_THAT(future.get(), Eq(2));
}
TYPED_TEST(SdbusTestObject, GetsManagedObjectsAsynchronouslyViaFutureOverload)
{
auto adaptor2 = std::make_unique<TestAdaptor>(*this->s_adaptorConnection, OBJECT_PATH_2);
auto future = this->m_objectManagerProxy->GetManagedObjectsAsync(sdbus::with_future);
ASSERT_THAT(future.get().size(), Eq(2));
}
TYPED_TEST(SdbusTestObject, EmitsInterfacesAddedSignalForSelectedObjectInterfaces)
{
std::atomic<bool> signalReceived{false};

View File

@ -50,6 +50,8 @@
namespace sdbus { namespace test {
inline const uint32_t ANY_UNSIGNED_NUMBER{123};
class BaseTestFixture : public ::testing::Test
{
public:

View File

@ -113,6 +113,16 @@ uint32_t TestProxy::doOperationWithTimeout(const std::chrono::microseconds &time
return result;
}
MethodReply TestProxy::doOperationOnBasicAPILevel(uint32_t param)
{
auto methodCall = getProxy().createMethodCall(test::INTERFACE_NAME, MethodName{"doOperation"});
methodCall << param;
m_methodCallMsg = std::make_unique<MethodCall>(methodCall);
return getProxy().callMethod(methodCall);
}
sdbus::PendingAsyncCall TestProxy::doOperationClientSideAsync(uint32_t param)
{
return getProxy().callMethodAsync("doOperation")

View File

@ -95,6 +95,7 @@ protected:
public:
void installDoOperationClientSideAsyncReplyHandler(std::function<void(uint32_t res, std::optional<sdbus::Error> err)> handler);
uint32_t doOperationWithTimeout(const std::chrono::microseconds &timeout, uint32_t param);
MethodReply doOperationOnBasicAPILevel(uint32_t param);
sdbus::PendingAsyncCall doOperationClientSideAsync(uint32_t param);
[[nodiscard]] sdbus::Slot doOperationClientSideAsync(uint32_t param, sdbus::return_slot_t);
std::future<uint32_t> doOperationClientSideAsync(uint32_t param, with_future_t);
@ -121,6 +122,7 @@ public: // for tests
std::function<void(uint32_t res, std::optional<sdbus::Error> err)> m_DoOperationClientSideAsyncReplyHandler;
std::function<void(const sdbus::InterfaceName&, const std::map<PropertyName, sdbus::Variant>&, const std::vector<PropertyName>&)> m_onPropertiesChangedHandler;
std::unique_ptr<const MethodCall> m_methodCallMsg;
std::unique_ptr<const Message> m_signalMsg;
SignalName m_signalName;
};

View File

@ -62,13 +62,18 @@ public:
registerAdaptor();
}
CelsiusThermometerAdaptor(const CelsiusThermometerAdaptor&) = delete;
CelsiusThermometerAdaptor& operator=(const CelsiusThermometerAdaptor&) = delete;
CelsiusThermometerAdaptor(CelsiusThermometerAdaptor&&) = delete;
CelsiusThermometerAdaptor& operator=(CelsiusThermometerAdaptor&&) = delete;
~CelsiusThermometerAdaptor()
{
unregisterAdaptor();
}
protected:
virtual uint32_t getCurrentTemperature() override
uint32_t getCurrentTemperature() override
{
return m_currentTemperature++;
}
@ -86,6 +91,11 @@ public:
registerProxy();
}
CelsiusThermometerProxy(const CelsiusThermometerProxy&) = delete;
CelsiusThermometerProxy& operator=(const CelsiusThermometerProxy&) = delete;
CelsiusThermometerProxy(CelsiusThermometerProxy&&) = delete;
CelsiusThermometerProxy& operator=(CelsiusThermometerProxy&&) = delete;
~CelsiusThermometerProxy()
{
unregisterProxy();
@ -152,6 +162,11 @@ public:
registerAdaptor();
}
FahrenheitThermometerAdaptor(const FahrenheitThermometerAdaptor&) = delete;
FahrenheitThermometerAdaptor& operator=(const FahrenheitThermometerAdaptor&) = delete;
FahrenheitThermometerAdaptor(FahrenheitThermometerAdaptor&&) = delete;
FahrenheitThermometerAdaptor& operator=(FahrenheitThermometerAdaptor&&) = delete;
~FahrenheitThermometerAdaptor()
{
exit_ = true;
@ -163,13 +178,13 @@ public:
}
protected:
virtual uint32_t getCurrentTemperature() override
uint32_t getCurrentTemperature() override
{
// In this D-Bus call, make yet another D-Bus call to another service over the same connection
return static_cast<uint32_t>(celsiusProxy_.getCurrentTemperature() * 1.8 + 32.);
}
virtual void createDelegateObject(sdbus::Result<sdbus::ObjectPath>&& result) override
void createDelegateObject(sdbus::Result<sdbus::ObjectPath>&& result) override
{
static size_t objectCounter{};
objectCounter++;
@ -180,7 +195,7 @@ protected:
cond_.notify_one();
}
virtual void destroyDelegateObject(sdbus::Result<>&& /*result*/, sdbus::ObjectPath delegate) override
void destroyDelegateObject(sdbus::Result<>&& /*result*/, sdbus::ObjectPath delegate) override
{
std::unique_lock<std::mutex> lock(mutex_);
requests_.push(WorkItem{0, std::move(delegate), {}});
@ -216,6 +231,11 @@ public:
registerProxy();
}
FahrenheitThermometerProxy(const FahrenheitThermometerProxy&) = delete;
FahrenheitThermometerProxy& operator=(const FahrenheitThermometerProxy&) = delete;
FahrenheitThermometerProxy(FahrenheitThermometerProxy&&) = delete;
FahrenheitThermometerProxy& operator=(FahrenheitThermometerProxy&&) = delete;
~FahrenheitThermometerProxy()
{
unregisterProxy();
@ -262,6 +282,11 @@ public:
registerAdaptor();
}
ConcatenatorAdaptor(const ConcatenatorAdaptor&) = delete;
ConcatenatorAdaptor& operator=(const ConcatenatorAdaptor&) = delete;
ConcatenatorAdaptor(ConcatenatorAdaptor&&) = delete;
ConcatenatorAdaptor& operator=(ConcatenatorAdaptor&&) = delete;
~ConcatenatorAdaptor()
{
exit_ = true;
@ -273,7 +298,7 @@ public:
}
protected:
virtual void concatenate(sdbus::Result<std::string>&& result, std::map<std::string, sdbus::Variant> params) override
void concatenate(sdbus::Result<std::string>&& result, std::map<std::string, sdbus::Variant> params) override
{
std::unique_lock<std::mutex> lock(mutex_);
requests_.push(WorkItem{std::move(params), std::move(result)});
@ -303,13 +328,18 @@ public:
registerProxy();
}
ConcatenatorProxy(const ConcatenatorProxy&) = delete;
ConcatenatorProxy& operator=(const ConcatenatorProxy&) = delete;
ConcatenatorProxy(ConcatenatorProxy&&) = delete;
ConcatenatorProxy& operator=(ConcatenatorProxy&&) = delete;
~ConcatenatorProxy()
{
unregisterProxy();
}
private:
virtual void onConcatenateReply(const std::string& result, [[maybe_unused]] std::optional<sdbus::Error> error) override
void onConcatenateReply(const std::string& result, [[maybe_unused]] std::optional<sdbus::Error> error) override
{
assert(error == std::nullopt);
@ -318,21 +348,21 @@ private:
str >> aString;
assert(aString == "sdbus-c++-stress-tests");
uint32_t aNumber;
uint32_t aNumber{};
str >> aNumber;
assert(aNumber > 0);
++repliesReceived_;
}
virtual void onConcatenatedSignal(const std::string& concatenatedString) override
void onConcatenatedSignal(const std::string& concatenatedString) override
{
std::stringstream str(concatenatedString);
std::string aString;
str >> aString;
assert(aString == "sdbus-c++-stress-tests");
uint32_t aNumber;
uint32_t aNumber{};
str >> aNumber;
assert(aNumber > 0);
@ -345,10 +375,10 @@ public:
};
//-----------------------------------------
int main(int argc, char *argv[])
int main(int argc, char *argv[]) // NOLINT(bugprone-exception-escape, readability-function-cognitive-complexity)
{
long loops;
long loopDuration;
long loops{};
long loopDuration{};
if (argc == 1)
{
@ -357,8 +387,8 @@ int main(int argc, char *argv[])
}
else if (argc == 3)
{
loops = std::atol(argv[1]);
loopDuration = std::atol(argv[2]);
loops = std::atol(argv[1]); // NOLINT(cert-err34-c, cppcoreguidelines-pro-bounds-pointer-arithmetic)
loopDuration = std::atol(argv[2]); // NOLINT(cert-err34-c, cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
else
throw std::runtime_error("Wrong program options");
@ -442,8 +472,8 @@ int main(int argc, char *argv[])
// Update statistics
concatenationCallsMade = localCounter;
concatenationRepliesReceived = (uint32_t)concatenator.repliesReceived_;
concatenationSignalsReceived = (uint32_t)concatenator.signalsReceived_;
concatenationRepliesReceived = static_cast<uint32_t>(concatenator.repliesReceived_);
concatenationSignalsReceived = static_cast<uint32_t>(concatenator.signalsReceived_);
}
}
});

View File

@ -121,7 +121,7 @@ std::string AdaptorGenerator::processInterface(Node& interface) const
if(!annotationRegistration.empty())
{
std::stringstream str;
str << "sdbus::setInterfaceFlags()" << annotationRegistration << ";";
str << "sdbus::setInterfaceFlags()" << annotationRegistration;
annotationRegistration = str.str();
}