From d1610ad0d6f1b6751964af41a0cc1599e2d7a955 Mon Sep 17 00:00:00 2001 From: Lutz Bichler Date: Tue, 27 Oct 2020 10:00:57 +0100 Subject: capicxx-dbus-runtime 3.2.0 --- include/CommonAPI/DBus/CommonAPIDBus.hpp | 7 +- include/CommonAPI/DBus/DBusAddress.hpp | 4 +- include/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 +- .../CommonAPI/DBus/DBusFreedesktopAttribute.hpp | 2 +- .../DBus/DBusFreedesktopPropertiesStub.hpp | 2 +- .../DBus/DBusFreedesktopStubAdapterHelper.hpp | 38 ++- include/CommonAPI/DBus/DBusFreedesktopVariant.hpp | 2 +- include/CommonAPI/DBus/DBusFunctionalHash.hpp | 2 +- include/CommonAPI/DBus/DBusHelper.hpp | 12 +- include/CommonAPI/DBus/DBusInputStream.hpp | 68 +++-- .../DBusInstanceAvailabilityStatusChangedEvent.hpp | 2 +- include/CommonAPI/DBus/DBusInterfaceHandler.hpp | 2 +- include/CommonAPI/DBus/DBusMainLoop.hpp | 29 +- include/CommonAPI/DBus/DBusMainLoopContext.hpp | 41 +-- include/CommonAPI/DBus/DBusMessage.hpp | 2 +- include/CommonAPI/DBus/DBusMultiEvent.hpp | 2 +- include/CommonAPI/DBus/DBusObjectManager.hpp | 2 +- include/CommonAPI/DBus/DBusObjectManagerStub.hpp | 2 +- include/CommonAPI/DBus/DBusOutputStream.hpp | 68 +++-- include/CommonAPI/DBus/DBusProxy.hpp | 3 +- .../DBus/DBusProxyAsyncCallbackHandler.hpp | 16 +- .../DBusProxyAsyncSignalMemberCallbackHandler.hpp | 2 +- include/CommonAPI/DBus/DBusProxyBase.hpp | 2 +- include/CommonAPI/DBus/DBusProxyConnection.hpp | 2 +- include/CommonAPI/DBus/DBusProxyHelper.hpp | 74 +++++- include/CommonAPI/DBus/DBusProxyManager.hpp | 2 +- include/CommonAPI/DBus/DBusSelectiveEvent.hpp | 2 +- .../CommonAPI/DBus/DBusSerializableArguments.hpp | 2 +- include/CommonAPI/DBus/DBusServiceRegistry.hpp | 8 +- include/CommonAPI/DBus/DBusStubAdapter.hpp | 2 +- include/CommonAPI/DBus/DBusStubAdapterHelper.hpp | 293 +++++++++++++-------- include/CommonAPI/DBus/DBusTypes.hpp | 2 +- include/CommonAPI/DBus/DBusUtils.hpp | 2 +- 43 files changed, 437 insertions(+), 310 deletions(-) (limited to 'include/CommonAPI') 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 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 @@ public: 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 @@ private: 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 @@ public: std::get<3>(subscription_) = ""; } - template + template inline void handleSignalDBusMessage(const DBusMessage &_message, index_sequence) { DBusInputStream input(_message); if (DBusSerializableArguments< @@ -165,7 +165,7 @@ public: } } - 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 @@ public: 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 @@ public: 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 @@ 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(_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 @@ public: 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 @@ private: _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 @@ private: }; - -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 @@ public: 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 @@ private: 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 @@ private: 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 @@ 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 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 @@ public: private: - template + template inline CallStatus handleDBusMessageReply( const CallStatus _dbusMessageCallStatus, const DBusMessage& _dbusMessage, @@ -208,10 +207,9 @@ private: 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 @@ protected: 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 @@ private: 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 @@ private: return true; } - template + template bool sendReplyInternal(const CommonAPI::CallId_t _call, index_sequence, const std::tuple...>& _args) { @@ -616,6 +650,11 @@ private: 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 @@ private: 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 @@ private: return true; } - template + template bool sendErrorReplyInternal(CommonAPI::CallId_t _call, index_sequence, const std::tuple...>& _args) { @@ -767,6 +809,11 @@ private: 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/. -- cgit v1.2.1