diff options
Diffstat (limited to 'include/CommonAPI/DBus')
43 files changed, 437 insertions, 310 deletions
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 @@ public: 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 @@ public: 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 @@ public: template<class Function, class... Arguments> 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<DBusMainloop> 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<void(const CommonAPI::CallStatus&, std::string)> GetNameOwnerAsyncCallback; COMMONAPI_EXPORT DBusDaemonProxy(const std::shared_ptr<DBusProxyConnection>& 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<std::string>::serialize(outputStream, busName); if (!success) { std::promise<CallStatus> 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<std::string>::serialize(outputStream, busName); if (!success) { std::promise<CallStatus> 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 @@ public: private: - template <int... DeplIn_ArgIndices> + template <size_t... DeplIn_ArgIndices> inline void initialize(index_sequence<DeplIn_ArgIndices...>, const std::tuple<DeplIn_Args*...> &_in) { in_ = std::make_tuple(std::get<DeplIn_ArgIndices>(_in)...); } - template <int... InArgIndices_> + template <size_t... InArgIndices_> void deserialize(const DBusMessage &_reply, index_sequence<InArgIndices_...>) { if (sizeof...(InArgs_) > 0) { DBusInputStream dbusInputStream(_reply); const bool success = DBusSerializableArguments<CommonAPI::Deployable<InArgs_, DeplIn_Args>...>::deserialize(dbusInputStream, std::get<InArgIndices_>(in_)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusErrorEvent::", __func__, "(", errorName_, "): deserialization failed!"); return; + } this->notifyListeners(errorName_, std::move(std::get<InArgIndices_>(in_).getValue())...); } } @@ -96,7 +98,7 @@ private: class DBusErrorEventHelper { public: - template <int... ErrorEventsIndices_, class... ErrorEvents_> + template <size_t... ErrorEventsIndices_, class... ErrorEvents_> static void notifyListeners(const DBusMessage &_reply, const std::string &_errorName, index_sequence<ErrorEventsIndices_...>, 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 @@ public: std::get<3>(subscription_) = ""; } - template<int ... Indices_> + template<size_t ... Indices_> inline void handleSignalDBusMessage(const DBusMessage &_message, index_sequence<Indices_...>) { DBusInputStream input(_message); if (DBusSerializableArguments< @@ -165,7 +165,7 @@ public: } } - template<int ... Indices_> + template<size_t ... Indices_> inline void handleSignalDBusMessage(const uint32_t tag, const DBusMessage &_message, index_sequence<Indices_...>) { 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 @@ public: typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::LockStubFunctor LockStubFunctor; typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::GetStubFunctor GetStubFunctor; - DBusGetFreedesktopAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, AttributeDepl_ *_depl = nullptr) - : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, "v", _depl) { + DBusGetFreedesktopAttributeStubDispatcher(LockStubFunctor _lockStubFunctor, GetStubFunctor _getStubFunctor, const bool _isImplemented, AttributeDepl_ *_depl = nullptr) + : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, "v", _isImplemented, _depl) { } virtual ~DBusGetFreedesktopAttributeStubDispatcher() {}; @@ -93,15 +93,13 @@ public: typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr<CommonAPI::ClientId>, 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<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, "v", _depl), - DBusGetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _depl), - DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl) { + : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, "v", _isImplemented, _depl), + DBusGetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _isImplemented, _depl), + DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _isImplemented, _depl) { } virtual ~DBusSetFreedesktopAttributeStubDispatcher() {}; @@ -133,18 +131,16 @@ public: 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<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, "v", _depl), - DBusGetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _depl), - DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl), - DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _depl), - DBusSetObservableAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _fireChangedFunctor, "v", _depl) { + : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, "v", _isImplemented, _depl), + DBusGetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _isImplemented, _depl), + DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _isImplemented, _depl), + DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _isImplemented, _depl), + DBusSetObservableAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_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 <int ...> +template <size_t ...> struct index_sequence {}; -template <int N_, int ...S_> +template <size_t N_, size_t ...S_> struct make_sequence : make_sequence<N_-1, N_-1, S_...> {}; -template <int ...S_> +template <size_t ...S_> struct make_sequence<0, S_...> { typedef index_sequence<S_...> type; }; -template <int N_, int Offset_, int ...S_> +template <size_t N_, size_t Offset_, size_t ...S_> struct make_sequence_range : make_sequence_range<N_-1, Offset_, N_-1+Offset_, S_...> {}; -template <int Offset_, int ...S_> +template <size_t Offset_, size_t ...S_> struct make_sequence_range<0, Offset_, S_...> { typedef index_sequence<S_...> 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 @@ public: return (*this); } + template<int minimum, int maximum> + COMMONAPI_EXPORT InputStream &readValue(RangedInteger<minimum, maximum> &_value, const EmptyDeployment *) { + int tmpValue; + readValue(tmpValue, static_cast<EmptyDeployment *>(nullptr)); + if(!_value.validate()) { + setError(); + } + if (!hasError()) { + _value = tmpValue; + } + return (*this); + } + template<class Deployment_, typename Base_> COMMONAPI_EXPORT InputStream &readValue(Enumeration<Base_> &_value, const Deployment_ *_depl) { Base_ tmpValue; @@ -479,40 +492,51 @@ private: _readRaw(length + 1); } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_class<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(!std::is_class<Type_>::value && + !is_std_vector<Type_>::value && + !is_std_unordered_map<Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { if (4 < sizeof(Type_)) align(8); } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_same<Type_, std::string>::value>::type * = nullptr, - typename std::enable_if<std::is_class<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr, - typename std::enable_if<!std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(!std::is_same<Type_, std::string>::value && + std::is_class<Type_>::value && + !is_std_vector<Type_>::value && + !is_std_unordered_map<Type_>::value && + !std::is_base_of<Enumeration<uint8_t>, Type_>::value && + !std::is_base_of<Enumeration<uint16_t>, Type_>::value && + !std::is_base_of<Enumeration<uint32_t>, Type_>::value && + !std::is_base_of<Enumeration<int8_t>, Type_>::value && + !std::is_base_of<Enumeration<int16_t>, Type_>::value && + !std::is_base_of<Enumeration<int32_t>, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(8); } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_same<Type_, std::string>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(std::is_same<Type_, std::string>::value || + is_std_vector<Type_>::value || + std::is_base_of<Enumeration<uint8_t>, Type_>::value || + std::is_base_of<Enumeration<int8_t>, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { // Intentionally do nothing } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_vector<Type_>::value>::type * = nullptr) { - // Intentionally do nothing - } - - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_unordered_map<Type_>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(is_std_unordered_map<Type_>::value || + std::is_base_of<Enumeration<uint32_t>, Type_>::value || + std::is_base_of<Enumeration<int32_t>, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(4); } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) { - align(4); + template<typename Type_, + typename std::enable_if<(std::is_base_of<Enumeration<uint16_t>, Type_>::value || + std::is_base_of<Enumeration<int16_t>, 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<bool> isExecuted_; /* execution flag: indicates, whether the dispatchSource is dispatched currently */ + std::atomic<bool> 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<bool> isExecuted_; /* execution flag: indicates, whether the timeout is dispatched currently */ + std::atomic<bool> deleteObject_; /* delete flag: indicates, whether the timeout can be deleted*/ + std::atomic<bool> 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<bool> isExecuted_; /* execution flag: indicates, whether the watch is dispatched currently */ + std::atomic<bool> 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<DispatchPriority, WatchToDispatchStruct*> registeredWatches_; std::multimap<DispatchPriority, TimeoutToDispatchStruct*> registeredTimeouts_; - std::mutex dispatchSourcesMutex_; + std::recursive_mutex dispatchSourcesMutex_; std::mutex watchesMutex_; std::mutex timeoutsMutex_; @@ -179,7 +170,7 @@ class DBusMainLoop { #endif std::atomic<bool> hasToStop_; - bool isBroken_; + std::atomic<bool> 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> dbusConnection); ~DBusDispatchSource(); bool prepare(int64_t& timeout); @@ -36,7 +36,7 @@ class DBusDispatchSource: public DispatchSource { bool dispatch(); private: - DBusConnection* dbusConnection_; + std::weak_ptr<DBusConnection> dbusConnection_; }; class DBusQueueWatch; @@ -146,41 +146,6 @@ private: }; - -class DBusTimeout: public Timeout { - public: - DBusTimeout(::DBusTimeout* libdbusTimeout, - std::weak_ptr<MainLoopContext>& mainLoopContext, - std::weak_ptr<DBusConnection>& 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<int64_t> dueTimeInMs_; - ::DBusTimeout* libdbusTimeout_; - std::weak_ptr<MainLoopContext> mainLoopContext_; - std::weak_ptr<DBusConnection> 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 @@ public: return (*this); } + template<int minimum, int maximum> + COMMONAPI_EXPORT OutputStream &writeValue(const RangedInteger<minimum, maximum> &_value, const EmptyDeployment *) { + if (_value.validate()) + writeValue(_value.value_, static_cast<EmptyDeployment *>(nullptr)); + else + setError(); + return (*this); + } + template<class Deployment_, typename Base_> COMMONAPI_EXPORT OutputStream &writeValue(const Enumeration<Base_> &_value, const Deployment_ *_depl = nullptr) { return writeValue(static_cast<Base_>(_value), _depl); @@ -359,40 +368,51 @@ private: COMMONAPI_EXPORT void pushPosition(); COMMONAPI_EXPORT size_t popPosition(); - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_class<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(!std::is_class<Type_>::value && + !is_std_vector<Type_>::value && + !is_std_unordered_map<Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { if (4 < sizeof(Type_)) align(8); } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_same<Type_, std::string>::value>::type * = nullptr, - typename std::enable_if<std::is_class<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr, - typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr, - typename std::enable_if<!std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(!std::is_same<Type_, std::string>::value && + std::is_class<Type_>::value && + !is_std_vector<Type_>::value && + !is_std_unordered_map<Type_>::value && + !std::is_base_of<Enumeration<uint8_t>, Type_>::value && + !std::is_base_of<Enumeration<uint16_t>, Type_>::value && + !std::is_base_of<Enumeration<uint32_t>, Type_>::value && + !std::is_base_of<Enumeration<int8_t>, Type_>::value && + !std::is_base_of<Enumeration<int16_t>, Type_>::value && + !std::is_base_of<Enumeration<int32_t>, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(8); } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_same<Type_, std::string>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(std::is_same<Type_, std::string>::value || + is_std_vector<Type_>::value || + std::is_base_of<Enumeration<uint8_t>, Type_>::value || + std::is_base_of<Enumeration<int8_t>, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { // Intentionally do nothing } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_vector<Type_>::value>::type * = nullptr) { - // Intentionally do nothing - } - - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_unordered_map<Type_>::value>::type * = nullptr) { + template<typename Type_, + typename std::enable_if<(is_std_unordered_map<Type_>::value || + std::is_base_of<Enumeration<uint32_t>, Type_>::value || + std::is_base_of<Enumeration<int32_t>, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { align(4); } - template<typename Type_> - COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) { - align(4); + template<typename Type_, + typename std::enable_if<(std::is_base_of<Enumeration<uint16_t>, Type_>::value || + std::is_base_of<Enumeration<int16_t>, Type_>::value), int>::type = 0> + COMMONAPI_EXPORT void alignVector() { + align(2); } COMMONAPI_EXPORT void setError(); @@ -459,7 +479,7 @@ private: COMMONAPI_EXPORT size_t getCurrentStreamPosition(); - DBusError dbusError_; + bool errorOccurred_; DBusMessage dbusMessage_; std::vector<size_t> 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 @@ private: } // 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<ArgTypes_...> args_; private: - template <int... ArgIndices_> + template <size_t... ArgIndices_> inline CallStatus handleDBusMessageReply( const CallStatus _dbusMessageCallStatus, const DBusMessage& _dbusMessage, @@ -132,10 +132,9 @@ class DBusProxyAsyncCallbackHandler : if (_dbusMessageCallStatus == CallStatus::SUCCESS) { DBusInputStream dbusInputStream(_dbusMessage); - if(DBusSerializableArguments<ArgTypes_...>::deserialize(dbusInputStream, + if(!DBusSerializableArguments<ArgTypes_...>::deserialize(dbusInputStream, std::get<ArgIndices_>(_argTuple)...)) { - } else { - callStatus = CallStatus::REMOTE_ERROR; + callStatus = CallStatus::SERIALIZATION_ERROR; } } @@ -195,7 +194,7 @@ public: private: - template <int... ArgIndices_> + template <size_t... ArgIndices_> inline CallStatus handleDBusMessageReply( const CallStatus _dbusMessageCallStatus, const DBusMessage& _dbusMessage, @@ -208,10 +207,9 @@ private: if (_dbusMessageCallStatus == CallStatus::SUCCESS) { DBusInputStream dbusInputStream(_dbusMessage); - if(DBusSerializableArguments<ArgTypes_...>::deserialize(dbusInputStream, + if (!DBusSerializableArguments<ArgTypes_...>::deserialize(dbusInputStream, std::get<ArgIndices_>(_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 <memory> #include <string> +#include <CommonAPI/Logger.hpp> + #include <CommonAPI/DBus/DBusAddress.hpp> #include <CommonAPI/DBus/DBusConfig.hpp> #include <CommonAPI/DBus/DBusMessage.hpp> @@ -62,7 +64,13 @@ struct DBusProxyHelper<In_<DBusInputStream, DBusOutputStream, InArgs_...>, if (sizeof...(InArgs_) > 0) { DBusOutputStream output(message); if (!DBusSerializableArguments<InArgs_...>::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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, if (sizeof...(InArgs_) > 0) { DBusOutputStream output(_message); if (!DBusSerializableArguments<InArgs_...>::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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, if (sizeof...(OutArgs_) > 0) { DBusInputStream input(reply); if (!DBusSerializableArguments<OutArgs_...>::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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, InArgs_... >::serialize(output, _in...); if (!success) { + COMMONAPI_ERROR("MethodAsync (dbus): serialization failed: [", + _message.getObjectPath(), " ", + _message.getInterface(), " ", + _message.getMember(), " ", + _message.getSerial(), "]"); + std::promise<CallStatus> 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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, 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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, return callMethodAsync(_proxy, message, _info, _in..., _function, _out); } - template <int... ArgIndices_> + template <size_t... ArgIndices_> static void callCallbackOnNotAvailable(std::function<void(CallStatus, OutArgs_&...)> _callback, index_sequence<ArgIndices_...>, std::tuple<OutArgs_...> _out) { const CallStatus status(CallStatus::NOT_AVAILABLE); @@ -347,7 +377,13 @@ struct DBusProxyHelper<In_<DBusInputStream, DBusOutputStream, InArgs_...>, if (sizeof...(InArgs_) > 0) { DBusOutputStream output(_message); if (!DBusSerializableArguments<InArgs_...>::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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, if (sizeof...(OutArgs_) > 0) { DBusInputStream input(reply); if (!DBusSerializableArguments<OutArgs_...>::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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, 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<CallStatus> 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<In_<DBusInputStream, DBusOutputStream, InArgs_...>, 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<DBusServiceRegistry>, +class COMMONAPI_EXPORT DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegistry>, public DBusProxyConnection::DBusSignalHandler { public: enum class DBusRecordState { @@ -73,8 +73,8 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist typedef std::function<void(const DBusObjectManagerStub::DBusObjectPathAndInterfacesDict)> GetAvailableServiceInstancesCallback; - static std::shared_ptr<DBusServiceRegistry> get(std::shared_ptr<DBusProxyConnection> _connection, bool _insert=true); - static void remove(std::shared_ptr<DBusProxyConnection> _connection); + static std::shared_ptr<DBusServiceRegistry> get(const std::shared_ptr<DBusProxyConnection> &_connection, bool _insert=true); + static void remove(const std::shared_ptr<DBusProxyConnection> &_connection); DBusServiceRegistry(std::shared_ptr<DBusProxyConnection> 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<In_<DBusInputStream, DBusOutputStream, InArgs_...>> DBusOutputStream outputStream(dbusMessage); const bool success = DBusSerializableArguments<InArgs_...>::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<In_<DBusInputStream, DBusOutputStream, InArgs_...>> DBusOutputStream outputStream(dbusMessage); const bool success = DBusSerializableArguments<InArgs_...>::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<StubClass_, In_<InArgs_...>, DeplIn_<DeplIn_Args. typedef typename StubClass_::RemoteEventHandlerType RemoteEventHandlerType; typedef void (StubClass_::*StubFunctor_)(std::shared_ptr<CommonAPI::ClientId>, InArgs_...); - DBusMethodStubDispatcher(StubFunctor_ stubFunctor, std::tuple<DeplIn_Args*...> _in): - stubFunctor_(stubFunctor) { + DBusMethodStubDispatcher(StubFunctor_ stubFunctor, const bool _isImplemented, std::tuple<DeplIn_Args*...> _in): + stubFunctor_(stubFunctor), isImplemented_(_isImplemented) { initialize(typename make_sequence_range<sizeof...(DeplIn_Args), 0>::type(), _in); } @@ -455,16 +465,20 @@ class DBusMethodStubDispatcher<StubClass_, In_<InArgs_...>, DeplIn_<DeplIn_Args. std::weak_ptr<DBusProxyConnection> _connection) { (void) _remoteEventHandler; (void) _connection; + + if (!this->isImplemented_) + return false; + return handleDBusMessage(dbusMessage, stub, typename make_sequence_range<sizeof...(InArgs_), 0>::type()); } private: - template <int... DeplIn_ArgIndices> + template <size_t... DeplIn_ArgIndices> inline void initialize(index_sequence<DeplIn_ArgIndices...>, std::tuple<DeplIn_Args*...> &_in) { in_ = std::make_tuple(std::get<DeplIn_ArgIndices>(_in)...); } - template <int... InArgIndices_> + template <size_t... InArgIndices_> inline bool handleDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, index_sequence<InArgIndices_...>) { @@ -472,8 +486,14 @@ class DBusMethodStubDispatcher<StubClass_, In_<InArgs_...>, DeplIn_<DeplIn_Args. if (sizeof...(InArgs_) > 0) { DBusInputStream dbusInputStream(dbusMessage); const bool success = DBusSerializableArguments<CommonAPI::Deployable<InArgs_, DeplIn_Args>...>::deserialize(dbusInputStream, std::get<InArgIndices_>(in_)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodStubDispatcher (dbus): deserialization failed! [", + dbusMessage.getObjectPath(), " ", + dbusMessage.getInterface(), ".", + dbusMessage.getMember(), " ", + dbusMessage.getSerial()); return false; + } } std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender())); @@ -484,6 +504,7 @@ class DBusMethodStubDispatcher<StubClass_, In_<InArgs_...>, DeplIn_<DeplIn_Args. } StubFunctor_ stubFunctor_; + const bool isImplemented_; std::tuple<CommonAPI::Deployable<InArgs_, DeplIn_Args>...> in_; }; @@ -512,13 +533,15 @@ class DBusMethodWithReplyStubDispatcher< std::shared_ptr<CommonAPI::ClientId>, InArgs_..., ReplyType_t); DBusMethodWithReplyStubDispatcher(StubFunctor_ _stubFunctor, - const char* _dbusReplySignature, - const std::tuple<DeplIn_Args*...>& _inDepArgs, - const std::tuple<DeplOutArgs_*...>& _outDepArgs): - out_(_outDepArgs), - currentCall_(0), - stubFunctor_(_stubFunctor), - dbusReplySignature_(_dbusReplySignature) { + const char* _dbusReplySignature, + const bool _isImplemented, + const std::tuple<DeplIn_Args*...> &_inDepArgs, + const std::tuple<DeplOutArgs_*...> &_outDepArgs) + : out_(_outDepArgs), + currentCall_(0), + isImplemented_(_isImplemented), + stubFunctor_(_stubFunctor), + dbusReplySignature_(_dbusReplySignature) { initialize(typename make_sequence_range<sizeof...(DeplIn_Args), 0>::type(), _inDepArgs); } @@ -528,6 +551,10 @@ class DBusMethodWithReplyStubDispatcher< RemoteEventHandlerType* _remoteEventHandler, std::weak_ptr<DBusProxyConnection> _connection) { (void) _remoteEventHandler; + + if (!this->isImplemented_) + return false; + connection_ = _connection; return handleDBusMessage( _dbusMessage, @@ -560,15 +587,16 @@ protected: std::mutex mutex_; // protects pending_ std::weak_ptr<DBusProxyConnection> connection_; + const bool isImplemented_; private: - template <int... DeplIn_ArgIndices> + template <size_t... DeplIn_ArgIndices> inline void initialize(index_sequence<DeplIn_ArgIndices...>, const std::tuple<DeplIn_Args*...>& _in) { in_ = std::make_tuple(std::get<DeplIn_ArgIndices>(_in)...); } - template <int... InArgIndices_, int... OutArgIndices_> + template <size_t... InArgIndices_, size_t... OutArgIndices_> inline bool handleDBusMessage(const DBusMessage& _dbusMessage, const std::shared_ptr<StubClass_>& _stub, index_sequence<InArgIndices_...>, @@ -576,8 +604,14 @@ private: if (sizeof...(DeplIn_Args) > 0) { DBusInputStream dbusInputStream(_dbusMessage); const bool success = DBusSerializableArguments<CommonAPI::Deployable<InArgs_, DeplIn_Args>...>::deserialize(dbusInputStream, std::get<InArgIndices_>(in_)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodWithReplyStubDispatcher (dbus): deserialization failed! [", + _dbusMessage.getObjectPath(), " ", + _dbusMessage.getInterface(), ".", + _dbusMessage.getMember(), " ", + _dbusMessage.getSerial()); return false; + } } std::shared_ptr<DBusClientId> clientId @@ -603,7 +637,7 @@ private: return true; } - template<int... OutArgIndices_> + template<size_t... OutArgIndices_> bool sendReplyInternal(const CommonAPI::CallId_t _call, index_sequence<OutArgIndices_...>, const std::tuple<CommonAPI::Deployable<OutArgs_, DeplOutArgs_>...>& _args) { @@ -616,6 +650,11 @@ private: output, std::get<OutArgIndices_>(_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::ClientId>, CommonAPI::CallId_t, InArgs_..., ReplyType_t, ErrorReplies_...); - DBusMethodWithReplyStubDispatcher(StubFunctor_ _stubFunctor, - const char* _dbusReplySignature, - const std::tuple<DeplIn_Args*...>& _inDepArgs, - const std::tuple<DeplOutArgs_*...>& _outDepArgs, - const ErrorReplies_... _errorReplies) : - DBusMethodWithReplyStubDispatcher< - StubClass_, - In_<InArgs_...>, - Out_<OutArgs_...>, - DeplIn_<DeplIn_Args...>, - DeplOut_<DeplOutArgs_...>>( - NULL, - _dbusReplySignature, - _inDepArgs, - _outDepArgs), - stubFunctor_(_stubFunctor), - errorReplies_(std::make_tuple(_errorReplies...)) { } + DBusMethodWithReplyStubDispatcher(StubFunctor_ _stubFunctor, const char* _dbusReplySignature, + const bool _isImplemented, + const std::tuple<DeplIn_Args*...> &_inDepArgs, + const std::tuple<DeplOutArgs_*...> &_outDepArgs, + const ErrorReplies_... _errorReplies) + : DBusMethodWithReplyStubDispatcher<StubClass_, In_<InArgs_...>, Out_<OutArgs_...>, + DeplIn_<DeplIn_Args...>, DeplOut_<DeplOutArgs_...>>(NULL, + _dbusReplySignature, _isImplemented, _inDepArgs, _outDepArgs), + stubFunctor_(_stubFunctor), + errorReplies_(std::make_tuple(_errorReplies...)) { } bool dispatchDBusMessage(const DBusMessage& _dbusMessage, const std::shared_ptr<StubClass_>& _stub, RemoteEventHandlerType* _remoteEventHandler, std::weak_ptr<DBusProxyConnection> _connection) { (void) _remoteEventHandler; + + if (!this->isImplemented_) + return false; + this->connection_ = _connection; return handleDBusMessage( _dbusMessage, @@ -716,7 +752,7 @@ class DBusMethodWithReplyStubDispatcher< private: - template <int... InArgIndices_, int... OutArgIndices_, int... ErrorRepliesIndices_> + template <size_t... InArgIndices_, size_t... OutArgIndices_, size_t... ErrorRepliesIndices_> inline bool handleDBusMessage(const DBusMessage& _dbusMessage, const std::shared_ptr<StubClass_>& _stub, index_sequence<InArgIndices_...>, @@ -725,8 +761,14 @@ private: if (sizeof...(DeplIn_Args) > 0) { DBusInputStream dbusInputStream(_dbusMessage); const bool success = DBusSerializableArguments<CommonAPI::Deployable<InArgs_, DeplIn_Args>...>::deserialize(dbusInputStream, std::get<InArgIndices_>(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<DBusClientId> clientId @@ -754,7 +796,7 @@ private: return true; } - template<int... ErrorReplyOutArgIndices_, class... ErrorReplyOutArgs_, class ...ErrorReplyDeplOutArgs_> + template<size_t... ErrorReplyOutArgIndices_, class... ErrorReplyOutArgs_, class ...ErrorReplyDeplOutArgs_> bool sendErrorReplyInternal(CommonAPI::CallId_t _call, index_sequence<ErrorReplyOutArgIndices_...>, const std::tuple<CommonAPI::Deployable<ErrorReplyOutArgs_, ErrorReplyDeplOutArgs_>...>& _args) { @@ -767,6 +809,11 @@ private: output, std::get<ErrorReplyOutArgIndices_>(_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...> class In_, class... InArgs_, template <class...> class Out_, class... OutArgs_> -class DBusMethodWithReplyAdapterDispatcher<StubClass_, StubAdapterClass_, In_<InArgs_...>, Out_<OutArgs_...> >: - public StubDispatcher<StubClass_> { +class DBusMethodWithReplyAdapterDispatcher<StubClass_, StubAdapterClass_, In_<InArgs_...>, Out_<OutArgs_...> > + : public StubDispatcher<StubClass_> { public: typedef typename StubClass_::RemoteEventHandlerType RemoteEventHandlerType; typedef void (StubAdapterClass_::*StubFunctor_)(std::shared_ptr<CommonAPI::ClientId>, InArgs_..., OutArgs_&...); typedef typename CommonAPI::Stub<typename StubClass_::StubAdapterType, typename StubClass_::RemoteEventType> 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<StubClass_>& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr<DBusProxyConnection> _connection) { + RemoteEventHandlerType *_remoteEventHandler, std::weak_ptr<DBusProxyConnection> _connection) { (void)_remoteEventHandler; + if (!this->isImplemented_) + return false; + std::tuple<InArgs_..., OutArgs_...> argTuple; return handleDBusMessage( dbusMessage, @@ -823,7 +873,7 @@ class DBusMethodWithReplyAdapterDispatcher<StubClass_, StubAdapterClass_, In_<In } private: - template <int... InArgIndices_, int... OutArgIndices_> + template <size_t... InArgIndices_, size_t... OutArgIndices_> inline bool handleDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, std::weak_ptr<DBusProxyConnection> _connection, @@ -835,8 +885,14 @@ class DBusMethodWithReplyAdapterDispatcher<StubClass_, StubAdapterClass_, In_<In if (sizeof...(InArgs_) > 0) { DBusInputStream dbusInputStream(dbusMessage); const bool success = DBusSerializableArguments<InArgs_...>::deserialize(dbusInputStream, std::get<InArgIndices_>(argTuple)...); - if (!success) + if (!success) { + COMMONAPI_ERROR("DBusMethodWithReplyAdapterDispatcher (dbus): deserialization failed! [", + dbusMessage.getObjectPath(), " ", + dbusMessage.getInterface(), ".", + dbusMessage.getMember(), " ", + dbusMessage.getSerial()); return false; + } } std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender())); @@ -847,8 +903,14 @@ class DBusMethodWithReplyAdapterDispatcher<StubClass_, StubAdapterClass_, In_<In if (sizeof...(OutArgs_) > 0) { DBusOutputStream dbusOutputStream(dbusMessageReply); const bool success = DBusSerializableArguments<OutArgs_...>::serialize(dbusOutputStream, std::get<OutArgIndices_>(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<StubClass_, StubAdapterClass_, In_<In StubFunctor_ stubFunctor_; const char* dbusReplySignature_; + const bool isImplemented_; }; @@ -875,19 +938,25 @@ class DBusGetAttributeStubDispatcher: public virtual StubDispatcher<StubClass_> typedef typename StubClass_::StubAdapterType StubAdapterType; typedef typename CommonAPI::Stub<StubAdapterType, typename StubClass_::RemoteEventType> 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<StubClass_>& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr<DBusProxyConnection> _connection) { + RemoteEventHandlerType* _remoteEventHandler, std::weak_ptr<DBusProxyConnection> _connection) { (void) _remoteEventHandler; + + if (!this->isImplemented_) + return false; + return sendAttributeValueReply(dbusMessage, stub, _connection); } @@ -929,6 +998,7 @@ class DBusGetAttributeStubDispatcher: public virtual StubDispatcher<StubClass_> 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<CommonAPI::ClientId>, AttributeType_); typedef void (RemoteEventHandlerType::*OnRemoteChangedFunctor)(); - DBusSetAttributeStubDispatcher(LockStubFunctor lockStubFunctor, - GetStubFunctor getStubFunctor, - OnRemoteSetFunctor onRemoteSetFunctor, - OnRemoteChangedFunctor onRemoteChangedFunctor, - const char* dbusSignature, - AttributeDepl_ *_depl = nullptr) : - DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(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<StubClass_, AttributeType_, AttributeDepl_>(_lockStubFunctor, _getStubFunctor, _signature, _isImplemented, _depl), + onRemoteSetFunctor_(onRemoteSetFunctor), + onRemoteChangedFunctor_(onRemoteChangedFunctor) { } virtual ~DBusSetAttributeStubDispatcher() {}; - bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr<DBusProxyConnection> _connection) { + bool dispatchDBusMessage(const DBusMessage &_message, const std::shared_ptr<StubClass_> &_stub, + RemoteEventHandlerType *_remoteEventHandler, std::weak_ptr<DBusProxyConnection> _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<AttributeType_, AttributeDepl_> attributeValue(this->depl_); - dbusInputStream >> attributeValue; + DBusInputStream itsInput(_message); + CommonAPI::Deployable<AttributeType_, AttributeDepl_> 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<StubClass_>& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr<DBusProxyConnection> _connection, - bool& attributeValueChanged) { + inline bool setAttributeValue(const DBusMessage &_message, + const std::shared_ptr<StubClass_> &_stub, + RemoteEventHandlerType *_remoteEventHandler, + std::weak_ptr<DBusProxyConnection> _connection, + bool &_hasChanged) { bool errorOccured; - CommonAPI::Deployable<AttributeType_, AttributeDepl_> attributeValue( - retrieveAttributeValue(dbusMessage, errorOccured), this->depl_); + CommonAPI::Deployable<AttributeType_, AttributeDepl_> itsValue( + retrieveAttributeValue(_message, errorOccured), this->depl_); - if(errorOccured) { + if (errorOccured) { return false; } - std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender())); + std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(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<CommonAPI::ClientId> clientId, const std::shared_ptr<StubClass_>& stub) { - return (stub.get()->*(this->getStubFunctor_))(clientId); + inline AttributeType_ getAttributeValue(std::shared_ptr<CommonAPI::ClientId> _client, + const std::shared_ptr<StubClass_> &_stub) { + return (_stub.get()->*(this->getStubFunctor_))(_client); } const OnRemoteSetFunctor onRemoteSetFunctor_; @@ -1018,7 +1090,7 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc template <typename StubClass_, typename AttributeType_, typename AttributeDepl_ = EmptyDeployment> class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_> { - public: +public: typedef typename StubClass_::RemoteEventHandlerType RemoteEventHandlerType; typedef typename StubClass_::StubAdapterType StubAdapterType; typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::LockStubFunctor LockStubFunctor; @@ -1028,43 +1100,44 @@ class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeS typedef typename CommonAPI::Stub<StubAdapterType, typename StubClass_::RemoteEventType> 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<StubClass_, AttributeType_, AttributeDepl_>( - lockStubFunctor, getStubFunctor, dbusSignature, _depl), + _lockStubFunctor, _getStubFunctor, dbusSignature, _isImplemented, _depl), DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>( - 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<StubClass_>& stub, - RemoteEventHandlerType* _remoteEventHandler, - std::weak_ptr<DBusProxyConnection> _connection) { - bool attributeValueChanged; - if (!this->setAttributeValue(dbusMessage, stub, _remoteEventHandler, _connection, attributeValueChanged)) + bool dispatchDBusMessage(const DBusMessage &_message, const std::shared_ptr<StubClass_> &_stub, + RemoteEventHandlerType *_remoteEventHandler, std::weak_ptr<DBusProxyConnection> _connection) { + + if (!this->isImplemented_) + return false; + + bool hasChanged; + if (!this->setAttributeValue(_message, _stub, _remoteEventHandler, _connection, hasChanged)) return false; - if (attributeValueChanged) { - std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender())); - fireAttributeValueChanged(clientId, _remoteEventHandler, stub); + if (hasChanged) { + std::shared_ptr<DBusClientId> itsClient = std::make_shared<DBusClientId>(std::string(_message.getSender())); + fireAttributeValueChanged(itsClient, _remoteEventHandler, _stub); this->notifyOnRemoteChanged(_remoteEventHandler); } return true; } + protected: virtual void fireAttributeValueChanged(std::shared_ptr<CommonAPI::ClientId> _client, - RemoteEventHandlerType* _remoteEventHandler, - const std::shared_ptr<StubClass_> _stub) { + RemoteEventHandlerType *_remoteEventHandler, const std::shared_ptr<StubClass_> _stub) { (void)_remoteEventHandler; - auto stubAdapter = _stub->StubType::getStubAdapter(); (_stub.get()->*DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::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/. |