Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
# 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,\
-llvm-header-guard,\
-google-runtime-int,\
-google-default-arguments,\
-hicpp-named-parameter,\
-readability-named-parameter,\
-bugprone-macro-parentheses,\
-google-readability-todo,\
-google-build-using-namespace,\
-cppcoreguidelines-pro-type-reinterpret-cast,\
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,\
-hicpp-no-array-decay,\
-cppcoreguidelines-avoid-c-arrays,\
-hicpp-avoid-c-arrays,\
-cppcoreguidelines-non-private-member-variables-in-classes,\
-misc-non-private-member-variables-in-classes,\
-modernize-avoid-c-arrays"

HeaderFilterRegex: '.*'
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-implicit-bool-conversion.AllowIntegerConditions
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|t|fd|id|ok|it|ts'
- 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: misc-include-cleaner.IgnoreHeaders
value: 'systemd/.*|sdbus-c\+\+/.*|gtest/.*|gmock/.*|bits/chrono.h|bits/basic_string.h|time.h|poll.h|stdlib.h'
- key: readability-simplify-boolean-expr.IgnoreMacros
value: '1'
- key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams
value: '1'
# - key: bugprone-easily-swappable-parameters.MinimumLength
# value: '3'
# - key: readability-braces-around-statements.ShortStatementLines
# value: '3'
45 changes: 29 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,44 +46,57 @@ jobs:
- 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: |
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 -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 ..
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.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 ..
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'
run: |
cd build
cd _build
cpack -G DEB
- name: 'Upload Artifact'
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 -DSDBUSCPP_BUILD_EXAMPLES=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
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -130,6 +130,8 @@ endif()

find_package(Threads REQUIRED)

include(cmake/clang-tidy.cmake) # Static analysis with clang-tidy

#-------------------------------
# SOURCE FILES CONFIGURATION
#-------------------------------
Expand Down
16 changes: 16 additions & 0 deletions cmake/clang-tidy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#----------------------------------
# STATIC ANALYSIS
#----------------------------------

