From d1610ad0d6f1b6751964af41a0cc1599e2d7a955 Mon Sep 17 00:00:00 2001 From: Lutz Bichler Date: Tue, 27 Oct 2020 10:00:57 +0100 Subject: [PATCH] capicxx-dbus-runtime 3.2.0 --- CHANGES | 25 +- CMakeLists.txt | 20 +- README.md | 6 +- include/CommonAPI/DBus/CommonAPIDBus.hpp | 7 +- include/CommonAPI/DBus/DBusAddress.hpp | 4 +- .../CommonAPI/DBus/DBusAddressTranslator.hpp | 2 +- include/CommonAPI/DBus/DBusAttribute.hpp | 2 +- include/CommonAPI/DBus/DBusClientId.hpp | 6 +- include/CommonAPI/DBus/DBusConfig.hpp | 2 +- include/CommonAPI/DBus/DBusConnection.hpp | 4 +- include/CommonAPI/DBus/DBusDaemonProxy.hpp | 8 +- include/CommonAPI/DBus/DBusDeployment.hpp | 2 +- include/CommonAPI/DBus/DBusError.hpp | 2 +- include/CommonAPI/DBus/DBusErrorEvent.hpp | 12 +- include/CommonAPI/DBus/DBusEvent.hpp | 6 +- include/CommonAPI/DBus/DBusFactory.hpp | 2 +- .../DBus/DBusFreedesktopAttribute.hpp | 2 +- .../DBus/DBusFreedesktopPropertiesStub.hpp | 2 +- .../DBus/DBusFreedesktopStubAdapterHelper.hpp | 38 +-- .../CommonAPI/DBus/DBusFreedesktopVariant.hpp | 2 +- include/CommonAPI/DBus/DBusFunctionalHash.hpp | 2 +- include/CommonAPI/DBus/DBusHelper.hpp | 12 +- include/CommonAPI/DBus/DBusInputStream.hpp | 68 ++-- ...InstanceAvailabilityStatusChangedEvent.hpp | 2 +- .../CommonAPI/DBus/DBusInterfaceHandler.hpp | 2 +- include/CommonAPI/DBus/DBusMainLoop.hpp | 29 +- .../CommonAPI/DBus/DBusMainLoopContext.hpp | 41 +-- include/CommonAPI/DBus/DBusMessage.hpp | 2 +- include/CommonAPI/DBus/DBusMultiEvent.hpp | 2 +- include/CommonAPI/DBus/DBusObjectManager.hpp | 2 +- .../CommonAPI/DBus/DBusObjectManagerStub.hpp | 2 +- include/CommonAPI/DBus/DBusOutputStream.hpp | 68 ++-- include/CommonAPI/DBus/DBusProxy.hpp | 3 +- .../DBus/DBusProxyAsyncCallbackHandler.hpp | 16 +- ...sProxyAsyncSignalMemberCallbackHandler.hpp | 2 +- include/CommonAPI/DBus/DBusProxyBase.hpp | 2 +- .../CommonAPI/DBus/DBusProxyConnection.hpp | 2 +- include/CommonAPI/DBus/DBusProxyHelper.hpp | 74 ++++- include/CommonAPI/DBus/DBusProxyManager.hpp | 2 +- include/CommonAPI/DBus/DBusSelectiveEvent.hpp | 2 +- .../DBus/DBusSerializableArguments.hpp | 2 +- .../CommonAPI/DBus/DBusServiceRegistry.hpp | 8 +- include/CommonAPI/DBus/DBusStubAdapter.hpp | 2 +- .../CommonAPI/DBus/DBusStubAdapterHelper.hpp | 293 +++++++++++------- include/CommonAPI/DBus/DBusTypes.hpp | 2 +- include/CommonAPI/DBus/DBusUtils.hpp | 2 +- include/pugixml/pugixml.hpp | 105 ++++--- src/CommonAPI/DBus/DBusAddress.cpp | 12 +- src/CommonAPI/DBus/DBusAddressTranslator.cpp | 2 +- src/CommonAPI/DBus/DBusClientId.cpp | 10 +- src/CommonAPI/DBus/DBusConnection.cpp | 29 +- src/CommonAPI/DBus/DBusDaemonProxy.cpp | 14 +- src/CommonAPI/DBus/DBusError.cpp | 2 +- src/CommonAPI/DBus/DBusFactory.cpp | 2 +- .../DBus/DBusFreedesktopPropertiesStub.cpp | 2 +- src/CommonAPI/DBus/DBusFunctionalHash.cpp | 2 +- src/CommonAPI/DBus/DBusInputStream.cpp | 2 +- ...InstanceAvailabilityStatusChangedEvent.cpp | 4 +- src/CommonAPI/DBus/DBusMainLoop.cpp | 140 +++------ src/CommonAPI/DBus/DBusMainLoopContext.cpp | 91 +----- src/CommonAPI/DBus/DBusMessage.cpp | 2 +- src/CommonAPI/DBus/DBusObjectManager.cpp | 2 +- src/CommonAPI/DBus/DBusObjectManagerStub.cpp | 2 +- src/CommonAPI/DBus/DBusOutputStream.cpp | 8 +- src/CommonAPI/DBus/DBusProxy.cpp | 4 +- src/CommonAPI/DBus/DBusProxyBase.cpp | 2 +- src/CommonAPI/DBus/DBusProxyManager.cpp | 2 +- src/CommonAPI/DBus/DBusServiceRegistry.cpp | 7 +- src/CommonAPI/DBus/DBusStubAdapter.cpp | 2 +- src/murmurhash/MurmurHash3.cpp | 35 ++- src/pugixml/pugixml.cpp | 8 +- src/test/CMakeLists.txt | 47 --- src/test/DBusClientIdTest.cpp | 7 +- 73 files changed, 662 insertions(+), 681 deletions(-) diff --git a/CHANGES b/CHANGES index db275b0..b31e6b5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,29 +1,8 @@ Changes ======= -v3.1.12.11 -- Prevent crash when deregistering managed service (via 'deregisterManagedStub*') and - another service (via 'unregisterService') in parallel with same DBus connection -v3.1.12.10 -- Unregister mappings in DBusAddressTranslator (to free memory again) when - services/stubs are unregistered - -v3.1.12.9 -- Unregister mappings in DBusAddressTranslator (to free memory again) when - proxies are destroyed - -v3.1.12.8 -- Fixed crash in DBusConnectionTest - -v3.1.12.7 -- Adapted 'capi-dbus-add-support-for-custom-marshalling.patch' to be compatible with dbus version 1.12.x - -v3.1.12.6 -- Removed concurrent timeout handling - -v3.1.12.5 -- Ensure availability listeners are unregistered properly (to free memory) when - proxies are being destroyed in callback invoking the availability listener(s) +v3.2.0 +- adapt to CommonAPI v3.2.0 v3.1.12.4 - support 'lock functors' in AttributeDispatcher(s) diff --git a/CMakeLists.txt b/CMakeLists.txt index e98d655..1c444be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,8 @@ PROJECT(libcommonapi-dbus) # version of CommonAPI-DBus SET( LIBCOMMONAPI_DBUS_MAJOR_VERSION 3 ) -SET( LIBCOMMONAPI_DBUS_MINOR_VERSION 1 ) -SET( LIBCOMMONAPI_DBUS_PATCH_VERSION 12 ) +SET( LIBCOMMONAPI_DBUS_MINOR_VERSION 2 ) +SET( LIBCOMMONAPI_DBUS_PATCH_VERSION 0 ) message(STATUS "Project name: ${PROJECT_NAME}") @@ -59,10 +59,14 @@ message(STATUS "DBUS_DAEMON_PROXY_DEFAULT_SEND_TIMEOUT is set to value: ${DBUS_D SET(RPM_PACKAGE_VERSION "r0" CACHE STRING "rpm packet version") # used in e.g. commonapi-dbus.spec.in +# Set a default build type if none was specified +set(default_build_type "RelWithDebInfo") if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING - "Choose the type of build, options are: Debug Release." FORCE) -endif(NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() set(CMAKE_BUILD_TYPE_FOR_SPEC_IN "") # used in *.cmake.in string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_FOR_SPEC_IN) @@ -123,9 +127,9 @@ message(STATUS "CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}") FIND_PACKAGE(PkgConfig) FIND_PACKAGE(Threads REQUIRED) if ("${USE_INSTALLED_COMMONAPI}" STREQUAL "ON") - FIND_PACKAGE(CommonAPI 3.1.12 REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) + FIND_PACKAGE(CommonAPI 3.2.0 REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) else() - FIND_PACKAGE(CommonAPI 3.1.12 REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + FIND_PACKAGE(CommonAPI 3.2.0 REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) endif() message(STATUS "CommonAPI_CONSIDERED_CONFIGS: ${CommonAPI_CONSIDERED_CONFIGS}") @@ -164,7 +168,7 @@ if (MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS -DCOMMONAPI_INTERNAL_COMPILATION -DCOMMONAPI_DLL_COMPILATION /EHsc /wd4503") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -DCOMMONAPI_INTERNAL_COMPILATION -DCOMMONAPI_DLL_COMPILATION /wd4503") else() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector -fasynchronous-unwind-tables -fno-omit-frame-pointer -DCOMMONAPI_INTERNAL_COMPILATION -D_GLIBCXX_USE_NANOSLEEP") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector -fasynchronous-unwind-tables -fno-omit-frame-pointer -DCOMMONAPI_INTERNAL_COMPILATION -D_GLIBCXX_USE_NANOSLEEP -fvisibility=hidden") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCOMMONAPI_LOGLEVEL=COMMONAPI_LOGLEVEL_${MAX_LOG_LEVEL}") diff --git a/README.md b/README.md index f3b577e..4eea348 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ### CommonAPI C++ D-Bus Runtime ##### Copyright -Copyright (C) 2016-2017, Bayerische Motoren Werke Aktiengesellschaft (BMW AG). -Copyright (C) 2016-2017, GENIVI Alliance, Inc. +Copyright (C) 2016-2020, Bayerische Motoren Werke Aktiengesellschaft (BMW AG). +Copyright (C) 2016-2020, GENIVI Alliance, Inc. This file is part of GENIVI Project IPC Common API C++. Contributions are licensed to the GENIVI Alliance under one or more Contribution License Agreements or MPL 2.0. @@ -59,4 +59,4 @@ $ make install You can change the installation directory by the CMake variable _CMAKE_INSTALL_PREFIX_ or you can let it uninstalled (skip the _make install_ command). If you want to use the uninstalled version of CommonAPI set the CMake variable _USE_INSTALLED_COMMONAPI_ to _OFF_. -For further build instructions (build for windows, build documentation, tests etc.) please refer to the CommonAPI D-Bus tutorial. \ No newline at end of file +For further build instructions (build for windows, build documentation, tests etc.) please refer to the CommonAPI D-Bus tutorial. diff --git a/include/CommonAPI/DBus/CommonAPIDBus.hpp b/include/CommonAPI/DBus/CommonAPIDBus.hpp index 3df526d..e4c2366 100644 --- a/include/CommonAPI/DBus/CommonAPIDBus.hpp +++ b/include/CommonAPI/DBus/CommonAPIDBus.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -8,11 +8,14 @@ #ifndef COMMONAPI_INTERNAL_COMPILATION #define COMMONAPI_INTERNAL_COMPILATION +#define HAS_DEFINED_COMMONAPI_INTERNAL_COMPILATION_HERE #endif #include "DBusAddressTranslator.hpp" +#ifdef HAS_DEFINED_COMMONAPI_INTERNAL_COMPILATION_HERE #undef COMMONAPI_INTERNAL_COMPILATION +#undef HAS_DEFINED_COMMONAPI_INTERNAL_COMPILATION_HERE +#endif #endif // COMMONAPI_DBUS_HPP_ - diff --git a/include/CommonAPI/DBus/DBusAddress.hpp b/include/CommonAPI/DBus/DBusAddress.hpp index 171a482..81b0fea 100644 --- a/include/CommonAPI/DBus/DBusAddress.hpp +++ b/include/CommonAPI/DBus/DBusAddress.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -26,6 +26,8 @@ class DBusAddress { COMMONAPI_EXPORT DBusAddress(const DBusAddress &_source); COMMONAPI_EXPORT virtual ~DBusAddress(); + COMMONAPI_EXPORT DBusAddress &operator=(const DBusAddress &_other); + COMMONAPI_EXPORT bool operator==(const DBusAddress &_other) const; COMMONAPI_EXPORT bool operator!=(const DBusAddress &_other) const; COMMONAPI_EXPORT bool operator<(const DBusAddress &_other) const; diff --git a/include/CommonAPI/DBus/DBusAddressTranslator.hpp b/include/CommonAPI/DBus/DBusAddressTranslator.hpp index bad7b19..28e9c34 100644 --- a/include/CommonAPI/DBus/DBusAddressTranslator.hpp +++ b/include/CommonAPI/DBus/DBusAddressTranslator.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusAttribute.hpp b/include/CommonAPI/DBus/DBusAttribute.hpp index 5db6b49..344cdca 100644 --- a/include/CommonAPI/DBus/DBusAttribute.hpp +++ b/include/CommonAPI/DBus/DBusAttribute.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusClientId.hpp b/include/CommonAPI/DBus/DBusClientId.hpp index f5f5e85..2f3bbd0 100644 --- a/include/CommonAPI/DBus/DBusClientId.hpp +++ b/include/CommonAPI/DBus/DBusClientId.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -38,6 +38,10 @@ class COMMONAPI_EXPORT_CLASS_EXPLICIT DBusClientId COMMONAPI_EXPORT const char * getDBusId(); COMMONAPI_EXPORT DBusMessage createMessage(const std::string objectPath, const std::string interfaceName, const std::string signalName) const; + + COMMONAPI_EXPORT uid_t getUid() const; + COMMONAPI_EXPORT gid_t getGid() const; + protected: std::string dbusId_; }; diff --git a/include/CommonAPI/DBus/DBusConfig.hpp b/include/CommonAPI/DBus/DBusConfig.hpp index 3043c8e..2375c0c 100644 --- a/include/CommonAPI/DBus/DBusConfig.hpp +++ b/include/CommonAPI/DBus/DBusConfig.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusConnection.hpp b/include/CommonAPI/DBus/DBusConnection.hpp index ef4e0dc..310d180 100644 --- a/include/CommonAPI/DBus/DBusConnection.hpp +++ b/include/CommonAPI/DBus/DBusConnection.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -217,8 +217,6 @@ class DBusConnection template COMMONAPI_EXPORT void proxyPushFunctionToMainLoop(Function&& _function, Arguments&& ... _args); - COMMONAPI_EXPORT void setPendingCallTimedOut(DBusPendingCall* _pendingCall, ::DBusTimeout* _timeout) const; - #ifdef COMMONAPI_DBUS_TEST inline std::weak_ptr getLoop() { return loop_; } #endif diff --git a/include/CommonAPI/DBus/DBusDaemonProxy.hpp b/include/CommonAPI/DBus/DBusDaemonProxy.hpp index 22d461f..04ae1e2 100644 --- a/include/CommonAPI/DBus/DBusDaemonProxy.hpp +++ b/include/CommonAPI/DBus/DBusDaemonProxy.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -55,7 +55,7 @@ class DBusDaemonProxy : public DBusProxyBase, typedef std::function GetNameOwnerAsyncCallback; COMMONAPI_EXPORT DBusDaemonProxy(const std::shared_ptr& dbusConnection); - COMMONAPI_EXPORT virtual ~DBusDaemonProxy() {} + COMMONAPI_EXPORT virtual ~DBusDaemonProxy(); COMMONAPI_EXPORT virtual bool isAvailable() const; COMMONAPI_EXPORT virtual bool isAvailableBlocking() const; @@ -112,7 +112,7 @@ class DBusDaemonProxy : public DBusProxyBase, const bool success = DBusSerializableArguments::serialize(outputStream, busName); if (!success) { std::promise promise; - promise.set_value(CallStatus::OUT_OF_MEMORY); + promise.set_value(CallStatus::SERIALIZATION_ERROR); return promise.get_future(); } outputStream.flush(); @@ -170,7 +170,7 @@ class DBusDaemonProxy : public DBusProxyBase, const bool success = DBusSerializableArguments::serialize(outputStream, busName); if (!success) { std::promise promise; - promise.set_value(CallStatus::OUT_OF_MEMORY); + promise.set_value(CallStatus::SERIALIZATION_ERROR); return promise.get_future(); } outputStream.flush(); diff --git a/include/CommonAPI/DBus/DBusDeployment.hpp b/include/CommonAPI/DBus/DBusDeployment.hpp index 9eec01f..566f7ea 100644 --- a/include/CommonAPI/DBus/DBusDeployment.hpp +++ b/include/CommonAPI/DBus/DBusDeployment.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusError.hpp b/include/CommonAPI/DBus/DBusError.hpp index 25d7864..977ec79 100644 --- a/include/CommonAPI/DBus/DBusError.hpp +++ b/include/CommonAPI/DBus/DBusError.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusErrorEvent.hpp b/include/CommonAPI/DBus/DBusErrorEvent.hpp index 966f9e1..0ab53aa 100644 --- a/include/CommonAPI/DBus/DBusErrorEvent.hpp +++ b/include/CommonAPI/DBus/DBusErrorEvent.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -73,19 +73,21 @@ class DBusErrorEvent< private: - template + template inline void initialize(index_sequence, const std::tuple &_in) { in_ = std::make_tuple(std::get(_in)...); } - template + template void deserialize(const DBusMessage &_reply, index_sequence) { if (sizeof...(InArgs_) > 0) { DBusInputStream dbusInputStream(_reply); const bool success = DBusSerializableArguments...>::deserialize(dbusInputStream, std::get(in_)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusErrorEvent::", __func__, "(", errorName_, "): deserialization failed!"); return; + } this->notifyListeners(errorName_, std::move(std::get(in_).getValue())...); } } @@ -96,7 +98,7 @@ class DBusErrorEvent< class DBusErrorEventHelper { public: - template + template static void notifyListeners(const DBusMessage &_reply, const std::string &_errorName, index_sequence, diff --git a/include/CommonAPI/DBus/DBusEvent.hpp b/include/CommonAPI/DBus/DBusEvent.hpp index c954a88..05046cd 100644 --- a/include/CommonAPI/DBus/DBusEvent.hpp +++ b/include/CommonAPI/DBus/DBusEvent.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -155,7 +155,7 @@ class DBusEvent: public Event_ { std::get<3>(subscription_) = ""; } - template + template inline void handleSignalDBusMessage(const DBusMessage &_message, index_sequence) { DBusInputStream input(_message); if (DBusSerializableArguments< @@ -165,7 +165,7 @@ class DBusEvent: public Event_ { } } - template + template inline void handleSignalDBusMessage(const uint32_t tag, const DBusMessage &_message, index_sequence) { DBusInputStream input(_message); if (DBusSerializableArguments< diff --git a/include/CommonAPI/DBus/DBusFactory.hpp b/include/CommonAPI/DBus/DBusFactory.hpp index 9654a94..e54bbe6 100644 --- a/include/CommonAPI/DBus/DBusFactory.hpp +++ b/include/CommonAPI/DBus/DBusFactory.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp b/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp index 28b41da..6d26505 100644 --- a/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp +++ b/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp b/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp index 0a0914d..ac4270a 100644 --- a/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp +++ b/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp b/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp index 56f2f17..a183446 100644 --- a/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp +++ b/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -44,8 +44,8 @@ class DBusGetFreedesktopAttributeStubDispatcher typedef typename DBusGetAttributeStubDispatcher::LockStubFunctor LockStubFunctor; typedef typename DBusGetAttributeStubDispatcher::GetStubFunctor GetStubFunctor; - DBusGetFreedesktopAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, AttributeDepl_ *_depl = nullptr) - : DBusGetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, "v", _depl) { + DBusGetFreedesktopAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, const bool _isImplemented, AttributeDepl_ *_depl = nullptr) + : DBusGetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, "v", _isImplemented, _depl) { } virtual ~DBusGetFreedesktopAttributeStubDispatcher() {}; @@ -93,15 +93,13 @@ class DBusSetFreedesktopAttributeStubDispatcher typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr, AttributeType_); typedef void (RemoteEventHandlerType::*OnRemoteChangedFunctor)(); - DBusSetFreedesktopAttributeStubDispatcher( - LockStubFunctor _lockStubFunctor, - GetStubFunctor _getStubFunctor, - OnRemoteSetFunctor _onRemoteSetFunctor, - OnRemoteChangedFunctor _onRemoteChangedFunctor, + DBusSetFreedesktopAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, + OnRemoteSetFunctor _onRemoteSetFunctor, OnRemoteChangedFunctor _onRemoteChangedFunctor, + const bool _isImplemented, AttributeDepl_ * _depl = nullptr) - : DBusGetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, "v", _depl), - DBusGetFreedesktopAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _depl), - DBusSetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl) { + : DBusGetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, "v", _isImplemented, _depl), + DBusGetFreedesktopAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _isImplemented, _depl), + DBusSetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _isImplemented, _depl) { } virtual ~DBusSetFreedesktopAttributeStubDispatcher() {}; @@ -133,18 +131,16 @@ class DBusSetFreedesktopObservableAttributeStubDispatcher typedef typename StubClass_::StubAdapterType StubAdapterType; typedef void (StubAdapterType::*FireChangedFunctor)(const AttributeType_&); - DBusSetFreedesktopObservableAttributeStubDispatcher( - LockStubFunctor _lockStubFunctor, - GetStubFunctor _getStubFunctor, - OnRemoteSetFunctor _onRemoteSetFunctor, - OnRemoteChangedFunctor _onRemoteChangedFunctor, + DBusSetFreedesktopObservableAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, + OnRemoteSetFunctor _onRemoteSetFunctor, OnRemoteChangedFunctor _onRemoteChangedFunctor, FireChangedFunctor _fireChangedFunctor, + const bool _isImplemented, AttributeDepl_ *_depl = nullptr) - : DBusGetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, "v", _depl), - DBusGetFreedesktopAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _depl), - DBusSetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl), - DBusSetFreedesktopAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _depl), - DBusSetObservableAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _fireChangedFunctor, "v", _depl) { + : DBusGetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, "v", _isImplemented, _depl), + DBusGetFreedesktopAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _isImplemented, _depl), + DBusSetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _isImplemented, _depl), + DBusSetFreedesktopAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _isImplemented, _depl), + DBusSetObservableAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _fireChangedFunctor, "v", _isImplemented, _depl) { } }; diff --git a/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp b/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp index bd1fb58..530c434 100644 --- a/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp +++ b/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusFunctionalHash.hpp b/include/CommonAPI/DBus/DBusFunctionalHash.hpp index fbc1ea3..f83345d 100644 --- a/include/CommonAPI/DBus/DBusFunctionalHash.hpp +++ b/include/CommonAPI/DBus/DBusFunctionalHash.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusHelper.hpp b/include/CommonAPI/DBus/DBusHelper.hpp index ebde2b8..7aa07d9 100644 --- a/include/CommonAPI/DBus/DBusHelper.hpp +++ b/include/CommonAPI/DBus/DBusHelper.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -16,23 +16,23 @@ namespace CommonAPI { namespace DBus { -template +template struct index_sequence {}; -template +template struct make_sequence : make_sequence {}; -template +template struct make_sequence<0, S_...> { typedef index_sequence type; }; -template +template struct make_sequence_range : make_sequence_range {}; -template +template struct make_sequence_range<0, Offset_, S_...> { typedef index_sequence type; }; diff --git a/include/CommonAPI/DBus/DBusInputStream.hpp b/include/CommonAPI/DBus/DBusInputStream.hpp index 568dc4d..a4f3609 100644 --- a/include/CommonAPI/DBus/DBusInputStream.hpp +++ b/include/CommonAPI/DBus/DBusInputStream.hpp @@ -107,6 +107,19 @@ class DBusInputStream return (*this); } + template + COMMONAPI_EXPORT InputStream &readValue(RangedInteger &_value, const EmptyDeployment *) { + int tmpValue; + readValue(tmpValue, static_cast(nullptr)); + if(!_value.validate()) { + setError(); + } + if (!hasError()) { + _value = tmpValue; + } + return (*this); + } + template COMMONAPI_EXPORT InputStream &readValue(Enumeration &_value, const Deployment_ *_depl) { Base_ tmpValue; @@ -479,40 +492,51 @@ class DBusInputStream _readRaw(length + 1); } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr) { + template::value && + !is_std_vector::value && + !is_std_unordered_map::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { if (4 < sizeof(Type_)) align(8); } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if, Type_>::value>::type * = nullptr) { + template::value && + std::is_class::value && + !is_std_vector::value && + !is_std_unordered_map::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(8); } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr) { + template::value || + is_std_vector::value || + std::is_base_of, Type_>::value || + std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { // Intentionally do nothing } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr) { - // Intentionally do nothing - } - - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr) { + template::value || + std::is_base_of, Type_>::value || + std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(4); } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if, Type_>::value>::type * = nullptr) { - align(4); + template, Type_>::value || + std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { + align(2); } char *begin_; diff --git a/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp b/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp index 91fa410..a65172f 100644 --- a/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp +++ b/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusInterfaceHandler.hpp b/include/CommonAPI/DBus/DBusInterfaceHandler.hpp index 9804aff..8b331b4 100644 --- a/include/CommonAPI/DBus/DBusInterfaceHandler.hpp +++ b/include/CommonAPI/DBus/DBusInterfaceHandler.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusMainLoop.hpp b/include/CommonAPI/DBus/DBusMainLoop.hpp index 2ca7202..0fd5851 100755 --- a/include/CommonAPI/DBus/DBusMainLoop.hpp +++ b/include/CommonAPI/DBus/DBusMainLoop.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -98,16 +98,13 @@ class DBusMainLoop { struct DispatchSourceToDispatchStruct { DispatchSource* dispatchSource_; - std::mutex* mutex_; - bool isExecuted_; /* execution flag: indicates, whether the dispatchSource is dispatched currently */ - bool deleteObject_; /* delete flag: indicates, whether the dispatchSource can be deleted*/ + std::atomic isExecuted_; /* execution flag: indicates, whether the dispatchSource is dispatched currently */ + std::atomic deleteObject_; /* delete flag: indicates, whether the dispatchSource can be deleted*/ DispatchSourceToDispatchStruct(DispatchSource* _dispatchSource, - std::mutex* _mutex, bool _isExecuted, bool _deleteObject) { dispatchSource_ = _dispatchSource; - mutex_ = _mutex; isExecuted_ = _isExecuted; deleteObject_ = _deleteObject; } @@ -115,18 +112,15 @@ class DBusMainLoop { struct TimeoutToDispatchStruct { Timeout* timeout_; - std::mutex* mutex_; - bool isExecuted_; /* execution flag: indicates, whether the timeout is dispatched currently */ - bool deleteObject_; /* delete flag: indicates, whether the timeout can be deleted*/ - bool timeoutElapsed_; /* timeout elapsed flag: indicates, whether the timeout is elapsed*/ + std::atomic isExecuted_; /* execution flag: indicates, whether the timeout is dispatched currently */ + std::atomic deleteObject_; /* delete flag: indicates, whether the timeout can be deleted*/ + std::atomic timeoutElapsed_; /* timeout elapsed flag: indicates, whether the timeout is elapsed*/ TimeoutToDispatchStruct(Timeout* _timeout, - std::mutex* _mutex, bool _isExecuted, bool _deleteObject, bool _timeoutElapsed) { timeout_ = _timeout; - mutex_ = _mutex; isExecuted_ = _isExecuted; deleteObject_ = _deleteObject; timeoutElapsed_ = _timeoutElapsed; @@ -136,18 +130,15 @@ class DBusMainLoop { struct WatchToDispatchStruct { int fd_; Watch* watch_; - std::mutex* mutex_; - bool isExecuted_; /* execution flag: indicates, whether the watch is dispatched currently */ - bool deleteObject_; /* delete flag: indicates, whether the watch can be deleted*/ + std::atomic isExecuted_; /* execution flag: indicates, whether the watch is dispatched currently */ + std::atomic deleteObject_; /* delete flag: indicates, whether the watch can be deleted*/ WatchToDispatchStruct(int _fd, Watch* _watch, - std::mutex* _mutex, bool _isExecuted, bool _deleteObject) { fd_ = _fd; watch_ = _watch; - mutex_ = _mutex; isExecuted_ = _isExecuted; deleteObject_ = _deleteObject; } @@ -157,7 +148,7 @@ class DBusMainLoop { std::multimap registeredWatches_; std::multimap registeredTimeouts_; - std::mutex dispatchSourcesMutex_; + std::recursive_mutex dispatchSourcesMutex_; std::mutex watchesMutex_; std::mutex timeoutsMutex_; @@ -179,7 +170,7 @@ class DBusMainLoop { #endif std::atomic hasToStop_; - bool isBroken_; + std::atomic isBroken_; }; } // namespace DBus diff --git a/include/CommonAPI/DBus/DBusMainLoopContext.hpp b/include/CommonAPI/DBus/DBusMainLoopContext.hpp index ecb49ee..c74dc91 100644 --- a/include/CommonAPI/DBus/DBusMainLoopContext.hpp +++ b/include/CommonAPI/DBus/DBusMainLoopContext.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -28,7 +28,7 @@ class DBusConnection; class DBusDispatchSource: public DispatchSource { public: - DBusDispatchSource(DBusConnection* dbusConnection); + DBusDispatchSource(std::weak_ptr dbusConnection); ~DBusDispatchSource(); bool prepare(int64_t& timeout); @@ -36,7 +36,7 @@ class DBusDispatchSource: public DispatchSource { bool dispatch(); private: - DBusConnection* dbusConnection_; + std::weak_ptr dbusConnection_; }; class DBusQueueWatch; @@ -146,41 +146,6 @@ class DBusQueueWatch : public Watch { }; - -class DBusTimeout: public Timeout { - public: - DBusTimeout(::DBusTimeout* libdbusTimeout, - std::weak_ptr& mainLoopContext, - std::weak_ptr& dbusConnection); - - bool isReadyToBeMonitored(); - void startMonitoring(); - void stopMonitoring(); - - bool dispatch(); - - int64_t getTimeoutInterval() const; - int64_t getReadyTime() const; - - void setPendingCall(DBusPendingCall* _pendingCall); - -#ifdef _WIN32 - __declspec(thread) static DBusTimeout *currentTimeout_; -#else - thread_local static DBusTimeout *currentTimeout_; -#endif - - private: - void recalculateDueTime(); - - std::atomic dueTimeInMs_; - ::DBusTimeout* libdbusTimeout_; - std::weak_ptr mainLoopContext_; - std::weak_ptr dbusConnection_; - DBusPendingCall *pendingCall_; -}; - - } // namespace DBus } // namespace CommonAPI diff --git a/include/CommonAPI/DBus/DBusMessage.hpp b/include/CommonAPI/DBus/DBusMessage.hpp index b30749e..3fdf5f4 100644 --- a/include/CommonAPI/DBus/DBusMessage.hpp +++ b/include/CommonAPI/DBus/DBusMessage.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusMultiEvent.hpp b/include/CommonAPI/DBus/DBusMultiEvent.hpp index cf18a48..cd9be83 100644 --- a/include/CommonAPI/DBus/DBusMultiEvent.hpp +++ b/include/CommonAPI/DBus/DBusMultiEvent.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusObjectManager.hpp b/include/CommonAPI/DBus/DBusObjectManager.hpp index 432e733..94d2dcd 100644 --- a/include/CommonAPI/DBus/DBusObjectManager.hpp +++ b/include/CommonAPI/DBus/DBusObjectManager.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusObjectManagerStub.hpp b/include/CommonAPI/DBus/DBusObjectManagerStub.hpp index d8de02d..c27333d 100644 --- a/include/CommonAPI/DBus/DBusObjectManagerStub.hpp +++ b/include/CommonAPI/DBus/DBusObjectManagerStub.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusOutputStream.hpp b/include/CommonAPI/DBus/DBusOutputStream.hpp index 8719146..a337845 100644 --- a/include/CommonAPI/DBus/DBusOutputStream.hpp +++ b/include/CommonAPI/DBus/DBusOutputStream.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -138,6 +138,15 @@ class DBusOutputStream: public OutputStream { return (*this); } + template + COMMONAPI_EXPORT OutputStream &writeValue(const RangedInteger &_value, const EmptyDeployment *) { + if (_value.validate()) + writeValue(_value.value_, static_cast(nullptr)); + else + setError(); + return (*this); + } + template COMMONAPI_EXPORT OutputStream &writeValue(const Enumeration &_value, const Deployment_ *_depl = nullptr) { return writeValue(static_cast(_value), _depl); @@ -359,40 +368,51 @@ class DBusOutputStream: public OutputStream { COMMONAPI_EXPORT void pushPosition(); COMMONAPI_EXPORT size_t popPosition(); - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr) { + template::value && + !is_std_vector::value && + !is_std_unordered_map::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { if (4 < sizeof(Type_)) align(8); } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if::value>::type * = nullptr, - typename std::enable_if, Type_>::value>::type * = nullptr) { + template::value && + std::is_class::value && + !is_std_vector::value && + !is_std_unordered_map::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value && + !std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(8); } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr) { + template::value || + is_std_vector::value || + std::is_base_of, Type_>::value || + std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { // Intentionally do nothing } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr) { - // Intentionally do nothing - } - - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if::value>::type * = nullptr) { + template::value || + std::is_base_of, Type_>::value || + std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(4); } - template - COMMONAPI_EXPORT void alignVector(typename std::enable_if, Type_>::value>::type * = nullptr) { - align(4); + template, Type_>::value || + std::is_base_of, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { + align(2); } COMMONAPI_EXPORT void setError(); @@ -459,7 +479,7 @@ class DBusOutputStream: public OutputStream { COMMONAPI_EXPORT size_t getCurrentStreamPosition(); - DBusError dbusError_; + bool errorOccurred_; DBusMessage dbusMessage_; std::vector positions_; diff --git a/include/CommonAPI/DBus/DBusProxy.hpp b/include/CommonAPI/DBus/DBusProxy.hpp index 9a85a8d..19edf21 100644 --- a/include/CommonAPI/DBus/DBusProxy.hpp +++ b/include/CommonAPI/DBus/DBusProxy.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -181,4 +181,3 @@ class COMMONAPI_EXPORT_CLASS_EXPLICIT DBusProxy } // namespace CommonAPI #endif // COMMONAPI_DBUS_DBUSPROXY_HPP_ - diff --git a/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp b/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp index 25b2ecd..f1c8ac7 100644 --- a/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp +++ b/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -119,7 +119,7 @@ class DBusProxyAsyncCallbackHandler : std::tuple args_; private: - template + template inline CallStatus handleDBusMessageReply( const CallStatus _dbusMessageCallStatus, const DBusMessage& _dbusMessage, @@ -132,10 +132,9 @@ class DBusProxyAsyncCallbackHandler : if (_dbusMessageCallStatus == CallStatus::SUCCESS) { DBusInputStream dbusInputStream(_dbusMessage); - if(DBusSerializableArguments::deserialize(dbusInputStream, + if(!DBusSerializableArguments::deserialize(dbusInputStream, std::get(_argTuple)...)) { - } else { - callStatus = CallStatus::REMOTE_ERROR; + callStatus = CallStatus::SERIALIZATION_ERROR; } } @@ -195,7 +194,7 @@ class DBusProxyAsyncCallbackHandler< private: - template + template inline CallStatus handleDBusMessageReply( const CallStatus _dbusMessageCallStatus, const DBusMessage& _dbusMessage, @@ -208,10 +207,9 @@ class DBusProxyAsyncCallbackHandler< if (_dbusMessageCallStatus == CallStatus::SUCCESS) { DBusInputStream dbusInputStream(_dbusMessage); - if(DBusSerializableArguments::deserialize(dbusInputStream, + if (!DBusSerializableArguments::deserialize(dbusInputStream, std::get(_argTuple)...)) { - } else { - callStatus = CallStatus::REMOTE_ERROR; + callStatus = CallStatus::SERIALIZATION_ERROR; } } else { if(_dbusMessage.isErrorType()) { diff --git a/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp b/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp index a768e45..cd89207 100644 --- a/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp +++ b/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusProxyBase.hpp b/include/CommonAPI/DBus/DBusProxyBase.hpp index fd9c33d..4c1dade 100644 --- a/include/CommonAPI/DBus/DBusProxyBase.hpp +++ b/include/CommonAPI/DBus/DBusProxyBase.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusProxyConnection.hpp b/include/CommonAPI/DBus/DBusProxyConnection.hpp index 4d9f3e0..177bbe8 100644 --- a/include/CommonAPI/DBus/DBusProxyConnection.hpp +++ b/include/CommonAPI/DBus/DBusProxyConnection.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusProxyHelper.hpp b/include/CommonAPI/DBus/DBusProxyHelper.hpp index 2337fab..1202f4e 100644 --- a/include/CommonAPI/DBus/DBusProxyHelper.hpp +++ b/include/CommonAPI/DBus/DBusProxyHelper.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -62,7 +64,13 @@ struct DBusProxyHelper, if (sizeof...(InArgs_) > 0) { DBusOutputStream output(message); if (!DBusSerializableArguments::serialize(output, _in...)) { - _status = CallStatus::OUT_OF_MEMORY; + COMMONAPI_ERROR("MethodSync(dbus): serialization failed: [", + message.getObjectPath(), " ", + message.getInterface(), " ", + message.getMember(), " ", + message.getSerial(), "]"); + + _status = CallStatus::SERIALIZATION_ERROR; return; } output.flush(); @@ -87,7 +95,13 @@ struct DBusProxyHelper, if (sizeof...(InArgs_) > 0) { DBusOutputStream output(_message); if (!DBusSerializableArguments::serialize(output, _in...)) { - _status = CallStatus::OUT_OF_MEMORY; + COMMONAPI_ERROR("MethodSync w/ reply (dbus): serialization failed: [", + _message.getObjectPath(), " ", + _message.getInterface(), " ", + _message.getMember(), " ", + _message.getSerial(), "]"); + + _status = CallStatus::SERIALIZATION_ERROR; return; } output.flush(); @@ -103,7 +117,13 @@ struct DBusProxyHelper, if (sizeof...(OutArgs_) > 0) { DBusInputStream input(reply); if (!DBusSerializableArguments::deserialize(input, _out...)) { - _status = CallStatus::REMOTE_ERROR; + COMMONAPI_ERROR("MethodSync w/ reply (dbus): reply deserialization failed: [", + reply.getObjectPath(), " ", + reply.getInterface(), " ", + reply.getMember(), " ", + reply.getSerial(), "]"); + + _status = CallStatus::SERIALIZATION_ERROR; return; } } @@ -188,8 +208,14 @@ struct DBusProxyHelper, InArgs_... >::serialize(output, _in...); if (!success) { + COMMONAPI_ERROR("MethodAsync (dbus): serialization failed: [", + _message.getObjectPath(), " ", + _message.getInterface(), " ", + _message.getMember(), " ", + _message.getSerial(), "]"); + std::promise promise; - promise.set_value(CallStatus::OUT_OF_MEMORY); + promise.set_value(CallStatus::SERIALIZATION_ERROR); return promise.get_future(); } output.flush(); @@ -206,7 +232,11 @@ struct DBusProxyHelper, try { callStatusFuture = dbusMessageReplyAsyncHandler->getFuture(); } catch (std::exception& e) { - COMMONAPI_ERROR("MethodAsync(dbus): messageReplyAsyncHandler future failed(", e.what(), ")"); + COMMONAPI_ERROR("MethodAsync(dbus): messageReplyAsyncHandler future failed(", + e.what(), ") [", _message.getObjectPath(), " ", + _message.getInterface(), " ", + _message.getMember(), " ", + _message.getSerial(), "]"); } if(_proxy.isAvailable()) { @@ -317,7 +347,7 @@ struct DBusProxyHelper, return callMethodAsync(_proxy, message, _info, _in..., _function, _out); } - template + template static void callCallbackOnNotAvailable(std::function _callback, index_sequence, std::tuple _out) { const CallStatus status(CallStatus::NOT_AVAILABLE); @@ -347,7 +377,13 @@ struct DBusProxyHelper, if (sizeof...(InArgs_) > 0) { DBusOutputStream output(_message); if (!DBusSerializableArguments::serialize(output, _in...)) { - _status = CallStatus::OUT_OF_MEMORY; + COMMONAPI_ERROR("MethodSync w/ reply and error events (dbus): serialization failed: [", + _message.getObjectPath(), " ", + _message.getInterface(), " ", + _message.getMember(), " ", + _message.getSerial(), "]"); + + _status = CallStatus::SERIALIZATION_ERROR; return; } output.flush(); @@ -367,7 +403,13 @@ struct DBusProxyHelper, if (sizeof...(OutArgs_) > 0) { DBusInputStream input(reply); if (!DBusSerializableArguments::deserialize(input, _out...)) { - _status = CallStatus::REMOTE_ERROR; + COMMONAPI_ERROR("MethodSync w/ reply and error events (dbus): reply deserialization failed: [", + reply.getObjectPath(), " ", + reply.getInterface(), " ", + reply.getMember(), " ", + reply.getSerial(), "]"); + + _status = CallStatus::SERIALIZATION_ERROR; return; } } @@ -413,8 +455,14 @@ struct DBusProxyHelper, InArgs_... >::serialize(output, _in...); if (!success) { + COMMONAPI_ERROR("MethodAsync w/ reply and error events (dbus): serialization failed: [", + _message.getObjectPath(), " ", + _message.getInterface(), " ", + _message.getMember(), " ", + _message.getSerial(), "]"); + std::promise promise; - promise.set_value(CallStatus::OUT_OF_MEMORY); + promise.set_value(CallStatus::SERIALIZATION_ERROR); return promise.get_future(); } output.flush(); @@ -431,7 +479,11 @@ struct DBusProxyHelper, try { callStatusFuture = dbusMessageReplyAsyncHandler->getFuture(); } catch (std::exception& e) { - COMMONAPI_ERROR("MethodAsync(dbus): messageReplyAsyncHandler future failed(", e.what(), ")"); + COMMONAPI_ERROR("MethodAsync(dbus): messageReplyAsyncHandler future failed(", + e.what(), ") [", _message.getObjectPath(), " ", + _message.getInterface(), " ", + _message.getMember(), " ", + _message.getSerial(), "]"); } if(_proxy.isAvailable()) { diff --git a/include/CommonAPI/DBus/DBusProxyManager.hpp b/include/CommonAPI/DBus/DBusProxyManager.hpp index f8829b4..a5ac79e 100644 --- a/include/CommonAPI/DBus/DBusProxyManager.hpp +++ b/include/CommonAPI/DBus/DBusProxyManager.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusSelectiveEvent.hpp b/include/CommonAPI/DBus/DBusSelectiveEvent.hpp index da140b0..b8be8a8 100644 --- a/include/CommonAPI/DBus/DBusSelectiveEvent.hpp +++ b/include/CommonAPI/DBus/DBusSelectiveEvent.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusSerializableArguments.hpp b/include/CommonAPI/DBus/DBusSerializableArguments.hpp index 771de26..c2adf89 100644 --- a/include/CommonAPI/DBus/DBusSerializableArguments.hpp +++ b/include/CommonAPI/DBus/DBusSerializableArguments.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusServiceRegistry.hpp b/include/CommonAPI/DBus/DBusServiceRegistry.hpp index 2edcd8f..d27b153 100644 --- a/include/CommonAPI/DBus/DBusServiceRegistry.hpp +++ b/include/CommonAPI/DBus/DBusServiceRegistry.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -46,7 +46,7 @@ class DBusAddress; class DBusAddressTranslator; class DBusDaemonProxy; -class DBusServiceRegistry: public std::enable_shared_from_this, +class COMMONAPI_EXPORT DBusServiceRegistry: public std::enable_shared_from_this, public DBusProxyConnection::DBusSignalHandler { public: enum class DBusRecordState { @@ -73,8 +73,8 @@ class DBusServiceRegistry: public std::enable_shared_from_this GetAvailableServiceInstancesCallback; - static std::shared_ptr get(std::shared_ptr _connection, bool _insert=true); - static void remove(std::shared_ptr _connection); + static std::shared_ptr get(const std::shared_ptr &_connection, bool _insert=true); + static void remove(const std::shared_ptr &_connection); DBusServiceRegistry(std::shared_ptr dbusProxyConnection); diff --git a/include/CommonAPI/DBus/DBusStubAdapter.hpp b/include/CommonAPI/DBus/DBusStubAdapter.hpp index 882ec8f..434c6e7 100644 --- a/include/CommonAPI/DBus/DBusStubAdapter.hpp +++ b/include/CommonAPI/DBus/DBusStubAdapter.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp b/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp index d4252ab..8a64c3b 100644 --- a/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp +++ b/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -380,6 +380,11 @@ struct DBusStubSignalHelper> DBusOutputStream outputStream(dbusMessage); const bool success = DBusSerializableArguments::serialize(outputStream, inArgs...); if (!success) { + COMMONAPI_ERROR("DBusStubSignalHelper (dbus): serialization failed! [", + dbusMessage.getObjectPath(), " ", + dbusMessage.getInterface(), ".", + dbusMessage.getMember(), " ", + dbusMessage.getSerial()); return false; } outputStream.flush(); @@ -422,6 +427,11 @@ struct DBusStubSignalHelper> DBusOutputStream outputStream(dbusMessage); const bool success = DBusSerializableArguments::serialize(outputStream, inArgs...); if (!success) { + COMMONAPI_ERROR("DBusStubSignalHelper 2 (dbus): serialization failed! [", + dbusMessage.getObjectPath(), " ", + dbusMessage.getInterface(), ".", + dbusMessage.getMember(), " ", + dbusMessage.getSerial()); return false; } outputStream.flush(); @@ -445,8 +455,8 @@ class DBusMethodStubDispatcher, DeplIn_, InArgs_...); - DBusMethodStubDispatcher(StubFunctor_ stubFunctor, std::tuple _in): - stubFunctor_(stubFunctor) { + DBusMethodStubDispatcher(StubFunctor_ stubFunctor, const bool _isImplemented, std::tuple _in): + stubFunctor_(stubFunctor), isImplemented_(_isImplemented) { initialize(typename make_sequence_range::type(), _in); } @@ -455,16 +465,20 @@ class DBusMethodStubDispatcher, DeplIn_ _connection) { (void) _remoteEventHandler; (void) _connection; + + if (!this->isImplemented_) + return false; + return handleDBusMessage(dbusMessage, stub, typename make_sequence_range::type()); } private: - template + template inline void initialize(index_sequence, std::tuple &_in) { in_ = std::make_tuple(std::get(_in)...); } - template + template inline bool handleDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr& stub, index_sequence) { @@ -472,8 +486,14 @@ class DBusMethodStubDispatcher, DeplIn_ 0) { DBusInputStream dbusInputStream(dbusMessage); const bool success = DBusSerializableArguments...>::deserialize(dbusInputStream, std::get(in_)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodStubDispatcher (dbus): deserialization failed! [", + dbusMessage.getObjectPath(), " ", + dbusMessage.getInterface(), ".", + dbusMessage.getMember(), " ", + dbusMessage.getSerial()); return false; + } } std::shared_ptr clientId = std::make_shared(std::string(dbusMessage.getSender())); @@ -484,6 +504,7 @@ class DBusMethodStubDispatcher, DeplIn_...> in_; }; @@ -512,13 +533,15 @@ class DBusMethodWithReplyStubDispatcher< std::shared_ptr, InArgs_..., ReplyType_t); DBusMethodWithReplyStubDispatcher(StubFunctor_ _stubFunctor, - const char* _dbusReplySignature, - const std::tuple& _inDepArgs, - const std::tuple& _outDepArgs): - out_(_outDepArgs), - currentCall_(0), - stubFunctor_(_stubFunctor), - dbusReplySignature_(_dbusReplySignature) { + const char* _dbusReplySignature, + const bool _isImplemented, + const std::tuple &_inDepArgs, + const std::tuple &_outDepArgs) + : out_(_outDepArgs), + currentCall_(0), + isImplemented_(_isImplemented), + stubFunctor_(_stubFunctor), + dbusReplySignature_(_dbusReplySignature) { initialize(typename make_sequence_range::type(), _inDepArgs); } @@ -528,6 +551,10 @@ class DBusMethodWithReplyStubDispatcher< RemoteEventHandlerType* _remoteEventHandler, std::weak_ptr _connection) { (void) _remoteEventHandler; + + if (!this->isImplemented_) + return false; + connection_ = _connection; return handleDBusMessage( _dbusMessage, @@ -560,15 +587,16 @@ class DBusMethodWithReplyStubDispatcher< std::mutex mutex_; // protects pending_ std::weak_ptr connection_; + const bool isImplemented_; private: - template + template inline void initialize(index_sequence, const std::tuple& _in) { in_ = std::make_tuple(std::get(_in)...); } - template + template inline bool handleDBusMessage(const DBusMessage& _dbusMessage, const std::shared_ptr& _stub, index_sequence, @@ -576,8 +604,14 @@ class DBusMethodWithReplyStubDispatcher< if (sizeof...(DeplIn_Args) > 0) { DBusInputStream dbusInputStream(_dbusMessage); const bool success = DBusSerializableArguments...>::deserialize(dbusInputStream, std::get(in_)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodWithReplyStubDispatcher (dbus): deserialization failed! [", + _dbusMessage.getObjectPath(), " ", + _dbusMessage.getInterface(), ".", + _dbusMessage.getMember(), " ", + _dbusMessage.getSerial()); return false; + } } std::shared_ptr clientId @@ -603,7 +637,7 @@ class DBusMethodWithReplyStubDispatcher< return true; } - template + template bool sendReplyInternal(const CommonAPI::CallId_t _call, index_sequence, const std::tuple...>& _args) { @@ -616,6 +650,11 @@ class DBusMethodWithReplyStubDispatcher< output, std::get(_args)...)) { (void)_args; pending_.erase(_call); + COMMONAPI_ERROR("DBusMethodWithReplyStubDispatcher (dbus): serialization failed! [", + reply->second.getObjectPath(), " ", + reply->second.getInterface(), ".", + reply->second.getMember(), " ", + reply->second.getSerial()); return false; } output.flush(); @@ -664,29 +703,26 @@ class DBusMethodWithReplyStubDispatcher< typedef void (StubClass_::*StubFunctor_)( std::shared_ptr, CommonAPI::CallId_t, InArgs_..., ReplyType_t, ErrorReplies_...); - DBusMethodWithReplyStubDispatcher(StubFunctor_ _stubFunctor, - const char* _dbusReplySignature, - const std::tuple& _inDepArgs, - const std::tuple& _outDepArgs, - const ErrorReplies_... _errorReplies) : - DBusMethodWithReplyStubDispatcher< - StubClass_, - In_, - Out_, - DeplIn_, - DeplOut_>( - NULL, - _dbusReplySignature, - _inDepArgs, - _outDepArgs), - stubFunctor_(_stubFunctor), - errorReplies_(std::make_tuple(_errorReplies...)) { } + DBusMethodWithReplyStubDispatcher(StubFunctor_ _stubFunctor, const char* _dbusReplySignature, + const bool _isImplemented, + const std::tuple &_inDepArgs, + const std::tuple &_outDepArgs, + const ErrorReplies_... _errorReplies) + : DBusMethodWithReplyStubDispatcher, Out_, + DeplIn_, DeplOut_>(NULL, + _dbusReplySignature, _isImplemented, _inDepArgs, _outDepArgs), + stubFunctor_(_stubFunctor), + errorReplies_(std::make_tuple(_errorReplies...)) { } bool dispatchDBusMessage(const DBusMessage& _dbusMessage, const std::shared_ptr& _stub, RemoteEventHandlerType* _remoteEventHandler, std::weak_ptr _connection) { (void) _remoteEventHandler; + + if (!this->isImplemented_) + return false; + this->connection_ = _connection; return handleDBusMessage( _dbusMessage, @@ -716,7 +752,7 @@ class DBusMethodWithReplyStubDispatcher< private: - template + template inline bool handleDBusMessage(const DBusMessage& _dbusMessage, const std::shared_ptr& _stub, index_sequence, @@ -725,8 +761,14 @@ class DBusMethodWithReplyStubDispatcher< if (sizeof...(DeplIn_Args) > 0) { DBusInputStream dbusInputStream(_dbusMessage); const bool success = DBusSerializableArguments...>::deserialize(dbusInputStream, std::get(this->in_)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodWithReplyStubDispatcher w/ error replies (dbus): deserialization failed! [", + _dbusMessage.getObjectPath(), " ", + _dbusMessage.getInterface(), ".", + _dbusMessage.getMember(), " ", + _dbusMessage.getSerial()); return false; + } } std::shared_ptr clientId @@ -754,7 +796,7 @@ class DBusMethodWithReplyStubDispatcher< return true; } - template + template bool sendErrorReplyInternal(CommonAPI::CallId_t _call, index_sequence, const std::tuple...>& _args) { @@ -767,6 +809,11 @@ class DBusMethodWithReplyStubDispatcher< output, std::get(_args)...)) { (void)_args; this->pending_.erase(_call); + COMMONAPI_ERROR("DBusMethodWithReplyStubDispatcher w/ error replies 2 (dbus): serialization failed! [", + reply->second.getObjectPath(), " ", + reply->second.getInterface(), ".", + reply->second.getMember(), " ", + reply->second.getSerial()); return false; } output.flush(); @@ -795,24 +842,27 @@ template < typename StubAdapterClass_, template class In_, class... InArgs_, template class Out_, class... OutArgs_> -class DBusMethodWithReplyAdapterDispatcher, Out_ >: - public StubDispatcher { +class DBusMethodWithReplyAdapterDispatcher, Out_ > + : public StubDispatcher { public: typedef typename StubClass_::RemoteEventHandlerType RemoteEventHandlerType; typedef void (StubAdapterClass_::*StubFunctor_)(std::shared_ptr, InArgs_..., OutArgs_&...); typedef typename CommonAPI::Stub StubType; - DBusMethodWithReplyAdapterDispatcher(StubFunctor_ stubFunctor, const char* dbusReplySignature): - stubFunctor_(stubFunctor), - dbusReplySignature_(dbusReplySignature) { + DBusMethodWithReplyAdapterDispatcher(StubFunctor_ stubFunctor, const char* dbusReplySignature, const bool _isImplemented) + : stubFunctor_(stubFunctor), + dbusReplySignature_(dbusReplySignature), + isImplemented_(_isImplemented) { } bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr _connection) { + RemoteEventHandlerType *_remoteEventHandler, std::weak_ptr _connection) { (void)_remoteEventHandler; + if (!this->isImplemented_) + return false; + std::tuple argTuple; return handleDBusMessage( dbusMessage, @@ -823,7 +873,7 @@ class DBusMethodWithReplyAdapterDispatcher + template inline bool handleDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr& stub, std::weak_ptr _connection, @@ -835,8 +885,14 @@ class DBusMethodWithReplyAdapterDispatcher 0) { DBusInputStream dbusInputStream(dbusMessage); const bool success = DBusSerializableArguments::deserialize(dbusInputStream, std::get(argTuple)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodWithReplyAdapterDispatcher (dbus): deserialization failed! [", + dbusMessage.getObjectPath(), " ", + dbusMessage.getInterface(), ".", + dbusMessage.getMember(), " ", + dbusMessage.getSerial()); return false; + } } std::shared_ptr clientId = std::make_shared(std::string(dbusMessage.getSender())); @@ -847,8 +903,14 @@ class DBusMethodWithReplyAdapterDispatcher 0) { DBusOutputStream dbusOutputStream(dbusMessageReply); const bool success = DBusSerializableArguments::serialize(dbusOutputStream, std::get(argTuple)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodWithReplyAdapterDispatcher (dbus): serialization failed! [", + dbusMessageReply.getObjectPath(), " ", + dbusMessageReply.getInterface(), ".", + dbusMessageReply.getMember(), " ", + dbusMessageReply.getSerial()); return false; + } dbusOutputStream.flush(); } @@ -863,6 +925,7 @@ class DBusMethodWithReplyAdapterDispatcher typedef typename StubClass_::StubAdapterType StubAdapterType; typedef typename CommonAPI::Stub StubType; - DBusGetAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, const char *_signature, AttributeDepl_ *_depl = nullptr): - lockStubFunctor_(_lockStubFunctor), - getStubFunctor_(_getStubFunctor), - signature_(_signature), - depl_(_depl) { + DBusGetAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, const char *_signature, + const bool _isImplemented, + AttributeDepl_ *_depl = nullptr) + : lockStubFunctor_(_lockStubFunctor), + getStubFunctor_(_getStubFunctor), + signature_(_signature), + isImplemented_(_isImplemented), + depl_(_depl) { } virtual ~DBusGetAttributeStubDispatcher() {}; bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr _connection) { + RemoteEventHandlerType* _remoteEventHandler, std::weak_ptr _connection) { (void) _remoteEventHandler; + + if (!this->isImplemented_) + return false; + return sendAttributeValueReply(dbusMessage, stub, _connection); } @@ -929,6 +998,7 @@ class DBusGetAttributeStubDispatcher: public virtual StubDispatcher LockStubFunctor lockStubFunctor_; GetStubFunctor getStubFunctor_; const char* signature_; + const bool isImplemented_; AttributeDepl_ *depl_; }; @@ -942,25 +1012,26 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr, AttributeType_); typedef void (RemoteEventHandlerType::*OnRemoteChangedFunctor)(); - DBusSetAttributeStubDispatcher(LockStubFunctor lockStubFunctor, - GetStubFunctor getStubFunctor, - OnRemoteSetFunctor onRemoteSetFunctor, - OnRemoteChangedFunctor onRemoteChangedFunctor, - const char* dbusSignature, - AttributeDepl_ *_depl = nullptr) : - DBusGetAttributeStubDispatcher(lockStubFunctor, getStubFunctor, dbusSignature, _depl), - onRemoteSetFunctor_(onRemoteSetFunctor), - onRemoteChangedFunctor_(onRemoteChangedFunctor) { + DBusSetAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, + OnRemoteSetFunctor onRemoteSetFunctor, OnRemoteChangedFunctor onRemoteChangedFunctor, + const char *_signature, + const bool _isImplemented, + AttributeDepl_ *_depl = nullptr) + : DBusGetAttributeStubDispatcher(_lockStubFunctor, _getStubFunctor, _signature, _isImplemented, _depl), + onRemoteSetFunctor_(onRemoteSetFunctor), + onRemoteChangedFunctor_(onRemoteChangedFunctor) { } virtual ~DBusSetAttributeStubDispatcher() {}; - bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr _connection) { + bool dispatchDBusMessage(const DBusMessage &_message, const std::shared_ptr &_stub, + RemoteEventHandlerType *_remoteEventHandler, std::weak_ptr _connection) { bool attributeValueChanged; - if (!setAttributeValue(dbusMessage, stub, _remoteEventHandler, _connection, attributeValueChanged)) + if (!this->isImplemented_) + return false; + + if (!setAttributeValue(_message, _stub, _remoteEventHandler, _connection, attributeValueChanged)) return false; if (attributeValueChanged) @@ -970,46 +1041,47 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc } protected: - virtual AttributeType_ retrieveAttributeValue(const DBusMessage& dbusMessage, bool& errorOccured) { - errorOccured = false; + virtual AttributeType_ retrieveAttributeValue(const DBusMessage &_message, bool &_errorOccured) { + _errorOccured = false; - DBusInputStream dbusInputStream(dbusMessage); - CommonAPI::Deployable attributeValue(this->depl_); - dbusInputStream >> attributeValue; + DBusInputStream itsInput(_message); + CommonAPI::Deployable itsValue(this->depl_); + itsInput >> itsValue; - if (dbusInputStream.hasError()) { - errorOccured = true; + if (itsInput.hasError()) { + _errorOccured = true; } - return attributeValue.getValue(); + return itsValue.getValue(); } - inline bool setAttributeValue(const DBusMessage& dbusMessage, - const std::shared_ptr& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr _connection, - bool& attributeValueChanged) { + inline bool setAttributeValue(const DBusMessage &_message, + const std::shared_ptr &_stub, + RemoteEventHandlerType *_remoteEventHandler, + std::weak_ptr _connection, + bool &_hasChanged) { bool errorOccured; - CommonAPI::Deployable attributeValue( - retrieveAttributeValue(dbusMessage, errorOccured), this->depl_); + CommonAPI::Deployable itsValue( + retrieveAttributeValue(_message, errorOccured), this->depl_); - if(errorOccured) { + if (errorOccured) { return false; } - std::shared_ptr clientId = std::make_shared(std::string(dbusMessage.getSender())); + std::shared_ptr clientId = std::make_shared(std::string(_message.getSender())); - attributeValueChanged = (_remoteEventHandler->*onRemoteSetFunctor_)(clientId, std::move(attributeValue.getValue())); + _hasChanged = (_remoteEventHandler->*onRemoteSetFunctor_)(clientId, std::move(itsValue.getValue())); - return this->sendAttributeValueReply(dbusMessage, stub, _connection); + return this->sendAttributeValueReply(_message, _stub, _connection); } - inline void notifyOnRemoteChanged(RemoteEventHandlerType* _remoteEventHandler) { + inline void notifyOnRemoteChanged(RemoteEventHandlerType *_remoteEventHandler) { (_remoteEventHandler->*onRemoteChangedFunctor_)(); } - inline const AttributeType_& getAttributeValue(std::shared_ptr clientId, const std::shared_ptr& stub) { - return (stub.get()->*(this->getStubFunctor_))(clientId); + inline AttributeType_ getAttributeValue(std::shared_ptr _client, + const std::shared_ptr &_stub) { + return (_stub.get()->*(this->getStubFunctor_))(_client); } const OnRemoteSetFunctor onRemoteSetFunctor_; @@ -1018,7 +1090,7 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc template class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeStubDispatcher { - public: +public: typedef typename StubClass_::RemoteEventHandlerType RemoteEventHandlerType; typedef typename StubClass_::StubAdapterType StubAdapterType; typedef typename DBusGetAttributeStubDispatcher::LockStubFunctor LockStubFunctor; @@ -1028,43 +1100,44 @@ class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeS typedef typename CommonAPI::Stub StubType; typedef void (StubAdapterType::*FireChangedFunctor)(const AttributeType_&); - DBusSetObservableAttributeStubDispatcher(LockStubFunctor lockStubFunctor, - GetStubFunctor getStubFunctor, - OnRemoteSetFunctor onRemoteSetFunctor, - OnRemoteChangedFunctor onRemoteChangedFunctor, - FireChangedFunctor fireChangedFunctor, - const char* dbusSignature, - AttributeDepl_ *_depl = nullptr) + DBusSetObservableAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, + OnRemoteSetFunctor onRemoteSetFunctor, OnRemoteChangedFunctor onRemoteChangedFunctor, + FireChangedFunctor fireChangedFunctor, + const char* dbusSignature, + const bool _isImplemented, + AttributeDepl_ *_depl = nullptr) : DBusGetAttributeStubDispatcher( - lockStubFunctor, getStubFunctor, dbusSignature, _depl), + _lockStubFunctor, _getStubFunctor, dbusSignature, _isImplemented, _depl), DBusSetAttributeStubDispatcher( - lockStubFunctor, getStubFunctor, onRemoteSetFunctor, onRemoteChangedFunctor, dbusSignature, _depl), + _lockStubFunctor, _getStubFunctor, onRemoteSetFunctor, onRemoteChangedFunctor, dbusSignature, _depl), fireChangedFunctor_(fireChangedFunctor) { } virtual ~DBusSetObservableAttributeStubDispatcher() {}; - bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr _connection) { - bool attributeValueChanged; - if (!this->setAttributeValue(dbusMessage, stub, _remoteEventHandler, _connection, attributeValueChanged)) + bool dispatchDBusMessage(const DBusMessage &_message, const std::shared_ptr &_stub, + RemoteEventHandlerType *_remoteEventHandler, std::weak_ptr _connection) { + + if (!this->isImplemented_) + return false; + + bool hasChanged; + if (!this->setAttributeValue(_message, _stub, _remoteEventHandler, _connection, hasChanged)) return false; - if (attributeValueChanged) { - std::shared_ptr clientId = std::make_shared(std::string(dbusMessage.getSender())); - fireAttributeValueChanged(clientId, _remoteEventHandler, stub); + if (hasChanged) { + std::shared_ptr itsClient = std::make_shared(std::string(_message.getSender())); + fireAttributeValueChanged(itsClient, _remoteEventHandler, _stub); this->notifyOnRemoteChanged(_remoteEventHandler); } return true; } + protected: virtual void fireAttributeValueChanged(std::shared_ptr _client, - RemoteEventHandlerType* _remoteEventHandler, - const std::shared_ptr _stub) { + RemoteEventHandlerType *_remoteEventHandler, const std::shared_ptr _stub) { (void)_remoteEventHandler; - auto stubAdapter = _stub->StubType::getStubAdapter(); (_stub.get()->*DBusGetAttributeStubDispatcher::lockStubFunctor_)(true); (stubAdapter.get()->*fireChangedFunctor_)(this->getAttributeValue(_client, _stub)); diff --git a/include/CommonAPI/DBus/DBusTypes.hpp b/include/CommonAPI/DBus/DBusTypes.hpp index ec7e092..fa7ae9c 100644 --- a/include/CommonAPI/DBus/DBusTypes.hpp +++ b/include/CommonAPI/DBus/DBusTypes.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/CommonAPI/DBus/DBusUtils.hpp b/include/CommonAPI/DBus/DBusUtils.hpp index 03fd401..5b4dbd6 100644 --- a/include/CommonAPI/DBus/DBusUtils.hpp +++ b/include/CommonAPI/DBus/DBusUtils.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/include/pugixml/pugixml.hpp b/include/pugixml/pugixml.hpp index 77b4dcf..50dcdea 100644 --- a/include/pugixml/pugixml.hpp +++ b/include/pugixml/pugixml.hpp @@ -48,9 +48,14 @@ # endif #endif -// If no API is defined, assume default #ifndef PUGIXML_API -# define PUGIXML_API +# if defined(__GNUC__) +# define PUGIXML_API __attribute__((visibility("default"))) +# elif defined(_MSC_VER) && _MSC_VER >= 1300 +# define PUGIXML_API +# else +# define PUGIXML_API +# endif #endif // If no API for classes is defined, assume default @@ -124,13 +129,13 @@ namespace pugi // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default. const unsigned int parse_eol = 0x0020; - + // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default. const unsigned int parse_wconv_attribute = 0x0040; // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default. const unsigned int parse_wnorm_attribute = 0x0080; - + // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default. const unsigned int parse_declaration = 0x0100; @@ -168,16 +173,16 @@ namespace pugi }; // Formatting flags - + // Indent the nodes that are written to output stream with as many indentation strings as deep the node is in DOM tree. This flag is on by default. const unsigned int format_indent = 0x01; - + // Write encoding-specific BOM to the output stream. This flag is off by default. const unsigned int format_write_bom = 0x02; // Use raw output mode (no indentation and no line breaks are written). This flag is off by default. const unsigned int format_raw = 0x04; - + // Omit default XML declaration even if there is no declaration in the document. This flag is off by default. const unsigned int format_no_declaration = 0x08; @@ -190,7 +195,7 @@ namespace pugi // The default set of formatting flags. // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. const unsigned int format_default = format_indent; - + // Forward declarations struct xml_attribute_struct; struct xml_node_struct; @@ -204,7 +209,7 @@ namespace pugi class xml_node; class xml_text; - + #ifndef PUGIXML_NO_XPATH class xpath_node; class xpath_node_set; @@ -277,13 +282,13 @@ namespace pugi private: xml_attribute_struct* _attr; - + typedef void (*unspecified_bool_type)(xml_attribute***); public: // Default constructor. Constructs an empty attribute. xml_attribute(); - + // Constructs attribute from internal pointer explicit xml_attribute(xml_attribute_struct* attr); @@ -378,7 +383,7 @@ namespace pugi // Borland C++ workaround bool operator!() const; - + // Comparison operators (compares wrapped node pointers) bool operator==(const xml_node& r) const; bool operator!=(const xml_node& r) const; @@ -396,7 +401,7 @@ namespace pugi // Get node name/value, or "" if node is empty or it has no name/value const char_t* name() const; const char_t* value() const; - + // Get attribute list xml_attribute first_attribute() const; xml_attribute last_attribute() const; @@ -408,7 +413,7 @@ namespace pugi // Get next/previous sibling in the children list of the parent node xml_node next_sibling() const; xml_node previous_sibling() const; - + // Get parent node xml_node parent() const; @@ -433,7 +438,7 @@ namespace pugi // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value) bool set_name(const char_t* rhs); bool set_value(const char_t* rhs); - + // Add attribute with specified name. Returns added attribute, or empty attribute on errors. xml_attribute append_attribute(const char_t* name); xml_attribute prepend_attribute(const char_t* name); @@ -476,11 +481,11 @@ namespace pugi template xml_attribute find_attribute(Predicate pred) const { if (!_root) return xml_attribute(); - + for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute()) if (pred(attrib)) return attrib; - + return xml_attribute(); } @@ -488,11 +493,11 @@ namespace pugi template xml_node find_child(Predicate pred) const { if (!_root) return xml_node(); - + for (xml_node node = first_child(); node; node = node.next_sibling()) if (pred(node)) return node; - + return xml_node(); } @@ -502,7 +507,7 @@ namespace pugi if (!_root) return xml_node(); xml_node cur = first_child(); - + while (cur._root && cur._root != _root) { if (pred(cur)) return cur; @@ -534,7 +539,7 @@ namespace pugi // Recursively traverse subtree with xml_tree_walker bool traverse(xml_tree_walker& walker); - + #ifndef PUGIXML_NO_XPATH // Select single node by evaluating XPath query. Returns first node from the resulting node set. xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = 0) const; @@ -544,7 +549,7 @@ namespace pugi xpath_node_set select_nodes(const char_t* query, xpath_variable_set* variables = 0) const; xpath_node_set select_nodes(const xpath_query& query) const; #endif - + // Print subtree using a writer object void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const; @@ -781,11 +786,11 @@ namespace pugi private: int _depth; - + protected: // Get current traversal depth int depth() const; - + public: xml_tree_walker(); virtual ~xml_tree_walker(); @@ -852,7 +857,7 @@ namespace pugi char_t* _buffer; char _memory[192]; - + // Non-copyable semantics xml_document(const xml_document&); const xml_document& operator=(const xml_document&); @@ -960,7 +965,7 @@ namespace pugi // Non-copyable semantics xpath_variable(const xpath_variable&); xpath_variable& operator=(const xpath_variable&); - + public: // Get variable name const char_t* name() const; @@ -1035,21 +1040,21 @@ namespace pugi // Get query expression return type xpath_value_type return_type() const; - + // Evaluate expression as boolean value in the specified context; performs type conversion if necessary. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. bool evaluate_boolean(const xpath_node& n) const; - + // Evaluate expression as double value in the specified context; performs type conversion if necessary. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. double evaluate_number(const xpath_node& n) const; - + #ifndef PUGIXML_NO_STL // Evaluate expression as string value in the specified context; performs type conversion if necessary. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. string_t evaluate_string(const xpath_node& n) const; #endif - + // Evaluate expression as string value in the specified context; performs type conversion if necessary. // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero). // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. @@ -1070,7 +1075,7 @@ namespace pugi // Borland C++ workaround bool operator!() const; }; - + #ifndef PUGIXML_NO_EXCEPTIONS // XPath exception class class PUGIXML_CLASS xpath_exception: public std::exception @@ -1089,20 +1094,20 @@ namespace pugi const xpath_parse_result& result() const; }; #endif - + // XPath node class (either xml_node or xml_attribute) class PUGIXML_CLASS xpath_node { private: xml_node _node; xml_attribute _attribute; - + typedef void (*unspecified_bool_type)(xpath_node***); public: // Default constructor; constructs empty XPath node xpath_node(); - + // Construct XPath node from XML node/attribute xpath_node(const xml_node& node); xpath_node(const xml_attribute& attribute, const xml_node& parent); @@ -1110,13 +1115,13 @@ namespace pugi // Get node/attribute, if any xml_node node() const; xml_attribute attribute() const; - + // Get parent of contained node/attribute xml_node parent() const; // Safe bool conversion operator operator unspecified_bool_type() const; - + // Borland C++ workaround bool operator!() const; @@ -1142,10 +1147,10 @@ namespace pugi type_sorted, // Sorted by document order (ascending) type_sorted_reverse // Sorted by document order (descending) }; - + // Constant iterator type typedef const xpath_node* const_iterator; - + // Default constructor. Constructs empty set. xpath_node_set(); @@ -1154,38 +1159,38 @@ namespace pugi // Destructor ~xpath_node_set(); - + // Copy constructor/assignment operator xpath_node_set(const xpath_node_set& ns); xpath_node_set& operator=(const xpath_node_set& ns); // Get collection type type_t type() const; - + // Get collection size size_t size() const; // Indexing operator const xpath_node& operator[](size_t index) const; - + // Collection iterators const_iterator begin() const; const_iterator end() const; // Sort the collection in ascending/descending order by document order void sort(bool reverse = false); - + // Get first node in the collection by document order xpath_node first() const; - + // Check if collection is empty bool empty() const; - + private: type_t _type; - + xpath_node _storage; - + xpath_node* _begin; xpath_node* _end; @@ -1197,7 +1202,7 @@ namespace pugi // Convert wide string to UTF8 std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf8(const wchar_t* str); std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf8(const std::basic_string, std::allocator >& str); - + // Convert UTF8 to wide string std::basic_string, std::allocator > PUGIXML_FUNCTION as_wide(const char* str); std::basic_string, std::allocator > PUGIXML_FUNCTION as_wide(const std::basic_string, std::allocator >& str); @@ -1205,13 +1210,13 @@ namespace pugi // Memory allocation function interface; returns pointer to allocated memory or NULL on failure typedef void* (*allocation_function)(size_t size); - + // Memory deallocation function interface typedef void (*deallocation_function)(void* ptr); // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions. void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate); - + // Get current memory management functions allocation_function PUGIXML_FUNCTION get_memory_allocation_function(); deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function(); @@ -1253,7 +1258,7 @@ namespace std * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND diff --git a/src/CommonAPI/DBus/DBusAddress.cpp b/src/CommonAPI/DBus/DBusAddress.cpp index 4819a40..bae8190 100644 --- a/src/CommonAPI/DBus/DBusAddress.cpp +++ b/src/CommonAPI/DBus/DBusAddress.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -27,6 +27,15 @@ DBusAddress::DBusAddress(const DBusAddress &_source) DBusAddress::~DBusAddress() { } +DBusAddress & +DBusAddress::operator=(const DBusAddress &_other) { + service_ = _other.service_; + objectPath_ = _other.objectPath_; + interface_ = _other.interface_; + + return (*this); +} + bool DBusAddress::operator==(const DBusAddress &_other) const { return (service_ == _other.service_ && @@ -97,6 +106,5 @@ operator<<(std::ostream &_out, const DBusAddress &_dbusAddress) { return _out; } - } // namespace DBus } // namespace CommonAPI diff --git a/src/CommonAPI/DBus/DBusAddressTranslator.cpp b/src/CommonAPI/DBus/DBusAddressTranslator.cpp index 643ea2e..56d5926 100644 --- a/src/CommonAPI/DBus/DBusAddressTranslator.cpp +++ b/src/CommonAPI/DBus/DBusAddressTranslator.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusClientId.cpp b/src/CommonAPI/DBus/DBusClientId.cpp index 12983b5..d6dcbc5 100644 --- a/src/CommonAPI/DBus/DBusClientId.cpp +++ b/src/CommonAPI/DBus/DBusClientId.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -58,5 +58,13 @@ DBusMessage DBusClientId::createMessage(const std::string objectPath, const std: return(returnMessage); } +uid_t DBusClientId::getUid() const { + return (0); +} + +gid_t DBusClientId::getGid() const { + return (0); +} + } // namespace DBus } // namespace CommonAPI diff --git a/src/CommonAPI/DBus/DBusConnection.cpp b/src/CommonAPI/DBus/DBusConnection.cpp index 06c3f5d..7364849 100644 --- a/src/CommonAPI/DBus/DBusConnection.cpp +++ b/src/CommonAPI/DBus/DBusConnection.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -231,7 +231,7 @@ bool DBusConnection::attachMainLoopContext(std::weak_ptr mainLo lockedContext->registerDispatchSource(queueDispatchSource_); lockedContext->registerWatch(queueWatch_); - dispatchSource_ = new DBusDispatchSource(this); + dispatchSource_ = new DBusDispatchSource(shared_from_this()); watchContext_ = new WatchContext(mainLoopContext_, dispatchSource_, shared_from_this()); lockedContext->registerDispatchSource(dispatchSource_); @@ -620,6 +620,8 @@ void DBusConnection::onLibdbusPendingCall(::DBusPendingCall* _libdbusPendingCall delete _dbusMessageReplyAsyncHandler; } else { _dbusMessageReplyAsyncHandler->unlock(); + std::lock_guard enforcerLock(enforcerThreadMutex_); + enforceTimeoutCondition_.notify_one(); } } @@ -1373,9 +1375,12 @@ bool DBusConnection::removeLibdbusSignalMatchRule(const std::string& dbusMatchRu dbus_bus_remove_match(connection_, dbusMatchRule.c_str(), NULL); - libdbusSignalMatchRulesCount_--; - if (libdbusSignalMatchRulesCount_ == 0) { - dbus_connection_remove_filter(connection_, &onLibdbusSignalFilterThunk, this); + { + std::unique_lock dbusConnectionLock(connectionGuard_); + libdbusSignalMatchRulesCount_--; + if (libdbusSignalMatchRulesCount_ == 0) { + dbus_connection_remove_filter(connection_, &onLibdbusSignalFilterThunk, this); + } } return true; @@ -1493,7 +1498,6 @@ void DBusConnection::addLibdbusSignalMatchRule(const std::string& objectPath, // add the libdbus message signal filter if (isFirstMatchRule) { - libdbusSuccess = 0 != dbus_connection_add_filter( connection_, &onLibdbusSignalFilterThunk, @@ -1795,19 +1799,6 @@ void DBusConnection::pushDBusMessageReplyToMainLoop(const DBusMessage& _reply, queueWatch_->pushQueue(msgReplyQueueEntry); } -void DBusConnection::setPendingCallTimedOut(DBusPendingCall* _pendingCall, ::DBusTimeout* _timeout) const { - std::lock_guard lock(enforceTimeoutMutex_); - auto it = timeoutMap_.find(_pendingCall); - if(it != timeoutMap_.end()) { - auto replyAsyncHandler = std::get<1>(it->second); - replyAsyncHandler->lock(); - if(!replyAsyncHandler->getTimeoutOccurred()) { - dbus_timeout_handle(_timeout); - } - replyAsyncHandler->unlock(); - } -} - void DBusConnection::deleteAsyncHandlers() { std::vector asyncHandlers; { diff --git a/src/CommonAPI/DBus/DBusDaemonProxy.cpp b/src/CommonAPI/DBus/DBusDaemonProxy.cpp index 7c2ce50..2258bb7 100644 --- a/src/CommonAPI/DBus/DBusDaemonProxy.cpp +++ b/src/CommonAPI/DBus/DBusDaemonProxy.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -48,6 +48,9 @@ DBusDaemonProxy::DBusDaemonProxy(const std::shared_ptr& dbu interfaceVersionAttribute_(1, 0) { } +DBusDaemonProxy::~DBusDaemonProxy() { +} + void DBusDaemonProxy::init() { } @@ -100,7 +103,8 @@ void DBusDaemonProxy::listNames(CommonAPI::CallStatus& callStatus, std::vector>::deserialize(inputStream, busNames); if (!success) { - callStatus = CallStatus::REMOTE_ERROR; + COMMONAPI_ERROR("DBusDaemonProxy::", __func__, ": deserialization failed!"); + callStatus = CallStatus::SERIALIZATION_ERROR; return; } @@ -113,7 +117,8 @@ void DBusDaemonProxy::nameHasOwner(const std::string& busName, CommonAPI::CallSt DBusOutputStream outputStream(dbusMethodCall); bool success = DBusSerializableArguments::serialize(outputStream, busName); if (!success) { - callStatus = CallStatus::OUT_OF_MEMORY; + COMMONAPI_ERROR("DBusDaemonProxy::", __func__, ": serialization failed!"); + callStatus = CallStatus::SERIALIZATION_ERROR; return; } outputStream.flush(); @@ -131,7 +136,8 @@ void DBusDaemonProxy::nameHasOwner(const std::string& busName, CommonAPI::CallSt DBusInputStream inputStream(dbusMessageReply); success = DBusSerializableArguments::deserialize(inputStream, hasOwner); if (!success) { - callStatus = CallStatus::REMOTE_ERROR; + COMMONAPI_ERROR("DBusDaemonProxy::", __func__, ": deserialization failed!"); + callStatus = CallStatus::SERIALIZATION_ERROR; return; } callStatus = CallStatus::SUCCESS; diff --git a/src/CommonAPI/DBus/DBusError.cpp b/src/CommonAPI/DBus/DBusError.cpp index 4b51318..2e9f46a 100644 --- a/src/CommonAPI/DBus/DBusError.cpp +++ b/src/CommonAPI/DBus/DBusError.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusFactory.cpp b/src/CommonAPI/DBus/DBusFactory.cpp index 332b1d5..ef17f9a 100644 --- a/src/CommonAPI/DBus/DBusFactory.cpp +++ b/src/CommonAPI/DBus/DBusFactory.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp b/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp index d9c950f..f4e7252 100644 --- a/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp +++ b/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusFunctionalHash.cpp b/src/CommonAPI/DBus/DBusFunctionalHash.cpp index 7e5dad0..2b54fb5 100644 --- a/src/CommonAPI/DBus/DBusFunctionalHash.cpp +++ b/src/CommonAPI/DBus/DBusFunctionalHash.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusInputStream.cpp b/src/CommonAPI/DBus/DBusInputStream.cpp index 1bede6f..6f59741 100644 --- a/src/CommonAPI/DBus/DBusInputStream.cpp +++ b/src/CommonAPI/DBus/DBusInputStream.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.cpp b/src/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.cpp index 8b88753..80bf391 100644 --- a/src/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.cpp +++ b/src/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -280,5 +280,3 @@ void DBusInstanceAvailabilityStatusChangedEvent::translate( } // namespace DBus } // namespace CommonAPI - - diff --git a/src/CommonAPI/DBus/DBusMainLoop.cpp b/src/CommonAPI/DBus/DBusMainLoop.cpp index 6b3d5e6..dec9888 100755 --- a/src/CommonAPI/DBus/DBusMainLoop.cpp +++ b/src/CommonAPI/DBus/DBusMainLoop.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -220,17 +220,15 @@ void DBusMainLoop::stop() { void DBusMainLoop::doSingleIteration(const int64_t& timeout) { { - std::lock_guard itsDispatchSourcesLock(dispatchSourcesMutex_); + std::lock_guard itsDispatchSourcesLock(dispatchSourcesMutex_); std::lock_guard itsWatchesLock(watchesMutex_); for (auto dispatchSourceIterator = registeredDispatchSources_.begin(); dispatchSourceIterator != registeredDispatchSources_.end(); dispatchSourceIterator++) { - (dispatchSourceIterator->second)->mutex_->lock(); if ((dispatchSourceIterator->second)->deleteObject_) { if (!(dispatchSourceIterator->second)->isExecuted_) { - (dispatchSourceIterator->second)->mutex_->unlock(); bool contained = false; for (std::set>::iterator dispatchSourceIteratorInner = sourcesToDispatch_.begin(); dispatchSourceIteratorInner != sourcesToDispatch_.end(); dispatchSourceIteratorInner++) { @@ -242,8 +240,6 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { if (!contained) { delete (dispatchSourceIterator->second)->dispatchSource_; (dispatchSourceIterator->second)->dispatchSource_ = NULL; - delete (dispatchSourceIterator->second)->mutex_; - (dispatchSourceIterator->second)->mutex_ = NULL; delete dispatchSourceIterator->second; dispatchSourceIterator = registeredDispatchSources_.erase(dispatchSourceIterator); } @@ -251,12 +247,6 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { break; } } - else { - (dispatchSourceIterator->second)->mutex_->unlock(); - } - } - else { - (dispatchSourceIterator->second)->mutex_->unlock(); } } @@ -264,10 +254,8 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { watchesIterator != registeredWatches_.end(); watchesIterator++) { - (watchesIterator->second)->mutex_->lock(); if ((watchesIterator->second)->deleteObject_) { if (!(watchesIterator->second)->isExecuted_) { - (watchesIterator->second)->mutex_->unlock(); bool contained = false; for (auto watchesIteratorInner = watchesToDispatch_.begin(); watchesIteratorInner != watchesToDispatch_.end(); watchesIteratorInner++) { @@ -279,8 +267,6 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { if (!contained) { delete (watchesIterator->second)->watch_; (watchesIterator->second)->watch_ = NULL; - delete (watchesIterator->second)->mutex_; - (watchesIterator->second)->mutex_ = NULL; delete watchesIterator->second; watchesIterator = registeredWatches_.erase(watchesIterator); } @@ -288,12 +274,6 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { break; } } - else { - (watchesIterator->second)->mutex_->unlock(); - } - } - else { - (watchesIterator->second)->mutex_->unlock(); } } } @@ -304,10 +284,8 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { timeoutIterator != registeredTimeouts_.end(); timeoutIterator++) { - (timeoutIterator->second)->mutex_->lock(); if ((timeoutIterator->second)->deleteObject_) { if (!(timeoutIterator->second)->isExecuted_) { - (timeoutIterator->second)->mutex_->unlock(); bool contained = false; for (std::set>::iterator timeoutIteratorInner = timeoutsToDispatch_.begin(); timeoutIteratorInner != timeoutsToDispatch_.end(); timeoutIteratorInner++) { @@ -319,8 +297,6 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { if (!contained) { delete (timeoutIterator->second)->timeout_; (timeoutIterator->second)->timeout_ = NULL; - delete (timeoutIterator->second)->mutex_; - (timeoutIterator->second)->mutex_ = NULL; delete timeoutIterator->second; timeoutIterator = registeredTimeouts_.erase(timeoutIterator); } @@ -328,12 +304,6 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { break; } } - else { - (timeoutIterator->second)->mutex_->unlock(); - } - } - else { - (timeoutIterator->second)->mutex_->unlock(); } } } @@ -351,22 +321,22 @@ void DBusMainLoop::doSingleIteration(const int64_t& timeout) { bool DBusMainLoop::prepare(const int64_t& timeout) { currentMinimalTimeoutInterval_ = timeout; - dispatchSourcesMutex_.lock(); - for (auto dispatchSourceIterator = registeredDispatchSources_.begin(); - dispatchSourceIterator != registeredDispatchSources_.end(); - dispatchSourceIterator++) { + { + std::lock_guard itsLock(dispatchSourcesMutex_); + for (auto dispatchSourceIterator = registeredDispatchSources_.begin(); + dispatchSourceIterator != registeredDispatchSources_.end(); + dispatchSourceIterator++) { + + int64_t dispatchTimeout = TIMEOUT_INFINITE; - int64_t dispatchTimeout = TIMEOUT_INFINITE; - dispatchSourcesMutex_.unlock(); - if (!(dispatchSourceIterator->second->deleteObject_) && - (dispatchSourceIterator->second)->dispatchSource_->prepare(dispatchTimeout)) { - sourcesToDispatch_.insert(*dispatchSourceIterator); - } else if (dispatchTimeout > 0 && dispatchTimeout < currentMinimalTimeoutInterval_) { - currentMinimalTimeoutInterval_ = dispatchTimeout; + if (!(dispatchSourceIterator->second)->deleteObject_ && + (dispatchSourceIterator->second)->dispatchSource_->prepare(dispatchTimeout)) { + sourcesToDispatch_.insert(*dispatchSourceIterator); + } else if (dispatchTimeout > 0 && dispatchTimeout < currentMinimalTimeoutInterval_) { + currentMinimalTimeoutInterval_ = dispatchTimeout; + } } - dispatchSourcesMutex_.lock(); } - dispatchSourcesMutex_.unlock(); int64_t currentContextTime = getCurrentTimeInMs(); @@ -376,11 +346,7 @@ bool DBusMainLoop::prepare(const int64_t& timeout) { timeoutPriorityRange != registeredTimeouts_.end(); timeoutPriorityRange++) { - (timeoutPriorityRange->second)->mutex_->lock(); - bool deleteObject = (timeoutPriorityRange->second)->deleteObject_; - (timeoutPriorityRange->second)->mutex_->unlock(); - - if (!deleteObject) { + if (!(timeoutPriorityRange->second)->deleteObject_) { if (!(timeoutPriorityRange->second)->timeoutElapsed_) { // check that timeout is not elapsed int64_t intervalToReady = (timeoutPriorityRange->second)->timeout_->getReadyTime() - currentContextTime; @@ -450,11 +416,7 @@ void DBusMainLoop::poll() { timeoutPriorityRange != registeredTimeouts_.end(); timeoutPriorityRange++) { - (timeoutPriorityRange->second)->mutex_->lock(); - bool deleteObject = (timeoutPriorityRange->second)->deleteObject_; - (timeoutPriorityRange->second)->mutex_->unlock(); - - if (!deleteObject) { + if (!(timeoutPriorityRange->second)->deleteObject_) { if (!(timeoutPriorityRange->second)->timeoutElapsed_) { // check that timeout is not elapsed int64_t intervalToReady = (timeoutPriorityRange->second)->timeout_->getReadyTime() @@ -491,11 +453,7 @@ bool DBusMainLoop::check() { registeredWatchIterator != registeredWatches_.end(); registeredWatchIterator++) { - (registeredWatchIterator->second)->mutex_->lock(); - bool deleteObject = (registeredWatchIterator->second)->deleteObject_; - (registeredWatchIterator->second)->mutex_->unlock(); - - if (!deleteObject) { + if (!(registeredWatchIterator->second)->deleteObject_) { if ((registeredWatchIterator->second)->fd_ == fileDescriptor->fd && fileDescriptor->revents) { watchesToDispatch_.insert(*registeredWatchIterator); @@ -506,18 +464,18 @@ bool DBusMainLoop::check() { } } - dispatchSourcesMutex_.lock(); - for (auto dispatchSourceIterator = registeredDispatchSources_.begin(); - dispatchSourceIterator != registeredDispatchSources_.end(); - ++dispatchSourceIterator) { - dispatchSourcesMutex_.unlock(); - if (!dispatchSourceIterator->second->deleteObject_&& - dispatchSourceIterator->second->dispatchSource_->check()) { - sourcesToDispatch_.insert(*dispatchSourceIterator); + { + std::lock_guard itsLock(dispatchSourcesMutex_); + for (auto dispatchSourceIterator = registeredDispatchSources_.begin(); + dispatchSourceIterator != registeredDispatchSources_.end(); + ++dispatchSourceIterator) { + + if (!(dispatchSourceIterator->second)->deleteObject_ && + dispatchSourceIterator->second->dispatchSource_->check()) { + sourcesToDispatch_.insert(*dispatchSourceIterator); + } } - dispatchSourcesMutex_.lock(); } - dispatchSourcesMutex_.unlock(); return (!timeoutsToDispatch_.empty() || !watchesToDispatch_.empty() || @@ -530,17 +488,12 @@ void DBusMainLoop::dispatch() { for (auto timeoutIterator = timeoutsToDispatch_.begin(); timeoutIterator != timeoutsToDispatch_.end(); timeoutIterator++) { auto timeoutToDispatchStruct = std::get<1>(*timeoutIterator); - timeoutToDispatchStruct->mutex_->lock(); if (!timeoutToDispatchStruct->deleteObject_) { timeoutToDispatchStruct->isExecuted_ = true; - timeoutToDispatchStruct->mutex_->unlock(); timeoutToDispatchStruct->timeout_->dispatch(); - timeoutToDispatchStruct->mutex_->lock(); timeoutToDispatchStruct->isExecuted_ = false; } - timeoutToDispatchStruct->mutex_->unlock(); } - timeoutsToDispatch_.clear(); } @@ -549,17 +502,13 @@ void DBusMainLoop::dispatch() { for (auto watchIterator = watchesToDispatch_.begin(); watchIterator != watchesToDispatch_.end(); watchIterator++) { auto watchToDispatchStruct = std::get<1>(*watchIterator); - watchToDispatchStruct->mutex_->lock(); if (!watchToDispatchStruct->deleteObject_) { watchToDispatchStruct->isExecuted_ = true; - watchToDispatchStruct->mutex_->unlock(); Watch* watch = watchToDispatchStruct->watch_; const unsigned int flags = (unsigned int)(watch->getAssociatedFileDescriptor().events); watch->dispatch(flags); - watchToDispatchStruct->mutex_->lock(); watchToDispatchStruct->isExecuted_ = false; } - watchToDispatchStruct->mutex_->unlock(); } watchesToDispatch_.clear(); } @@ -571,20 +520,14 @@ void DBusMainLoop::dispatch() { dispatchSourceIterator != sourcesToDispatch_.end() && !isBroken_; dispatchSourceIterator++) { auto dispatchSourceToDispatchStruct = std::get<1>(*dispatchSourceIterator); - dispatchSourceToDispatchStruct->mutex_->lock(); if (!dispatchSourceToDispatchStruct->deleteObject_) { dispatchSourceToDispatchStruct->isExecuted_ = true; - dispatchSourceToDispatchStruct->mutex_->unlock(); while(!dispatchSourceToDispatchStruct->deleteObject_ && dispatchSourceToDispatchStruct->dispatchSource_->dispatch()); - dispatchSourceToDispatchStruct->mutex_->lock(); dispatchSourceToDispatchStruct->isExecuted_ = false; } - dispatchSourceToDispatchStruct->mutex_->unlock(); - } - { - sourcesToDispatch_.clear(); } + sourcesToDispatch_.clear(); } } @@ -635,14 +578,12 @@ void DBusMainLoop::wakeupAck() { void DBusMainLoop::cleanup() { { - std::lock_guard itsLock(dispatchSourcesMutex_); + std::lock_guard itsLock(dispatchSourcesMutex_); for (auto dispatchSourceIterator = registeredDispatchSources_.begin(); dispatchSourceIterator != registeredDispatchSources_.end();) { delete (dispatchSourceIterator->second)->dispatchSource_; (dispatchSourceIterator->second)->dispatchSource_ = NULL; - delete (dispatchSourceIterator->second)->mutex_; - (dispatchSourceIterator->second)->mutex_ = NULL; delete dispatchSourceIterator->second; dispatchSourceIterator = registeredDispatchSources_.erase(dispatchSourceIterator); } @@ -655,8 +596,6 @@ void DBusMainLoop::cleanup() { delete (timeoutIterator->second)->timeout_; (timeoutIterator->second)->timeout_ = NULL; - delete (timeoutIterator->second)->mutex_; - (timeoutIterator->second)->mutex_ = NULL; delete timeoutIterator->second; timeoutIterator = registeredTimeouts_.erase(timeoutIterator); } @@ -669,8 +608,6 @@ void DBusMainLoop::cleanup() { delete (watchesIterator->second)->watch_; (watchesIterator->second)->watch_ = NULL; - delete (watchesIterator->second)->mutex_; - (watchesIterator->second)->mutex_ = NULL; delete watchesIterator->second; watchesIterator = registeredWatches_.erase(watchesIterator); } @@ -698,22 +635,20 @@ void DBusMainLoop::unregisterFileDescriptor( void DBusMainLoop::registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority) { - DispatchSourceToDispatchStruct* dispatchSourceStruct = new DispatchSourceToDispatchStruct(dispatchSource, new std::mutex, false, false); - std::lock_guard itsLock(dispatchSourcesMutex_); + DispatchSourceToDispatchStruct* dispatchSourceStruct = new DispatchSourceToDispatchStruct(dispatchSource, false, false); + std::lock_guard itsLock(dispatchSourcesMutex_); registeredDispatchSources_.insert({ dispatchPriority, dispatchSourceStruct }); } void DBusMainLoop::unregisterDispatchSource(DispatchSource* dispatchSource) { { - std::lock_guard itsLock(dispatchSourcesMutex_); + std::lock_guard itsLock(dispatchSourcesMutex_); for (auto dispatchSourceIterator = registeredDispatchSources_.begin(); dispatchSourceIterator != registeredDispatchSources_.end(); dispatchSourceIterator++) { if ((dispatchSourceIterator->second)->dispatchSource_ == dispatchSource){ - (dispatchSourceIterator->second)->mutex_->lock(); (dispatchSourceIterator->second)->deleteObject_ = true; - (dispatchSourceIterator->second)->mutex_->unlock(); break; } } @@ -728,13 +663,12 @@ void DBusMainLoop::registerWatch(Watch* watch, registerFileDescriptor(fdToRegister); std::lock_guard itsLock(watchesMutex_); - std::mutex* mtx = new std::mutex; #ifdef _WIN32 std::atomic_signal_fence(std::memory_order_acq_rel); #else asm volatile ("":::"memory"); #endif - WatchToDispatchStruct* watchStruct = new WatchToDispatchStruct(fdToRegister.fd, watch, mtx, false, false); + WatchToDispatchStruct* watchStruct = new WatchToDispatchStruct(fdToRegister.fd, watch, false, false); registeredWatches_.insert({ dispatchPriority, watchStruct}); } @@ -747,9 +681,7 @@ void DBusMainLoop::unregisterWatch(Watch* watch) { watchIterator != registeredWatches_.end(); watchIterator++) { if ((watchIterator->second)->watch_ == watch) { - (watchIterator->second)->mutex_->lock(); (watchIterator->second)->deleteObject_ = true; - (watchIterator->second)->mutex_->unlock(); break; } } @@ -758,7 +690,7 @@ void DBusMainLoop::unregisterWatch(Watch* watch) { void DBusMainLoop::registerTimeout(Timeout* timeout, const DispatchPriority dispatchPriority) { - TimeoutToDispatchStruct* timeoutStruct = new TimeoutToDispatchStruct(timeout, new std::mutex, false, false, false); + TimeoutToDispatchStruct* timeoutStruct = new TimeoutToDispatchStruct(timeout, false, false, false); std::lock_guard itsLock(timeoutsMutex_); registeredTimeouts_.insert({ dispatchPriority, timeoutStruct }); } @@ -771,9 +703,7 @@ void DBusMainLoop::unregisterTimeout(Timeout* timeout) { timeoutIterator++) { if ((timeoutIterator->second)->timeout_ == timeout) { - (timeoutIterator->second)->mutex_->lock(); (timeoutIterator->second)->deleteObject_ = true; - (timeoutIterator->second)->mutex_->unlock(); break; } } diff --git a/src/CommonAPI/DBus/DBusMainLoopContext.cpp b/src/CommonAPI/DBus/DBusMainLoopContext.cpp index 150676e..c68e296 100644 --- a/src/CommonAPI/DBus/DBusMainLoopContext.cpp +++ b/src/CommonAPI/DBus/DBusMainLoopContext.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -23,7 +23,7 @@ namespace CommonAPI { namespace DBus { -DBusDispatchSource::DBusDispatchSource(DBusConnection* dbusConnection): +DBusDispatchSource::DBusDispatchSource(std::weak_ptr dbusConnection): dbusConnection_(dbusConnection) { } @@ -32,15 +32,24 @@ DBusDispatchSource::~DBusDispatchSource() { bool DBusDispatchSource::prepare(int64_t &_timeout) { _timeout = -1; - return dbusConnection_->isDispatchReady(); + if(auto itsConnection = dbusConnection_.lock()) { + return itsConnection->isDispatchReady(); + } + return false; } bool DBusDispatchSource::check() { - return dbusConnection_->isDispatchReady(); + if(auto itsConnection = dbusConnection_.lock()) { + return itsConnection->isDispatchReady(); + } + return false; } bool DBusDispatchSource::dispatch() { - return dbusConnection_->singleDispatch(); + if(auto itsConnection = dbusConnection_.lock()) { + return itsConnection->singleDispatch(); + } + return false; } DBusQueueDispatchSource::DBusQueueDispatchSource(DBusQueueWatch* watch) : @@ -467,77 +476,5 @@ void DBusQueueWatch::processQueueEntry(std::shared_ptr _queueEntry) } } -#ifdef _WIN32 -__declspec(thread) DBusTimeout* DBusTimeout::currentTimeout_ = NULL; -#else -thread_local DBusTimeout* DBusTimeout::currentTimeout_ = NULL; -#endif - -DBusTimeout::DBusTimeout(::DBusTimeout* libdbusTimeout, std::weak_ptr& mainLoopContext, - std::weak_ptr& dbusConnection) : - dueTimeInMs_(TIMEOUT_INFINITE), - libdbusTimeout_(libdbusTimeout), - mainLoopContext_(mainLoopContext), - dbusConnection_(dbusConnection), - pendingCall_(NULL) { - currentTimeout_ = this; -} - -bool DBusTimeout::isReadyToBeMonitored() { - return 0 != dbus_timeout_get_enabled(libdbusTimeout_); -} - -void DBusTimeout::startMonitoring() { - auto lockedContext = mainLoopContext_.lock(); - if (NULL == lockedContext) { - COMMONAPI_ERROR(std::string(__FUNCTION__) + " lockedContext == NULL"); - } else { - recalculateDueTime(); - lockedContext->registerTimeoutSource(this); - } -} - -void DBusTimeout::stopMonitoring() { - dueTimeInMs_ = TIMEOUT_INFINITE; - auto lockedContext = mainLoopContext_.lock(); - if (lockedContext) { - lockedContext->deregisterTimeoutSource(this); - } -} - -bool DBusTimeout::dispatch() { - std::shared_ptr itsConnection = dbusConnection_.lock(); - if(itsConnection) { - if(itsConnection->setDispatching(true)) { - recalculateDueTime(); - itsConnection->setPendingCallTimedOut(pendingCall_, libdbusTimeout_); - itsConnection->setDispatching(false); - return true; - } - } - return false; -} - -int64_t DBusTimeout::getTimeoutInterval() const { - return dbus_timeout_get_interval(libdbusTimeout_); -} - -int64_t DBusTimeout::getReadyTime() const { - return dueTimeInMs_; -} - -void DBusTimeout::recalculateDueTime() { - if(dbus_timeout_get_enabled(libdbusTimeout_)) { - int intervalInMs = dbus_timeout_get_interval(libdbusTimeout_); - dueTimeInMs_ = getCurrentTimeInMs() + intervalInMs; - } else { - dueTimeInMs_ = TIMEOUT_INFINITE; - } -} - -void DBusTimeout::setPendingCall(DBusPendingCall* _pendingCall) { - pendingCall_ = _pendingCall; -} - } // namespace DBus } // namespace CommonAPI diff --git a/src/CommonAPI/DBus/DBusMessage.cpp b/src/CommonAPI/DBus/DBusMessage.cpp index 4bdf760..b6ad6ba 100644 --- a/src/CommonAPI/DBus/DBusMessage.cpp +++ b/src/CommonAPI/DBus/DBusMessage.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusObjectManager.cpp b/src/CommonAPI/DBus/DBusObjectManager.cpp index cf5fbc2..eb53506 100644 --- a/src/CommonAPI/DBus/DBusObjectManager.cpp +++ b/src/CommonAPI/DBus/DBusObjectManager.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusObjectManagerStub.cpp b/src/CommonAPI/DBus/DBusObjectManagerStub.cpp index 226c825..845cd50 100644 --- a/src/CommonAPI/DBus/DBusObjectManagerStub.cpp +++ b/src/CommonAPI/DBus/DBusObjectManagerStub.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusOutputStream.cpp b/src/CommonAPI/DBus/DBusOutputStream.cpp index 3f77c8f..31b4f62 100644 --- a/src/CommonAPI/DBus/DBusOutputStream.cpp +++ b/src/CommonAPI/DBus/DBusOutputStream.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -16,7 +16,8 @@ namespace CommonAPI { namespace DBus { DBusOutputStream::DBusOutputStream(DBusMessage dbusMessage) - : dbusMessage_(dbusMessage) { + : errorOccurred_(false), + dbusMessage_(dbusMessage) { } // Internal @@ -36,7 +37,7 @@ size_t DBusOutputStream::popPosition() { // TODO Check where dbusError_ is set bool DBusOutputStream::hasError() const { - return dbusError_; + return errorOccurred_; } // Writes the data that was buffered within this #DBusOutputMessageStream to @@ -52,6 +53,7 @@ void DBusOutputStream::flush() { } void DBusOutputStream::setError() { + errorOccurred_ = true; } /** diff --git a/src/CommonAPI/DBus/DBusProxy.cpp b/src/CommonAPI/DBus/DBusProxy.cpp index 2c11d8f..49d29b6 100644 --- a/src/CommonAPI/DBus/DBusProxy.cpp +++ b/src/CommonAPI/DBus/DBusProxy.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -651,6 +651,8 @@ void DBusProxy::freeDesktopGetCurrentValueForSignalListener( _message, DBusProxyAsyncSignalMemberCallbackHandler::create(delegate, dbusSignalHandler, subscription), &defaultCallInfo); + } else { + COMMONAPI_ERROR("DBusProxy::", __func__, ": serialization failed!"); } } else { availabilityMutex_.unlock(); diff --git a/src/CommonAPI/DBus/DBusProxyBase.cpp b/src/CommonAPI/DBus/DBusProxyBase.cpp index f4add0e..ce5d17f 100644 --- a/src/CommonAPI/DBus/DBusProxyBase.cpp +++ b/src/CommonAPI/DBus/DBusProxyBase.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusProxyManager.cpp b/src/CommonAPI/DBus/DBusProxyManager.cpp index a522bf4..8355066 100644 --- a/src/CommonAPI/DBus/DBusProxyManager.cpp +++ b/src/CommonAPI/DBus/DBusProxyManager.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/CommonAPI/DBus/DBusServiceRegistry.cpp b/src/CommonAPI/DBus/DBusServiceRegistry.cpp index 2953d12..247aa2e 100644 --- a/src/CommonAPI/DBus/DBusServiceRegistry.cpp +++ b/src/CommonAPI/DBus/DBusServiceRegistry.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -23,7 +23,7 @@ std::mutex DBusServiceRegistry::registriesMutex_; static CommonAPI::CallInfo serviceRegistryInfo(10000); std::shared_ptr -DBusServiceRegistry::get(std::shared_ptr _connection, bool _insert) { +DBusServiceRegistry::get(const std::shared_ptr &_connection, bool _insert) { std::unique_lock itsGuard(registriesMutex_); auto registries = getRegistryMap(); auto registryIterator = registries->find(_connection.get()); @@ -43,7 +43,7 @@ DBusServiceRegistry::get(std::shared_ptr _connection, bool } void -DBusServiceRegistry::remove(std::shared_ptr _connection) { +DBusServiceRegistry::remove(const std::shared_ptr &_connection) { std::lock_guard itsGuard(registriesMutex_); auto registries = getRegistryMap(); registries->erase(_connection.get()); @@ -759,6 +759,7 @@ bool DBusServiceRegistry::getManagedObjects(const std::string& dbusServiceName, DBusInputStream input(reply); if (!DBusSerializableArguments::deserialize( input, availableServiceInstances) || error) + COMMONAPI_ERROR("DBusServiceRegistry::", __func__, ": deserialization failed!"); return false; } return true; diff --git a/src/CommonAPI/DBus/DBusStubAdapter.cpp b/src/CommonAPI/DBus/DBusStubAdapter.cpp index 44ed866..ecdbb56 100644 --- a/src/CommonAPI/DBus/DBusStubAdapter.cpp +++ b/src/CommonAPI/DBus/DBusStubAdapter.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2013-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/murmurhash/MurmurHash3.cpp b/src/murmurhash/MurmurHash3.cpp index 86ca147..01292e3 100644 --- a/src/murmurhash/MurmurHash3.cpp +++ b/src/murmurhash/MurmurHash3.cpp @@ -130,7 +130,9 @@ void MurmurHash3_x86_32 ( const void * key, unsigned int len, switch(len & 3) { case 3: k1 ^= uint32_t(tail[2] << 16); + /* FALLTHROUGH */ case 2: k1 ^= uint32_t(tail[1] << 8); + /* FALLTHROUGH */ case 1: k1 ^= tail[0]; k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; }; @@ -205,25 +207,36 @@ void MurmurHash3_x86_128 ( const void * key, const unsigned int len, switch(len & 15) { case 15: k4 ^= uint32_t(tail[14] << 16); + /* FALLTHROUGH */ case 14: k4 ^= uint32_t(tail[13] << 8); + /* FALLTHROUGH */ case 13: k4 ^= tail[12]; k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4; - + /* FALLTHROUGH */ case 12: k3 ^= uint32_t(tail[11] << 24); + /* FALLTHROUGH */ case 11: k3 ^= uint32_t(tail[10] << 16); + /* FALLTHROUGH */ case 10: k3 ^= uint32_t(tail[ 9] << 8); + /* FALLTHROUGH */ case 9: k3 ^= tail[ 8]; k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3; - + /* FALLTHROUGH */ case 8: k2 ^= uint32_t(tail[ 7] << 24); + /* FALLTHROUGH */ case 7: k2 ^= uint32_t(tail[ 6] << 16); + /* FALLTHROUGH */ case 6: k2 ^= uint32_t(tail[ 5] << 8); + /* FALLTHROUGH */ case 5: k2 ^= tail[ 4]; k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2; - + /* FALLTHROUGH */ case 4: k1 ^= uint32_t(tail[ 3] << 24); + /* FALLTHROUGH */ case 3: k1 ^= uint32_t(tail[ 2] << 16); + /* FALLTHROUGH */ case 2: k1 ^= uint32_t(tail[ 1] << 8); + /* FALLTHROUGH */ case 1: k1 ^= tail[ 0]; k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; }; @@ -294,21 +307,34 @@ void MurmurHash3_x64_128 ( const void * key, const unsigned int len, switch(len & 15) { case 15: k2 ^= uint64_t(tail[14]) << 48; + /* FALLTHROUGH */ case 14: k2 ^= uint64_t(tail[13]) << 40; + /* FALLTHROUGH */ case 13: k2 ^= uint64_t(tail[12]) << 32; + /* FALLTHROUGH */ case 12: k2 ^= uint64_t(tail[11]) << 24; + /* FALLTHROUGH */ case 11: k2 ^= uint64_t(tail[10]) << 16; + /* FALLTHROUGH */ case 10: k2 ^= uint64_t(tail[ 9]) << 8; + /* FALLTHROUGH */ case 9: k2 ^= uint64_t(tail[ 8]) << 0; k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; - + /* FALLTHROUGH */ case 8: k1 ^= uint64_t(tail[ 7]) << 56; + /* FALLTHROUGH */ case 7: k1 ^= uint64_t(tail[ 6]) << 48; + /* FALLTHROUGH */ case 6: k1 ^= uint64_t(tail[ 5]) << 40; + /* FALLTHROUGH */ case 5: k1 ^= uint64_t(tail[ 4]) << 32; + /* FALLTHROUGH */ case 4: k1 ^= uint64_t(tail[ 3]) << 24; + /* FALLTHROUGH */ case 3: k1 ^= uint64_t(tail[ 2]) << 16; + /* FALLTHROUGH */ case 2: k1 ^= uint64_t(tail[ 1]) << 8; + /* FALLTHROUGH */ case 1: k1 ^= uint64_t(tail[ 0]) << 0; k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; }; @@ -332,4 +358,3 @@ void MurmurHash3_x64_128 ( const void * key, const unsigned int len, } //----------------------------------------------------------------------------- - diff --git a/src/pugixml/pugixml.cpp b/src/pugixml/pugixml.cpp index a97e065..84144e0 100644 --- a/src/pugixml/pugixml.cpp +++ b/src/pugixml/pugixml.cpp @@ -8119,7 +8119,7 @@ PUGI__NS_BEGIN // fallthrough to type conversion } - + /* FALLTHRU */ default: { switch (_rettype) @@ -8255,7 +8255,7 @@ PUGI__NS_BEGIN // fallthrough to type conversion } - + /* FALLTHRU */ default: { switch (_rettype) @@ -8524,7 +8524,7 @@ PUGI__NS_BEGIN // fallthrough to type conversion } - + /* FALLTHROUGH */ default: { switch (_rettype) @@ -8673,7 +8673,7 @@ PUGI__NS_BEGIN // fallthrough to type conversion } - + /* FALLTHROUGH */ default: assert(0 && "Wrong expression for return type node set"); return xpath_node_set_raw(); diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 3707379..5e8cd02 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -23,53 +23,6 @@ if ("${USE_INSTALLED_DBUS}" STREQUAL "OFF") ) endif() -set(VERSION "v1") - -set(TestInterfaceSources src-gen/core/commonapi/tests/DerivedTypeCollection.cpp - src-gen/core/${VERSION}/commonapi/tests/TestInterfaceStubDefault.cpp) - -set(TestInterfaceDBusSources ${TestInterfaceSources} - src-gen/dbus/${VERSION}/commonapi/tests/TestInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/TestInterfaceDBusStubAdapter.cpp - src-gen/dbus/${VERSION}/fake/legacy/service/LegacyInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/fake/legacy/service/LegacyInterfaceNoObjectManagerDBusProxy.cpp) - -set(TestInterfaceManagerSources src-gen/core/${VERSION}/commonapi/tests/TestInterfaceManagerStubDefault.cpp) - -set(TestInterfaceManagerDBusSources ${TestInterfaceManagerSources} - src-gen/dbus/${VERSION}/commonapi/tests/TestInterfaceManagerDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/TestInterfaceManagerDBusStubAdapter.cpp) - -set(FreedesktopPropertiesSources src-gen/core/${VERSION}/commonapi/tests/TestFreedesktopInterfaceStubDefault.cpp - src-gen/core/${VERSION}/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.cpp) - -set(FreedesktopPropertiesDBusSources ${FreedesktopPropertiesSources} - src-gen/dbus/${VERSION}/commonapi/tests/TestFreedesktopInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.cpp - src-gen/dbus/${VERSION}/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.cpp) - -set(ManagedSources src-gen/core/${VERSION}/commonapi/tests/managed/LeafInterfaceStubDefault.cpp - src-gen/core/${VERSION}/commonapi/tests/managed/BranchInterfaceStubDefault.cpp - src-gen/core/${VERSION}/commonapi/tests/managed/RootInterfaceStubDefault.cpp - src-gen/core/${VERSION}/commonapi/tests/managed/SecondRootStubDefault.cpp) - -set(ManagedDBusSources ${ManagedSources} - src-gen/dbus/${VERSION}/commonapi/tests/managed/RootInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp - src-gen/dbus/${VERSION}/commonapi/tests/managed/LeafInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp - src-gen/dbus/${VERSION}/commonapi/tests/managed/BranchInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp - src-gen/dbus/${VERSION}/commonapi/tests/managed/SecondRootDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp) - -set(ExtendedInterfaceSources src-gen/core/${VERSION}/commonapi/tests/ExtendedInterfaceStubDefault.cpp) - -set(ExtendedInterfaceDBusSources ${ExtendedInterfaceSources} - src-gen/dbus/${VERSION}/commonapi/tests/ExtendedInterfaceDBusProxy.cpp - src-gen/dbus/${VERSION}/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp) - if (MSVC) set(TEST_LINK_LIBRARIES ${DBus_LDFLAGS} CommonAPI-DBus CommonAPI gtest ) else() diff --git a/src/test/DBusClientIdTest.cpp b/src/test/DBusClientIdTest.cpp index d94a4aa..a94a2af 100644 --- a/src/test/DBusClientIdTest.cpp +++ b/src/test/DBusClientIdTest.cpp @@ -36,7 +36,12 @@ class TestClientId: public CommonAPI::ClientId { std::size_t hashCode() { return 0; } - + CommonAPI::uid_t getUid() const { + return 0; + } + CommonAPI::gid_t getGid() const { + return 0; + } }; TEST_F(DBusClientIdTest, TestClientIdImplementation) {