if(SDBUSCPP_CLANG_TIDY)
message(STATUS "Building with static analysis")
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(DO_CLANG_TIDY "${CLANG_TIDY}")
#set(DO_CLANG_TIDY "${CLANG_TIDY}" "-fix")
set(CMAKE_CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
endif()
endif()
16 changes: 14 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Building examples

add_executable(obj-manager-server org.freedesktop.DBus.ObjectManager/obj-manager-server.cpp)
set(OBJECTMANAGER_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.DBus.ObjectManager)
set(OBJECTMANAGER_GENERATED_DIR ${OBJECTMANAGER_SOURCE_DIR}/dbus-api/gen-cpp)
set(OBJECTMANAGER_SERVER_SRCS
${OBJECTMANAGER_SOURCE_DIR}/obj-manager-server.cpp
${OBJECTMANAGER_GENERATED_DIR}/examplemanager-planet1-server-glue.h)

add_executable(obj-manager-server ${OBJECTMANAGER_SERVER_SRCS})
target_include_directories(obj-manager-server SYSTEM PRIVATE ${OBJECTMANAGER_GENERATED_DIR})
target_link_libraries(obj-manager-server sdbus-c++)

add_executable(obj-manager-client org.freedesktop.DBus.ObjectManager/obj-manager-client.cpp)
set(OBJECTMANAGER_CLIENT_SRCS
${OBJECTMANAGER_SOURCE_DIR}/obj-manager-client.cpp
${OBJECTMANAGER_GENERATED_DIR}/examplemanager-planet1-client-glue.h)

add_executable(obj-manager-client ${OBJECTMANAGER_CLIENT_SRCS})
target_include_directories(obj-manager-client SYSTEM PRIVATE ${OBJECTMANAGER_GENERATED_DIR})
target_link_libraries(obj-manager-client sdbus-c++)

if(SDBUSCPP_INSTALL)
Expand Down
28 changes: 21 additions & 7 deletions examples/org.freedesktop.DBus.ObjectManager/obj-manager-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@
#include "examplemanager-planet1-client-glue.h"
#include <sdbus-c++/sdbus-c++.h>
#include <iostream>
#include <thread>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <memory>

class PlanetProxy final : public sdbus::ProxyInterfaces< org::sdbuscpp::ExampleManager::Planet1_proxy >
{
public:
PlanetProxy(sdbus::IConnection& connection, sdbus::ServiceName destination, sdbus::ObjectPath path)
: ProxyInterfaces(connection, std::move(destination), std::move(path))
: ProxyInterfaces(connection, std::move(destination), std::move(path))
{
registerProxy();
}

PlanetProxy(const PlanetProxy&) = delete;
PlanetProxy& operator=(const PlanetProxy&) = delete;
PlanetProxy(PlanetProxy&&) = delete;
PlanetProxy& operator=(PlanetProxy&&) = delete;

~PlanetProxy()
{
unregisterProxy();
Expand All @@ -35,11 +44,16 @@ class ManagerProxy final : public sdbus::ProxyInterfaces<sdbus::ObjectManager_pr
ManagerProxy(sdbus::IConnection& connection, sdbus::ServiceName destination, sdbus::ObjectPath path)
: ProxyInterfaces(connection, destination, std::move(path))
, m_connection(connection)
, m_destination(destination)
, m_destination(std::move(destination))
{
registerProxy();
}

ManagerProxy(const ManagerProxy&) = delete;
ManagerProxy& operator=(const ManagerProxy&) = delete;
ManagerProxy(ManagerProxy&&) = delete;
ManagerProxy& operator=(ManagerProxy&&) = delete;

~ManagerProxy()
{
unregisterProxy();
Expand All @@ -61,7 +75,7 @@ class ManagerProxy final : public sdbus::ProxyInterfaces<sdbus::ObjectManager_pr
for (const auto& [interface, _] : interfacesAndProperties) {
std::cout << interface << " ";
}
std::cout << std::endl;
std::cout << '\n';

// Parse and print some more info
auto planetInterface = interfacesAndProperties.find(sdbus::InterfaceName{org::sdbuscpp::ExampleManager::Planet1_proxy::INTERFACE_NAME});
Expand All @@ -73,7 +87,7 @@ class ManagerProxy final : public sdbus::ProxyInterfaces<sdbus::ObjectManager_pr
const auto& name = properties.at(sdbus::PropertyName{"Name"}).get<std::string>();
// or create a proxy instance to the newly added object.
PlanetProxy planet(m_connection, m_destination, objectPath);
std::cout << name << " has a population of " << planet.GetPopulation() << ".\n" << std::endl;
std::cout << name << " has a population of " << planet.GetPopulation() << ".\n" << '\n';
}

void onInterfacesRemoved( const sdbus::ObjectPath& objectPath
Expand All @@ -83,7 +97,7 @@ class ManagerProxy final : public sdbus::ProxyInterfaces<sdbus::ObjectManager_pr
for (const auto& interface : interfaces) {
std::cout << interface << " ";
}
std::cout << std::endl;
std::cout << '\n';
}

sdbus::IConnection& m_connection;
Expand All @@ -102,7 +116,7 @@ int main()
}
catch (const sdbus::Error& e) {
if (e.getName() == "org.freedesktop.DBus.Error.ServiceUnknown") {
std::cout << "Waiting for server to start ..." << std::endl;
std::cout << "Waiting for server to start ..." << '\n';
}
}

Expand Down
32 changes: 22 additions & 10 deletions examples/org.freedesktop.DBus.ObjectManager/obj-manager-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
#include <memory>
#include <thread>
#include <chrono>

using sdbus::ObjectPath;
#include <utility>
#include <string>
#include <cstdint>

class ManagerAdaptor : public sdbus::AdaptorInterfaces<sdbus::ObjectManager_adaptor>
{
Expand All @@ -30,6 +31,11 @@ class ManagerAdaptor : public sdbus::AdaptorInterfaces<sdbus::ObjectManager_adap
registerAdaptor();
}

ManagerAdaptor(const ManagerAdaptor&) = delete;
ManagerAdaptor& operator=(const ManagerAdaptor&) = delete;
ManagerAdaptor(ManagerAdaptor&&) = delete;
ManagerAdaptor& operator=(ManagerAdaptor&&) = delete;

~ManagerAdaptor()
{
unregisterAdaptor();
Expand All @@ -47,12 +53,17 @@ class PlanetAdaptor final : public sdbus::AdaptorInterfaces< org::sdbuscpp::Exam
, m_population(population)
{
registerAdaptor();
emitInterfacesAddedSignal({sdbus::InterfaceName{org::sdbuscpp::ExampleManager::Planet1_adaptor::INTERFACE_NAME}});
emitInterfacesAddedSignal({sdbus::InterfaceName{Planet1_adaptor::INTERFACE_NAME}});
}

PlanetAdaptor(const PlanetAdaptor&) = delete;
PlanetAdaptor& operator=(const PlanetAdaptor&) = delete;
PlanetAdaptor(PlanetAdaptor&&) = delete;
PlanetAdaptor& operator=(PlanetAdaptor&&) = delete;

~PlanetAdaptor()
{
emitInterfacesRemovedSignal({sdbus::InterfaceName{org::sdbuscpp::ExampleManager::Planet1_adaptor::INTERFACE_NAME}});
emitInterfacesRemovedSignal({sdbus::InterfaceName{Planet1_adaptor::INTERFACE_NAME}});
unregisterAdaptor();
}

Expand All @@ -78,25 +89,26 @@ void printCountDown(const std::string& message, int seconds)
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << i << " " << std::flush;
}
std::cout << std::endl;
std::cout << '\n';
}

int main()
{
auto connection = sdbus::createSessionBusConnection();
sdbus::ServiceName serviceName{"org.sdbuscpp.examplemanager"};
const sdbus::ServiceName serviceName{"org.sdbuscpp.examplemanager"};
connection->requestName(serviceName);
connection->enterEventLoopAsync();

auto manager = std::make_unique<ManagerAdaptor>(*connection, ObjectPath{"/org/sdbuscpp/examplemanager"});
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
auto manager = std::make_unique<ManagerAdaptor>(*connection, sdbus::ObjectPath{"/org/sdbuscpp/examplemanager"});
while (true)
{
printCountDown("Creating PlanetAdaptor in ", 5);
auto earth = std::make_unique<PlanetAdaptor>(*connection, ObjectPath{"/org/sdbuscpp/examplemanager/Planet1/Earth"}, "Earth", 7'874'965'825);
auto earth = std::make_unique<PlanetAdaptor>(*connection, sdbus::ObjectPath{"/org/sdbuscpp/examplemanager/Planet1/Earth"}, "Earth", 7'874'965'825);
printCountDown("Creating PlanetAdaptor in ", 5);
auto trantor = std::make_unique<PlanetAdaptor>(*connection, ObjectPath{"/org/sdbuscpp/examplemanager/Planet1/Trantor"}, "Trantor", 40'000'000'000);
auto trantor = std::make_unique<PlanetAdaptor>(*connection, sdbus::ObjectPath{"/org/sdbuscpp/examplemanager/Planet1/Trantor"}, "Trantor", 40'000'000'000);
printCountDown("Creating PlanetAdaptor in ", 5);
auto laconia = std::make_unique<PlanetAdaptor>(*connection, ObjectPath{"/org/sdbuscpp/examplemanager/Planet1/Laconia"}, "Laconia", 231'721);
auto laconia = std::make_unique<PlanetAdaptor>(*connection, sdbus::ObjectPath{"/org/sdbuscpp/examplemanager/Planet1/Laconia"}, "Laconia", 231'721);
printCountDown("Removing PlanetAdaptor in ", 5);
earth.reset();
printCountDown("Removing PlanetAdaptor in ", 5);
Expand Down
Loading