diff options
author | Stefan Laner <laner@itestra.de> | 2014-03-13 14:15:28 +0100 |
---|---|---|
committer | Johannes Langlotz <Johannes.Langlotz@partner.bmw.de> | 2014-03-24 16:46:50 +0100 |
commit | 845303b00a5ca98a83ccfd5be82075fc546b1e89 (patch) | |
tree | 0c876298d22474f17c821f5b6afe756d1a3b97ce | |
parent | b0a9c1d6c6ab78f722a74098080b32881c764784 (diff) | |
download | genivi-common-api-dbus-runtime-845303b00a5ca98a83ccfd5be82075fc546b1e89.tar.gz |
Implemented stub support for org.freedesktop.DBus.Properties
Change-Id: I75abc2e75643ff8da51795787970d55cf4e470c2
62 files changed, 3838 insertions, 388 deletions
diff --git a/CommonAPI-DBus.vcxproj b/CommonAPI-DBus.vcxproj index a4432cd..d039d58 100644 --- a/CommonAPI-DBus.vcxproj +++ b/CommonAPI-DBus.vcxproj @@ -84,6 +84,7 @@ <ClCompile Include="src\CommonAPI\DBus\DBusDaemonProxy.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusError.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusFactory.cpp" />
+ <ClCompile Include="src\CommonAPI\DBus\DBusFreedesktopPropertiesStub.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusFunctionalHash.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusInputStream.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusMainLoopContext.cpp" />
@@ -97,6 +98,7 @@ <ClCompile Include="src\CommonAPI\DBus\DBusRuntime.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusServicePublisher.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusServiceRegistry.cpp" />
+ <ClCompile Include="src\CommonAPI\DBus\DBusServiceStatusEvent.cpp" />
<ClCompile Include="src\CommonAPI\DBus\DBusStubAdapter.cpp" />
<ClCompile Include="src\murmurhash\MurmurHash3.cpp" />
<ClCompile Include="src\pugixml\pugixml.cpp" />
@@ -112,6 +114,7 @@ <ClInclude Include="src\CommonAPI\DBus\DBusError.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusEvent.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusFactory.h" />
+ <ClInclude Include="src\CommonAPI\DBus\DBusFreedesktopPropertiesStub.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusFunctionalHash.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusHelper.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusInputStream.h" />
@@ -135,6 +138,7 @@ <ClInclude Include="src\CommonAPI\DBus\DBusSerializableArguments.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusServicePublisher.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusServiceRegistry.h" />
+ <ClInclude Include="src\CommonAPI\DBus\DBusServiceStatusEvent.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusStubAdapter.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusStubAdapterHelper.h" />
<ClInclude Include="src\CommonAPI\DBus\DBusUtils.h" />
diff --git a/Makefile.am b/Makefile.am index fb3796a..0f692d7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ libCommonAPI_DBus_la_SOURCES = \ src/CommonAPI/DBus/DBusConnection.cpp \ src/CommonAPI/DBus/DBusDaemonProxy.cpp \ src/CommonAPI/DBus/DBusError.cpp \ + src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp \ src/CommonAPI/DBus/DBusFunctionalHash.cpp \ src/CommonAPI/DBus/DBusInputStream.cpp \ src/CommonAPI/DBus/DBusMainLoopContext.cpp \ @@ -90,6 +91,7 @@ CommonAPI_DBus_include_HEADERS = \ src/CommonAPI/DBus/DBusDaemonProxy.h \ src/CommonAPI/DBus/DBusError.h \ src/CommonAPI/DBus/DBusEvent.h \ + src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.h \ src/CommonAPI/DBus/DBusFunctionalHash.h \ src/CommonAPI/DBus/DBusHelper.h \ src/CommonAPI/DBus/DBusInputStream.h \ @@ -149,6 +151,15 @@ TestInterfaceDBusSources = \ src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp \ src/test/fake/legacy/service/LegacyInterfaceDBusProxy.cpp +FreedesktopPropertiesDBusSources = \ + ${TestInterfaceSources} \ + src/test/commonapi/tests/TestFreedesktopInterfaceDBusProxy.cpp \ + src/test/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.cpp \ + src/test/commonapi/tests/TestFreedesktopInterfaceStubDefault.cpp \ + src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.cpp \ + src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.cpp \ + src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.cpp + ManagedSources = \ src/test/commonapi/tests/managed/LeafInterfaceStubDefault.cpp \ src/test/commonapi/tests/managed/BranchInterfaceStubDefault.cpp \ @@ -218,7 +229,8 @@ check_PROGRAMS = \ DBusClientIdTest \ DBusSelectiveBroadcastTest \ DBusPolymorphicTest \ - DBusLoadTest + DBusLoadTest \ + DBusFreedesktopPropertiesTest noinst_PROGRAMS = ${check_PROGRAMS} TESTS = ${check_PROGRAMS} @@ -322,6 +334,13 @@ DBusProxyTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS} DBusProxyTest_CXXFLAGS = ${GTEST_CXXFLAGS} DBusProxyTest_LDADD = ${LDADD_FOR_GTEST} +DBusFreedesktopPropertiesTest_SOURCES = \ + src/test/DBusFreedesktopPropertiesTest.cpp \ + ${FreedesktopPropertiesDBusSources} +DBusFreedesktopPropertiesTest_CPPFLAGS = ${AM_CPPFLAGS} ${GTEST_CPPFLAGS} +DBusFreedesktopPropertiesTest_CXXFLAGS = ${GTEST_CXXFLAGS} +DBusFreedesktopPropertiesTest_LDADD = ${LDADD_FOR_GTEST} + DBusServicePublisherTest_SOURCES = \ src/test/DBusServicePublisherTest.cpp \ ${TestInterfaceDBusSources} diff --git a/UnitTests.vcxproj b/UnitTests.vcxproj index ac46eca..8ba96d0 100644 --- a/UnitTests.vcxproj +++ b/UnitTests.vcxproj @@ -27,6 +27,12 @@ <ClCompile Include="src\test\commonapi\tests\managed\SecondRootDBusProxy.cpp" />
<ClCompile Include="src\test\commonapi\tests\managed\SecondRootDBusStubAdapter.cpp" />
<ClCompile Include="src\test\commonapi\tests\managed\SecondRootStubDefault.cpp" />
+ <ClCompile Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceDBusProxy.cpp" />
+ <ClCompile Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceDBusStubAdapter.cpp" />
+ <ClCompile Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceStubDefault.cpp" />
+ <ClCompile Include="src\test\commonapi\tests\TestFreedesktopInterfaceDBusProxy.cpp" />
+ <ClCompile Include="src\test\commonapi\tests\TestFreedesktopInterfaceDBusStubAdapter.cpp" />
+ <ClCompile Include="src\test\commonapi\tests\TestFreedesktopInterfaceStubDefault.cpp" />
<ClCompile Include="src\test\commonapi\tests\TestInterfaceDBusProxy.cpp" />
<ClCompile Include="src\test\commonapi\tests\TestInterfaceDBusStubAdapter.cpp" />
<ClCompile Include="src\test\commonapi\tests\TestInterfaceStubDefault.cpp" />
@@ -36,6 +42,7 @@ <ClCompile Include="src\test\DBusConnectionTest.cpp" />
<ClCompile Include="src\test\DBusDaemonProxyTest.cpp" />
<ClCompile Include="src\test\DBusFactoryTest.cpp" />
+ <ClCompile Include="src\test\DBusFreedesktopPropertiesTest.cpp" />
<ClCompile Include="src\test\DBusInputStreamTest.cpp" />
<ClCompile Include="src\test\DBusMainLoopIntegrationTest.cpp" />
<ClCompile Include="src\test\DBusManagedTest.cpp" />
@@ -91,6 +98,20 @@ <ClInclude Include="src\test\commonapi\tests\managed\SecondRootStub.h" />
<ClInclude Include="src\test\commonapi\tests\managed\SecondRootStubDefault.h" />
<ClInclude Include="src\test\commonapi\tests\PredefinedTypeCollection.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopDerivedInterface.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceDBusProxy.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceDBusStubAdapter.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceProxy.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceProxyBase.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceStub.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopDerivedInterfaceStubDefault.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopInterface.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopInterfaceDBusProxy.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopInterfaceDBusStubAdapter.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopInterfaceProxy.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopInterfaceProxyBase.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopInterfaceStub.h" />
+ <ClInclude Include="src\test\commonapi\tests\TestFreedesktopInterfaceStubDefault.h" />
<ClInclude Include="src\test\commonapi\tests\TestInterface.h" />
<ClInclude Include="src\test\commonapi\tests\TestInterfaceDBusProxy.h" />
<ClInclude Include="src\test\commonapi\tests\TestInterfaceDBusStubAdapter.h" />
diff --git a/src/CommonAPI/DBus/DBusAttribute.h b/src/CommonAPI/DBus/DBusAttribute.h index adac105..146a190 100644 --- a/src/CommonAPI/DBus/DBusAttribute.h +++ b/src/CommonAPI/DBus/DBusAttribute.h @@ -29,31 +29,31 @@ class DBusProxy; template <typename _AttributeType, typename _DBusProxyType = DBusProxy> class DBusReadonlyAttribute: public _AttributeType { public: - typedef typename _AttributeType::ValueType ValueType; - typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback; + typedef typename _AttributeType::ValueType ValueType; + typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback; - DBusReadonlyAttribute(_DBusProxyType& dbusProxy, const char* setMethodSignature, const char* getMethodName): - dbusProxy_(dbusProxy), - getMethodName_(getMethodName), - setMethodSignature_(setMethodSignature) { - assert(getMethodName); - } + DBusReadonlyAttribute(_DBusProxyType& dbusProxy, const char* setMethodSignature, const char* getMethodName): + dbusProxy_(dbusProxy), + getMethodName_(getMethodName), + setMethodSignature_(setMethodSignature) { + assert(getMethodName); + } - void getValue(CallStatus& callStatus, ValueType& value) const { + void getValue(CallStatus& callStatus, ValueType& value) const { - DBusProxyHelper<DBusSerializableArguments<>, - DBusSerializableArguments<ValueType> >::callMethodWithReply(dbusProxy_, getMethodName_, "", callStatus, value); - } + DBusProxyHelper<DBusSerializableArguments<>, + DBusSerializableArguments<ValueType> >::callMethodWithReply(dbusProxy_, getMethodName_, "", callStatus, value); + } - std::future<CallStatus> getValueAsync(AttributeAsyncCallback attributeAsyncCallback) { - return DBusProxyHelper<DBusSerializableArguments<>, - DBusSerializableArguments<ValueType> >::callMethodAsync(dbusProxy_, getMethodName_, "", std::move(attributeAsyncCallback)); - } + std::future<CallStatus> getValueAsync(AttributeAsyncCallback attributeAsyncCallback) { + return DBusProxyHelper<DBusSerializableArguments<>, + DBusSerializableArguments<ValueType> >::callMethodAsync(dbusProxy_, getMethodName_, "", std::move(attributeAsyncCallback)); + } protected: - _DBusProxyType& dbusProxy_; - const char* getMethodName_; - const char* setMethodSignature_; + _DBusProxyType& dbusProxy_; + const char* getMethodName_; + const char* setMethodSignature_; }; template <typename _AttributeType, typename _DBusProxyType = DBusProxy> @@ -81,8 +81,8 @@ class DBusFreedesktopReadonlyAttribute: public _AttributeType { "org.freedesktop.DBus.Properties", "Get", "ss", - std::string(interfaceName_), - std::string(propertyName_), + interfaceName_, + propertyName_, callStatus, variantVal); value = variantVal.contained_.template get<ValueType>(); @@ -98,8 +98,8 @@ class DBusFreedesktopReadonlyAttribute: public _AttributeType { "org.freedesktop.DBus.Properties", "Get", "ss", - std::string(interfaceName_), - std::string(propertyName_), + interfaceName_, + propertyName_, std::bind( &CommonAPI::DBus::DBusFreedesktopReadonlyAttribute<_AttributeType>::AsyncVariantStripper, this, @@ -116,8 +116,8 @@ class DBusFreedesktopReadonlyAttribute: public _AttributeType { protected: _DBusProxyType& dbusProxy_; - const char* interfaceName_; - const char* propertyName_; + const std::string interfaceName_; + const std::string propertyName_; }; template <typename _AttributeType, typename _DBusProxyType = DBusProxy> @@ -145,8 +145,8 @@ class DBusFreedesktopUnionReadonlyAttribute: public _AttributeType { "org.freedesktop.DBus.Properties", "Get", "ss", - std::string(interfaceName_), - std::string(propertyName_), + interfaceName_, + propertyName_, callStatus, variantVal); value = variantVal.contained_; @@ -161,8 +161,8 @@ class DBusFreedesktopUnionReadonlyAttribute: public _AttributeType { "org.freedesktop.DBus.Properties", "Get", "ss", - std::string(interfaceName_), - std::string(propertyName_), + interfaceName_, + propertyName_, std::bind( &CommonAPI::DBus::DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::AsyncVariantStripper, this, @@ -179,23 +179,23 @@ class DBusFreedesktopUnionReadonlyAttribute: public _AttributeType { protected: _DBusProxyType& dbusProxy_; - const char* interfaceName_; - const char* propertyName_; + const std::string interfaceName_; + const std::string propertyName_; }; template <typename _AttributeType, typename _DBusProxyType = DBusProxy> class DBusAttribute: public DBusReadonlyAttribute<_AttributeType> { public: - typedef typename _AttributeType::ValueType ValueType; - typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback; + typedef typename _AttributeType::ValueType ValueType; + typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback; - DBusAttribute(_DBusProxyType& dbusProxy, const char* setMethodName, const char* setMethodSignature, const char* getMethodName): - DBusReadonlyAttribute<_AttributeType>(dbusProxy, setMethodSignature, getMethodName), - setMethodName_(setMethodName), - setMethodSignature_(setMethodSignature) { - assert(setMethodName); - assert(setMethodSignature); - } + DBusAttribute(_DBusProxyType& dbusProxy, const char* setMethodName, const char* setMethodSignature, const char* getMethodName): + DBusReadonlyAttribute<_AttributeType>(dbusProxy, setMethodSignature, getMethodName), + setMethodName_(setMethodName), + setMethodSignature_(setMethodSignature) { + assert(setMethodName); + assert(setMethodSignature); + } void setValue(const ValueType& requestValue, CallStatus& callStatus, ValueType& responseValue) { DBusProxyHelper<DBusSerializableArguments<ValueType>, @@ -209,19 +209,19 @@ class DBusAttribute: public DBusReadonlyAttribute<_AttributeType> { } - std::future<CallStatus> setValueAsync(const ValueType& requestValue, AttributeAsyncCallback attributeAsyncCallback) { - return DBusProxyHelper<DBusSerializableArguments<ValueType>, - DBusSerializableArguments<ValueType> >::callMethodAsync( - this->dbusProxy_, - setMethodName_, - setMethodSignature_, - requestValue, - attributeAsyncCallback); - } + std::future<CallStatus> setValueAsync(const ValueType& requestValue, AttributeAsyncCallback attributeAsyncCallback) { + return DBusProxyHelper<DBusSerializableArguments<ValueType>, + DBusSerializableArguments<ValueType> >::callMethodAsync( + this->dbusProxy_, + setMethodName_, + setMethodSignature_, + requestValue, + attributeAsyncCallback); + } protected: - const char* setMethodName_; - const char* setMethodSignature_; + const char* setMethodName_; + const char* setMethodSignature_; }; template <typename _AttributeType, typename _DBusProxyType = DBusProxy> @@ -251,8 +251,8 @@ class DBusFreedesktopAttribute: public DBusFreedesktopReadonlyAttribute<_Attribu "org.freedesktop.DBus.Properties", "Set", "ssv", - std::string(DBusFreedesktopReadonlyAttribute<_AttributeType>::interfaceName_), - std::string(DBusFreedesktopReadonlyAttribute<_AttributeType>::propertyName_), + DBusFreedesktopReadonlyAttribute<_AttributeType>::interfaceName_, + DBusFreedesktopReadonlyAttribute<_AttributeType>::propertyName_, variantVal, callStatus); responseValue = requestValue; @@ -269,8 +269,8 @@ class DBusFreedesktopAttribute: public DBusFreedesktopReadonlyAttribute<_Attribu "org.freedesktop.DBus.Properties", "Set", "ssv", - std::string(DBusFreedesktopReadonlyAttribute<_AttributeType>::interfaceName_), - std::string(DBusFreedesktopReadonlyAttribute<_AttributeType>::propertyName_), + DBusFreedesktopReadonlyAttribute<_AttributeType>::interfaceName_, + DBusFreedesktopReadonlyAttribute<_AttributeType>::propertyName_, variantVal, std::bind( &CommonAPI::DBus::DBusFreedesktopAttribute<_AttributeType>::AsyncVariantStripper, @@ -314,8 +314,8 @@ class DBusFreedesktopUnionAttribute: public DBusFreedesktopUnionReadonlyAttribut "org.freedesktop.DBus.Properties", "Set", "ssv", - std::string(DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::interfaceName_), - std::string(DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::propertyName_), + DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::interfaceName_, + DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::propertyName_, variantVal, callStatus); responseValue = requestValue; @@ -332,8 +332,8 @@ class DBusFreedesktopUnionAttribute: public DBusFreedesktopUnionReadonlyAttribut "org.freedesktop.DBus.Properties", "Set", "ssv", - std::string(DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::interfaceName_), - std::string(DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::propertyName_), + DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::interfaceName_, + DBusFreedesktopUnionReadonlyAttribute<_AttributeType>::propertyName_, variantVal, std::bind( &CommonAPI::DBus::DBusFreedesktopUnionAttribute<_AttributeType>::AsyncVariantStripper, @@ -353,22 +353,22 @@ class DBusFreedesktopUnionAttribute: public DBusFreedesktopUnionReadonlyAttribut template <typename _AttributeType, typename _DBusProxyType = DBusProxy> class DBusObservableAttribute: public _AttributeType { public: - typedef typename _AttributeType::ValueType ValueType; - typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback; - typedef typename _AttributeType::ChangedEvent ChangedEvent; + typedef typename _AttributeType::ValueType ValueType; + typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback; + typedef typename _AttributeType::ChangedEvent ChangedEvent; - template <typename... _AttributeTypeArguments> - DBusObservableAttribute(_DBusProxyType& dbusProxy, const char* changedEventName, _AttributeTypeArguments... arguments): - _AttributeType(dbusProxy, arguments...), - changedEvent_(dbusProxy, changedEventName, this->setMethodSignature_) { - } + template <typename... _AttributeTypeArguments> + DBusObservableAttribute(_DBusProxyType& dbusProxy, const char* changedEventName, _AttributeTypeArguments... arguments): + _AttributeType(dbusProxy, arguments...), + changedEvent_(dbusProxy, changedEventName, this->setMethodSignature_) { + } - ChangedEvent& getChangedEvent() { - return changedEvent_; - } + ChangedEvent& getChangedEvent() { + return changedEvent_; + } protected: - DBusEvent<ChangedEvent> changedEvent_; + DBusEvent<ChangedEvent> changedEvent_; }; template< class, class > @@ -392,8 +392,8 @@ protected: void onInternalEvent(const std::string& interfaceName, const std::unordered_map<std::string, DBusLegacyVariantWrapper<Variant<_Types> > >& props, const std::vector<std::string>& invalid) { - if (std::string(interfaceName_) == interfaceName) { - auto mapIter = props.find(std::string(propertyName_)); + if (interfaceName_ == interfaceName) { + auto mapIter = props.find(propertyName_); if (mapIter != props.end()) { notifyListeners(mapIter->second.contained_.template get<ValueType>()); } @@ -423,15 +423,13 @@ protected: typedef std::vector<std::string> InvalidArray; typedef Event<std::string, PropertyMap, InvalidArray> SignalEvent; - DBusEvent<SignalEvent> internalEvent_; typename DBusEvent<SignalEvent>::Subscription sub; - const char* interfaceName_; - const char* propertyName_; - + const std::string interfaceName_; + const std::string propertyName_; bool subSet_; - + DBusEvent<SignalEvent> internalEvent_; }; template <typename _AttributeType, typename _DBusProxyType = DBusProxy> @@ -447,10 +445,7 @@ class DBusFreedesktopObservableAttribute: public _AttributeType { const char* propertyName, _AttributeTypeArguments... arguments): _AttributeType(dbusProxy, interfaceName, propertyName, arguments...), - propertyName_(propertyName), - interfaceName_(interfaceName), externalChangedEvent_(dbusProxy, interfaceName, propertyName) { - } ChangedEvent& getChangedEvent() { @@ -459,8 +454,6 @@ class DBusFreedesktopObservableAttribute: public _AttributeType { protected: LegacyEvent<ChangedEvent, _DBusProxyType> externalChangedEvent_; - const char * propertyName_; - const char * interfaceName_; }; template< class, class > @@ -484,8 +477,8 @@ protected: void onInternalEvent(const std::string& interfaceName, const std::unordered_map<std::string, DBusLegacyVariantWrapper<ValueType> >& props, const std::vector<std::string>& invalid) { - if (std::string(interfaceName_) == interfaceName) { - auto mapIter = props.find(std::string(propertyName_)); + if (interfaceName_ == interfaceName) { + auto mapIter = props.find(propertyName_); if (mapIter != props.end()) { notifyListeners(mapIter->second.contained_); } @@ -519,8 +512,8 @@ protected: typename DBusEvent<SignalEvent>::Subscription sub; - const char* interfaceName_; - const char* propertyName_; + const std::string interfaceName_; + const std::string propertyName_; bool subSet_; @@ -539,10 +532,7 @@ class DBusFreedesktopUnionObservableAttribute: public _AttributeType { const char* propertyName, _AttributeTypeArguments... arguments): _AttributeType(dbusProxy, interfaceName, propertyName, arguments...), - propertyName_(propertyName), - interfaceName_(interfaceName), externalChangedEvent_(dbusProxy, interfaceName, propertyName) { - } ChangedEvent& getChangedEvent() { @@ -551,8 +541,6 @@ class DBusFreedesktopUnionObservableAttribute: public _AttributeType { protected: LegacyUnionEvent<ChangedEvent, _DBusProxyType> externalChangedEvent_; - const char * propertyName_; - const char * interfaceName_; }; } // namespace DBus diff --git a/src/CommonAPI/DBus/DBusEvent.h b/src/CommonAPI/DBus/DBusEvent.h index ecd8735..7b43ba2 100644 --- a/src/CommonAPI/DBus/DBusEvent.h +++ b/src/CommonAPI/DBus/DBusEvent.h @@ -98,8 +98,8 @@ class DBusEvent: public _EventType, public DBusProxyConnection::DBusSignalHandle _DBusProxy& dbusProxy_; const char* eventName_; const char* eventSignature_; - const char* interfaceName_; const char* objectPath_; + const char* interfaceName_; DBusProxyConnection::DBusSignalHandlerToken subscription_; }; diff --git a/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp b/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp new file mode 100644 index 0000000..9823af5 --- /dev/null +++ b/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.cpp @@ -0,0 +1,110 @@ +/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * 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/. */ +#include "DBusFreedesktopPropertiesStub.h" +#include "DBusStubAdapter.h" +#include "DBusServicePublisher.h" +#include "DBusOutputStream.h" +#include "DBusInputStream.h" + +#include <cassert> +#include <vector> + +namespace CommonAPI { +namespace DBus { + +DBusFreedesktopPropertiesStub::DBusFreedesktopPropertiesStub(const std::string& dbusObjectPath, + const std::string& dbusInterfaceName, + const std::shared_ptr<DBusProxyConnection>& dbusConnection, + const std::shared_ptr<DBusStubAdapter>& dbusStubAdapter) : + dbusObjectPath_(dbusObjectPath), + dbusConnection_(dbusConnection), + dbusStubAdapter_(dbusStubAdapter) { + assert(!dbusObjectPath.empty()); + assert(dbusObjectPath[0] == '/'); + assert(dbusConnection); + + dbusInterfacesLock_.lock(); + if(managedInterfaces_.find(dbusInterfaceName) == managedInterfaces_.end()) { + managedInterfaces_.insert({dbusInterfaceName, dbusStubAdapter}); + } + dbusInterfacesLock_.unlock(); + +} + +DBusFreedesktopPropertiesStub::~DBusFreedesktopPropertiesStub() { + // TODO: maybee some deregistration etc. +} + +const char* DBusFreedesktopPropertiesStub::getMethodsDBusIntrospectionXmlData() const { + return "<interface name=\"org.freedesktop.DBus.Properties\">\n" + "<method name=\"Get\">\n" + "<arg type=\"s\" name=\"interface_name\" direction=\"in\"/>\n" + "<arg type=\"s\" name=\"property_name\" direction=\"in\"/>\n" + "<arg type=\"v\" name=\"value\" direction=\"out\"/>\n" + "</method>\n" + "<method name=\"GetAll\">\n" + "<arg type=\"s\" name=\"interface_name\" direction=\"in\"/>\n" + "<arg type=\"a{sv}\" name=\"properties\" direction=\"out\"/>\n" + "</method>\n" + "<method name=\"Set\">\n" + "<arg type=\"s\" name=\"interface_name\" direction=\"in\"/>\n" + "<arg type=\"s\" name=\"property_name\" direction=\"in\"/>\n" + "<arg type=\"v\" name=\"value\" direction=\"in\"/>\n" + "</method>\n" + "<signal name=\"PropertiesChanged\">\n" + "<arg type=\"s\" name=\"interface_name\"/>\n" + "<arg type=\"a{sv}\" name=\"changed_properties\"/>\n" + "<arg type=\"as\" name=\"invalidated_properties\"/>\n" + "</signal>\n" + "</interface>\n"; +} + +bool DBusFreedesktopPropertiesStub::onInterfaceDBusMessage(const DBusMessage& dbusMessage) { + auto dbusConnection = dbusConnection_.lock(); + + if (!dbusConnection || !dbusConnection->isConnected()) { + return false; + } + + if (!dbusMessage.isMethodCallType() || !(dbusMessage.hasMemberName("Get") || dbusMessage.hasMemberName("GetAll") || dbusMessage.hasMemberName("Set"))) { + return false; + } + + DBusInputStream dbusInputStream(dbusMessage); + std::string interfaceName; + + dbusInputStream >> interfaceName; + + if(dbusInputStream.hasError()) { + return false; + } + + std::lock_guard<std::mutex> dbusInterfacesLock(dbusInterfacesLock_); + + auto managedInterfacesIterator = managedInterfaces_.find(interfaceName); + + if(managedInterfacesIterator == managedInterfaces_.end()) { + return false; + } + + return managedInterfacesIterator->second->onInterfaceDBusFreedesktopPropertiesMessage(dbusMessage); +} + +const bool DBusFreedesktopPropertiesStub::hasFreedesktopProperties() { + return false; +} + +const std::string& DBusFreedesktopPropertiesStub::getDBusObjectPath() const { + return dbusObjectPath_; +} + +const char* DBusFreedesktopPropertiesStub::getInterfaceName() { + return "org.freedesktop.DBus.Properties"; +} + +} // namespace DBus +} // namespace CommonAPI diff --git a/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.h b/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.h new file mode 100644 index 0000000..c6b38a0 --- /dev/null +++ b/src/CommonAPI/DBus/DBusFreedesktopPropertiesStub.h @@ -0,0 +1,60 @@ +/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * 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/. */ + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#error "Only <CommonAPI/CommonAPI.h> can be included directly, this file may disappear or change contents." +#endif + +#ifndef COMMONAPI_DBUS_DBUS_FREEDESKTOP_PROPERTIES_STUB_H_ +#define COMMONAPI_DBUS_DBUS_FREEDESKTOP_PROPERTIES_STUB_H_ + +#include "DBusInterfaceHandler.h" + +#include <memory> +#include <mutex> +#include <string> + +namespace CommonAPI { +namespace DBus { + +class DBusStubAdapter; + +/** + * Stub for standard <a href="http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">org.freedesktop.dbus.Properties</a> interface. + * + * DBusFreedesktopPropertiesStub gets the DBusStubAdapter for handling the actual properties with instantiation. + */ +class DBusFreedesktopPropertiesStub: public DBusInterfaceHandler { +public: + DBusFreedesktopPropertiesStub(const std::string& dbusObjectPath, + const std::string& dbusInterfaceName, + const std::shared_ptr<DBusProxyConnection>&, + const std::shared_ptr<DBusStubAdapter>& dbusStubAdapter); + + virtual ~DBusFreedesktopPropertiesStub(); + + const std::string& getDBusObjectPath() const; + static const char* getInterfaceName(); + + virtual const char* getMethodsDBusIntrospectionXmlData() const; + virtual bool onInterfaceDBusMessage(const DBusMessage& dbusMessage); + virtual const bool hasFreedesktopProperties(); +private: + std::string dbusObjectPath_; + std::weak_ptr<DBusProxyConnection> dbusConnection_; + std::shared_ptr<DBusStubAdapter> dbusStubAdapter_; + + typedef std::unordered_map<std::string, std::shared_ptr<DBusStubAdapter>> DBusInterfacesMap; + DBusInterfacesMap managedInterfaces_; + + std::mutex dbusInterfacesLock_; +}; + +} // namespace DBus +} // namespace CommonAPI + +#endif // COMMONAPI_DBUS_DBUS_FREEDESKTOP_PROPERTIES_STUB_H_ diff --git a/src/CommonAPI/DBus/DBusFunctionalHash.cpp b/src/CommonAPI/DBus/DBusFunctionalHash.cpp index bdc5daf..a3a334a 100644 --- a/src/CommonAPI/DBus/DBusFunctionalHash.cpp +++ b/src/CommonAPI/DBus/DBusFunctionalHash.cpp @@ -11,56 +11,58 @@ #include <cassert> #include <cstring> - /* * @see http://code.google.com/p/smhasher/ */ #define SMHASHER_SEED_VALUE 0xc70f6907UL - namespace std { -size_t hash< pair<const char*, const char*> >::operator()(const pair<const char*, const char*>& t) const { - const char* a = t.first; - const char* b = t.second; +size_t hash<pair<const char*, const char*> >::operator()(const pair<const char*, const char*>& t) const { + const char* a = t.first; + const char* b = t.second; - assert(a); - assert(b); + assert(a); + assert(b); - uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); - MurmurHash3_x86_32(a, strlen(a), seed, &seed); - MurmurHash3_x86_32(b, strlen(b), seed, &seed); + uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); + MurmurHash3_x86_32(a, strlen(a), seed, &seed); + MurmurHash3_x86_32(b, strlen(b), seed, &seed); - return static_cast<size_t>(seed); + return static_cast<size_t>(seed); } +size_t hash<const char*>::operator()(const char* const t) const { + uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); + MurmurHash3_x86_32(t, strlen(t), seed, &seed); + return static_cast<size_t>(seed); +} -size_t hash< pair<string, string> >::operator()(const pair<string, string>& t) const { - const string& a = t.first; - const string& b = t.second; +size_t hash<pair<string, string> >::operator()(const pair<string, string>& t) const { + const string& a = t.first; + const string& b = t.second; - uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); - MurmurHash3_x86_32(a.c_str(), a.length(), seed, &seed); - MurmurHash3_x86_32(b.c_str(), b.length(), seed, &seed); + uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); + MurmurHash3_x86_32(a.c_str(), a.length(), seed, &seed); + MurmurHash3_x86_32(b.c_str(), b.length(), seed, &seed); - return static_cast<size_t>(seed); + return static_cast<size_t>(seed); } +size_t hash<tuple<string, string, string> >::operator()(const tuple<string, string, string>& t) const { + const string& a = get<0>(t); + const string& b = get<1>(t); + const string& c = get<2>(t); -size_t hash< tuple<string, string, string> >::operator()(const tuple<string, string, string>& t) const { - const string& a = get<0>(t); - const string& b = get<1>(t); - const string& c = get<2>(t); - - uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); - MurmurHash3_x86_32(a.c_str(), a.length(), seed, &seed); - MurmurHash3_x86_32(b.c_str(), b.length(), seed, &seed); - MurmurHash3_x86_32(c.c_str(), c.length(), seed, &seed); + uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); + MurmurHash3_x86_32(a.c_str(), a.length(), seed, &seed); + MurmurHash3_x86_32(b.c_str(), b.length(), seed, &seed); + MurmurHash3_x86_32(c.c_str(), c.length(), seed, &seed); - return static_cast<size_t>(seed); + return static_cast<size_t>(seed); } -size_t hash< tuple<string, string, string, bool> >::operator()(const tuple<string, string, string, bool>& t) const { +size_t hash<tuple<string, string, string, bool> >::operator()(const tuple<string, string, string, bool>& t) const { const string& a = get<0>(t); const string& b = get<1>(t); const string& c = get<2>(t); @@ -75,7 +77,7 @@ size_t hash< tuple<string, string, string, bool> >::operator()(const tuple<strin return static_cast<size_t>(seed); } -size_t hash< tuple<string, string, string, int> >::operator()(const tuple<string, string, string, int>& t) const { +size_t hash<tuple<string, string, string, int> >::operator()(const tuple<string, string, string, int>& t) const { const string& a = get<0>(t); const string& b = get<1>(t); const string& c = get<2>(t); @@ -90,29 +92,27 @@ size_t hash< tuple<string, string, string, int> >::operator()(const tuple<string return static_cast<size_t>(seed); } +size_t hash<tuple<string, string, string, string> >::operator()(const tuple<string, string, string, string>& t) const { + const string& a = get<0>(t); + const string& b = get<1>(t); + const string& c = get<2>(t); + const string& d = get<3>(t); -size_t hash< tuple<string, string, string, string> >::operator()(const tuple<string, string, string, string>& t) const { - const string& a = get<0>(t); - const string& b = get<1>(t); - const string& c = get<2>(t); - const string& d = get<3>(t); - - uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); - MurmurHash3_x86_32(a.c_str(), a.length(), seed, &seed); - MurmurHash3_x86_32(b.c_str(), b.length(), seed, &seed); - MurmurHash3_x86_32(c.c_str(), c.length(), seed, &seed); - MurmurHash3_x86_32(d.c_str(), d.length(), seed, &seed); + uint32_t seed = static_cast<uint32_t>(SMHASHER_SEED_VALUE); + MurmurHash3_x86_32(a.c_str(), a.length(), seed, &seed); + MurmurHash3_x86_32(b.c_str(), b.length(), seed, &seed); + MurmurHash3_x86_32(c.c_str(), c.length(), seed, &seed); + MurmurHash3_x86_32(d.c_str(), d.length(), seed, &seed); - return static_cast<size_t>(seed); + return static_cast<size_t>(seed); } +bool equal_to<pair<const char*, const char*> >::operator()(const pair<const char*, const char*>& a, + const pair<const char*, const char*>& b) const { + if (a.first == b.first && a.second == b.second) + return true; -bool equal_to< pair<const char*, const char*> >::operator()(const pair<const char*, const char*>& a, - const pair<const char*, const char*>& b) const { - if (a.first == b.first && a.second == b.second) - return true; - - return !strcmp(a.first, b.first) && !strcmp(a.second, b.second); + return !strcmp(a.first, b.first) && !strcmp(a.second, b.second); } } // namespace std diff --git a/src/CommonAPI/DBus/DBusFunctionalHash.h b/src/CommonAPI/DBus/DBusFunctionalHash.h index 2e81ae1..7ffec89 100644 --- a/src/CommonAPI/DBus/DBusFunctionalHash.h +++ b/src/CommonAPI/DBus/DBusFunctionalHash.h @@ -19,26 +19,31 @@ namespace std { template<> -struct hash< pair<const char*, const char*> >: - public unary_function< pair<const char*, const char*>, size_t > { +struct hash<pair<const char*, const char*> > : + public unary_function<pair<const char*, const char*>, size_t> { - size_t operator()(const pair<const char*, const char*>& t) const; + size_t operator()(const pair<const char*, const char*>& t) const; }; - template<> -struct hash< pair<string, string> >: - public unary_function< pair<string, string>, size_t > { +struct hash<const char*> : + public unary_function<const char*, size_t> { - size_t operator()(const pair<string, string>& t) const; + size_t operator()(const char* const t) const; }; +template<> +struct hash<pair<string, string> > : + public unary_function<pair<string, string>, size_t> { + + size_t operator()(const pair<string, string>& t) const; +}; template<> -struct hash< tuple<string, string, string> >: - public unary_function< tuple<string, string, string>, size_t > { +struct hash<tuple<string, string, string> > : + public unary_function<tuple<string, string, string>, size_t> { - size_t operator()(const tuple<string, string, string>& t) const; + size_t operator()(const tuple<string, string, string>& t) const; }; template<> diff --git a/src/CommonAPI/DBus/DBusInterfaceHandler.h b/src/CommonAPI/DBus/DBusInterfaceHandler.h index 92b65fa..1ee2cb1 100644 --- a/src/CommonAPI/DBus/DBusInterfaceHandler.h +++ b/src/CommonAPI/DBus/DBusInterfaceHandler.h @@ -22,6 +22,8 @@ class DBusInterfaceHandler { virtual const char* getMethodsDBusIntrospectionXmlData() const = 0; virtual bool onInterfaceDBusMessage(const DBusMessage& dbusMessage) = 0; + + virtual const bool hasFreedesktopProperties() = 0; }; } // namespace dbus diff --git a/src/CommonAPI/DBus/DBusLegacyVariant.h b/src/CommonAPI/DBus/DBusLegacyVariant.h index 0ac9df6..ec3b5c9 100644 --- a/src/CommonAPI/DBus/DBusLegacyVariant.h +++ b/src/CommonAPI/DBus/DBusLegacyVariant.h @@ -43,7 +43,11 @@ struct ApplyIndexForStringVisitor<Visitor, Variant, _Type, _Types...> { DBusTypeOutputStream typeStream_; TypeWriter<_Type>::writeType(typeStream_); const std::string sig = typeStream_.retrieveSignature(); +#ifdef WIN32 + if (visitor.operator()<_Type>(sig)) { +#else if (visitor.template operator()<_Type>(sig)) { +#endif return index; } else { return ApplyIndexForStringVisitor<Visitor, Variant, _Types...>::visit(visitor, diff --git a/src/CommonAPI/DBus/DBusObjectManager.cpp b/src/CommonAPI/DBus/DBusObjectManager.cpp index 2feff75..df43bf0 100644 --- a/src/CommonAPI/DBus/DBusObjectManager.cpp +++ b/src/CommonAPI/DBus/DBusObjectManager.cpp @@ -10,6 +10,8 @@ #include "DBusOutputStream.h" #include "DBusUtils.h" +#include "DBusFreedesktopPropertiesStub.h" + #include <CommonAPI/utils.h> #include <dbus/dbus-protocol.h> @@ -54,6 +56,20 @@ bool DBusObjectManager::registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter> objectPathLock_.lock(); isRegistrationSuccessful = addDBusInterfaceHandler(dbusStubAdapterHandlerPath, dbusStubAdapter); + if(isRegistrationSuccessful && dbusStubAdapter->hasFreedesktopProperties()) { + const std::shared_ptr<DBusFreedesktopPropertiesStub> dbusFreedesktopPropertiesStub = + std::make_shared<DBusFreedesktopPropertiesStub>(dbusStubAdapterObjectPath, + dbusStubAdapterInterfaceName, + dbusStubAdapter->getDBusConnection(), + dbusStubAdapter); + isRegistrationSuccessful = isRegistrationSuccessful + && addDBusInterfaceHandler( + {dbusFreedesktopPropertiesStub->getDBusObjectPath(), + dbusFreedesktopPropertiesStub->getInterfaceName() + }, + dbusFreedesktopPropertiesStub); + } + if (isRegistrationSuccessful && dbusStubAdapter->isManagingInterface()) { auto managerStubIterator = managerStubs_.find(dbusStubAdapterObjectPath); const bool managerStubExists = managerStubIterator != managerStubs_.end(); @@ -252,7 +268,6 @@ bool DBusObjectManager::onIntrospectableInterfaceDBusMessage(const DBusMessage& << dbusStubAdapterBase->getMethodsDBusIntrospectionXmlData() << "\n" "</interface>\n"; nodeSet.insert(elems.back()); - //break; } else { if (dbusMessage.hasObjectPath("/") && elems.size() > 1) { if (nodeSet.find(elems[1]) == nodeSet.end()) { diff --git a/src/CommonAPI/DBus/DBusObjectManager.h b/src/CommonAPI/DBus/DBusObjectManager.h index db63e3e..6ce6e6c 100644 --- a/src/CommonAPI/DBus/DBusObjectManager.h +++ b/src/CommonAPI/DBus/DBusObjectManager.h @@ -50,6 +50,8 @@ class DBusObjectManager { std::shared_ptr<DBusInterfaceHandler> dbusInterfaceHandler); bool onIntrospectableInterfaceDBusMessage(const DBusMessage& callMessage); + bool onFreedesktopPropertiesDBusMessage(const DBusMessage& callMessage); + typedef std::unordered_map<DBusInterfaceHandlerPath, std::shared_ptr<DBusInterfaceHandler>> DBusRegisteredObjectsTable; DBusRegisteredObjectsTable dbusRegisteredObjectsTable_; diff --git a/src/CommonAPI/DBus/DBusObjectManagerStub.cpp b/src/CommonAPI/DBus/DBusObjectManagerStub.cpp index 7c2237e..970f366 100644 --- a/src/CommonAPI/DBus/DBusObjectManagerStub.cpp +++ b/src/CommonAPI/DBus/DBusObjectManagerStub.cpp @@ -186,6 +186,10 @@ bool DBusObjectManagerStub::emitInterfacesAddedSignal(std::shared_ptr<DBusStubAd dbusInterfacesAndPropertiesDict.insert({ getInterfaceName(), DBusPropertiesChangedDict() }); } + if (dbusStubAdapter->hasFreedesktopProperties()) { + dbusInterfacesAndPropertiesDict.insert({ "org.freedesktop.DBus.Properties", DBusPropertiesChangedDict() }); + } + dbusOutputStream << dbusStubObjectPath; dbusOutputStream << dbusInterfacesAndPropertiesDict; dbusOutputStream.flush(); @@ -280,6 +284,10 @@ bool DBusObjectManagerStub::onInterfaceDBusMessage(const DBusMessage& dbusMessag } +const bool DBusObjectManagerStub::hasFreedesktopProperties() { + return false; +} + const std::string& DBusObjectManagerStub::getDBusObjectPath() const { return dbusObjectPath_; } diff --git a/src/CommonAPI/DBus/DBusObjectManagerStub.h b/src/CommonAPI/DBus/DBusObjectManagerStub.h index 8a990ab..7de54f2 100644 --- a/src/CommonAPI/DBus/DBusObjectManagerStub.h +++ b/src/CommonAPI/DBus/DBusObjectManagerStub.h @@ -99,6 +99,7 @@ class DBusObjectManagerStub: public DBusInterfaceHandler { virtual const char* getMethodsDBusIntrospectionXmlData() const; virtual bool onInterfaceDBusMessage(const DBusMessage& dbusMessage); + virtual const bool hasFreedesktopProperties(); private: bool registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter); diff --git a/src/CommonAPI/DBus/DBusOutputStream.h b/src/CommonAPI/DBus/DBusOutputStream.h index 49b7ccd..51e5f2f 100644 --- a/src/CommonAPI/DBus/DBusOutputStream.h +++ b/src/CommonAPI/DBus/DBusOutputStream.h @@ -133,6 +133,10 @@ public: signature_.append("(yv)"); } + void writeLegacyVariantType() { + signature_.append("v"); + } + virtual std::string retrieveSignature() { return std::move(signature_); } diff --git a/src/CommonAPI/DBus/DBusStubAdapter.cpp b/src/CommonAPI/DBus/DBusStubAdapter.cpp index 6b97c0b..a27bf40 100644 --- a/src/CommonAPI/DBus/DBusStubAdapter.cpp +++ b/src/CommonAPI/DBus/DBusStubAdapter.cpp @@ -69,6 +69,10 @@ const std::string& DBusStubAdapter::getInstanceId() const { return commonApiParticipantId_; } +const bool DBusStubAdapter::hasFreedesktopProperties() { + return false; +} + const bool DBusStubAdapter::isManagingInterface() { return isManagingInterface_; } diff --git a/src/CommonAPI/DBus/DBusStubAdapter.h b/src/CommonAPI/DBus/DBusStubAdapter.h index fa7a377..3b6bfb6 100644 --- a/src/CommonAPI/DBus/DBusStubAdapter.h +++ b/src/CommonAPI/DBus/DBusStubAdapter.h @@ -59,7 +59,8 @@ class DBusStubAdapter: virtual public CommonAPI::StubAdapter, public DBusInterfa virtual bool onInterfaceDBusMessage(const DBusMessage& dbusMessage) = 0; virtual void deactivateManagedInstances() = 0; - + virtual const bool hasFreedesktopProperties(); + virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const DBusMessage& dbusMessage) = 0; protected: const std::string commonApiDomain_; diff --git a/src/CommonAPI/DBus/DBusStubAdapterHelper.h b/src/CommonAPI/DBus/DBusStubAdapterHelper.h index e2cbd13..dbac232 100644 --- a/src/CommonAPI/DBus/DBusStubAdapterHelper.h +++ b/src/CommonAPI/DBus/DBusStubAdapterHelper.h @@ -12,12 +12,15 @@ #ifndef COMMONAPI_DBUS_DBUS_STUB_ADAPTER_HELPER_H_ #define COMMONAPI_DBUS_DBUS_STUB_ADAPTER_HELPER_H_ +#include <CommonAPI/SerializableVariant.h> + #include "DBusStubAdapter.h" #include "DBusInputStream.h" #include "DBusOutputStream.h" #include "DBusHelper.h" #include "DBusSerializableArguments.h" #include "DBusClientId.h" +#include "DBusLegacyVariant.h" #include <memory> #include <initializer_list> @@ -33,6 +36,21 @@ public: }; template <typename _StubClass> +class DBusGetFreedesktopAttributeStubDispatcherBase; + +struct DBusAttributeDispatcherStruct { + StubDispatcherBase* getter; + StubDispatcherBase* setter; + + DBusAttributeDispatcherStruct(StubDispatcherBase* g, StubDispatcherBase* s) { + getter = g; + setter = s; + } +}; + +typedef std::unordered_map<std::string, DBusAttributeDispatcherStruct> StubAttributeTable; + +template <typename _StubClass> class DBusStubAdapterHelper: public virtual DBusStubAdapter { public: typedef typename _StubClass::StubAdapterType StubAdapterType; @@ -57,7 +75,8 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter { const std::shared_ptr<_StubClass>& stub, const bool isManagingInterface): DBusStubAdapter(factory, commonApiAddress, dbusInterfaceName, dbusBusName, dbusObjectPath, dbusConnection, isManagingInterface), - stub_(stub) { + stub_(stub), + remoteEventHandler_(NULL) { } virtual ~DBusStubAdapterHelper() { @@ -104,10 +123,118 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter { return dbusMessageHandled; } + virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const DBusMessage& dbusMessage) { + DBusInputStream dbusInputStream(dbusMessage); + + if(dbusMessage.hasMemberName("Get")) { + return handleFreedesktopGet(dbusMessage, dbusInputStream); + } else if(dbusMessage.hasMemberName("Set")) { + return handleFreedesktopSet(dbusMessage, dbusInputStream); + } else if(dbusMessage.hasMemberName("GetAll")) { + return handleFreedesktopGetAll(dbusMessage, dbusInputStream); + } + + return false; + } + virtual const StubDispatcherTable& getStubDispatcherTable() = 0; + virtual const StubAttributeTable& getStubAttributeTable() = 0; std::weak_ptr<_StubClass> stub_; RemoteEventHandlerType* remoteEventHandler_; + private: + bool handleFreedesktopGet(const DBusMessage& dbusMessage, DBusInputStream& dbusInputStream) { + std::string interfaceName; + std::string attributeName; + dbusInputStream >> interfaceName; + dbusInputStream >> attributeName; + + if (dbusInputStream.hasError()) { + return false; + } + + auto attributeDispatcherIterator = getStubAttributeTable().find(attributeName); + // check, if we want to access with a valid attribute name + if (attributeDispatcherIterator == getStubAttributeTable().end()) { + return false; + } + + //To prevent the destruction of the stub whilst still handling a message + auto stubSafety = stub_.lock(); + if (stubSafety) { + StubDispatcher* getterDispatcher = static_cast<StubDispatcher*>(attributeDispatcherIterator->second.getter); + assert(getterDispatcher != NULL); // all attributes have at least a getter + return (getterDispatcher->dispatchDBusMessage(dbusMessage, stubSafety, *this)); + } + + return false; + } + + bool handleFreedesktopSet(const DBusMessage& dbusMessage, DBusInputStream& dbusInputStream) { + std::string interfaceName; + std::string attributeName; + dbusInputStream >> interfaceName; + dbusInputStream >> attributeName; + + if(dbusInputStream.hasError()) { + return false; + } + + auto attributeDispatcherIterator = getStubAttributeTable().find(attributeName); + // check, if we want to access with a valid attribute name + if(attributeDispatcherIterator == getStubAttributeTable().end()) { + return false; + } + + //To prevent the destruction of the stub whilst still handling a message + auto stubSafety = stub_.lock(); + if (stubSafety) { + StubDispatcher* setterDispatcher = static_cast<StubDispatcher*>(attributeDispatcherIterator->second.setter); + + if(setterDispatcher == NULL) { // readonly attributes do not have a setter + return false; + } + + return(setterDispatcher->dispatchDBusMessage(dbusMessage, stubSafety, *this)); + } + + return false; + } + + bool handleFreedesktopGetAll(const DBusMessage& dbusMessage, DBusInputStream& dbusInputStream) { + std::string interfaceName; + dbusInputStream >> interfaceName; + + if(dbusInputStream.hasError()) { + return false; + } + + DBusMessage dbusMessageReply = dbusMessage.createMethodReturn("a{sv}"); + DBusOutputStream dbusOutputStream(dbusMessageReply); + dbusOutputStream.beginWriteVectorOfSerializableStructs(getStubAttributeTable().size()); + + std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSenderName())); + + auto stubSafety = stub_.lock(); + + for(auto attributeDispatcherIterator = getStubAttributeTable().begin(); attributeDispatcherIterator != getStubAttributeTable().end(); attributeDispatcherIterator++) { + //To prevent the destruction of the stub whilst still handling a message + if (stubSafety) { + DBusGetFreedesktopAttributeStubDispatcherBase<_StubClass>* const getterDispatcher = dynamic_cast<DBusGetFreedesktopAttributeStubDispatcherBase<_StubClass>*>(attributeDispatcherIterator->second.getter); + + if(getterDispatcher == NULL) { // readonly attributes do not have a setter + return false; + } + + dbusOutputStream << attributeDispatcherIterator->first; + getterDispatcher->dispatchDBusMessageAndAppendReply(dbusMessage, stubSafety, dbusOutputStream, clientId); + } + } + + dbusOutputStream.endWriteVector(); + dbusOutputStream.flush(); + return getDBusConnection()->sendDBusMessage(dbusMessageReply); + } }; template< class > @@ -115,14 +242,16 @@ struct DBusStubSignalHelper; template<template<class ...> class _In, class... _InArgs> struct DBusStubSignalHelper<_In<_InArgs...>> { - template <typename _DBusStub = DBusStubAdapter> - static bool sendSignal(const _DBusStub& dbusStub, + + static inline bool sendSignal(const char* objectPath, + const char* interfaceName, const char* signalName, const char* signalSignature, + const std::shared_ptr<DBusProxyConnection>& dbusConnection, const _InArgs&... inArgs) { DBusMessage dbusMessage = DBusMessage::createSignal( - dbusStub.getObjectPath().c_str(), - dbusStub.getInterfaceName(), + objectPath, + interfaceName, signalName, signalSignature); @@ -135,11 +264,25 @@ struct DBusStubSignalHelper<_In<_InArgs...>> { outputStream.flush(); } - const bool dbusMessageSent = dbusStub.getDBusConnection()->sendDBusMessage(dbusMessage); + const bool dbusMessageSent = dbusConnection->sendDBusMessage(dbusMessage); return dbusMessageSent; } template <typename _DBusStub = DBusStubAdapter> + static bool sendSignal(const _DBusStub& dbusStub, + const char* signalName, + const char* signalSignature, + const _InArgs&... inArgs) { + return(sendSignal(dbusStub.getObjectPath().c_str(), + dbusStub.getInterfaceName().c_str(), + signalName, + signalSignature, + dbusStub.getDBusConnection(), + inArgs...)); + } + + + template <typename _DBusStub = DBusStubAdapter> static bool sendSignal( const char* target, const _DBusStub& dbusStub, const char* signalName, @@ -167,7 +310,68 @@ struct DBusStubSignalHelper<_In<_InArgs...>> { } }; +template< class > +struct DBusStubFreedesktopPropertiesSignalHelper; + +template<template<class ...> class _In, class _InArg> +struct DBusStubFreedesktopPropertiesSignalHelper<_In<_InArg>> { + template <typename _ValueType> + struct DBusPropertiesEntry: public CommonAPI::SerializableStruct { + std::string propertyName_; + DBusLegacyVariantWrapper<CommonAPI::Variant<_ValueType>> propertyValue_; + + DBusPropertiesEntry() = default; + DBusPropertiesEntry(const std::string& propertyName, + const DBusLegacyVariantWrapper<CommonAPI::Variant<_ValueType>>& propertyValue): + propertyName_(propertyName), + propertyValue_(propertyValue) { + }; + + virtual void readFromInputStream(CommonAPI::InputStream& inputStream) { + inputStream >> propertyName_; + inputStream >> propertyValue_; + } + + virtual void writeToOutputStream(CommonAPI::OutputStream& outputStream) const { + outputStream << propertyName_; + outputStream << propertyValue_; + } + static inline void writeToTypeOutputStream(CommonAPI::TypeOutputStream& typeOutputStream) { + typeOutputStream.writeStringType(); + typeOutputStream.writeVariantType(); + } + + }; + + template <typename _DBusStub = DBusStubAdapter> + static bool sendPropertiesChangedSignal(const _DBusStub& dbusStub, const std::string& propertyName, const _InArg& inArg) { + const std::vector<std::string> invalidatedProperties; + const std::vector<DBusPropertiesEntry<_InArg>> changedProperties = {wrapValue(propertyName, inArg)}; + + return DBusStubSignalHelper<_In<const std::string, std::vector<DBusPropertiesEntry<_InArg>>, std::vector<std::string>>>:: + sendSignal(dbusStub.getObjectPath().c_str(), + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + "sa{sv}as", + dbusStub.getDBusConnection(), + dbusStub.getInterfaceName(), + changedProperties, + invalidatedProperties); + } +private: + template <typename _ValueType> + static DBusPropertiesEntry<_ValueType> wrapValue(const std::string& propertyName, _ValueType value) { + CommonAPI::Variant<_ValueType> returnVariant(value); + + DBusLegacyVariantWrapper<CommonAPI::Variant<_ValueType>> wrappedReturnVariant; + wrappedReturnVariant.contained_ = returnVariant; + + DBusPropertiesEntry<_ValueType> returnEntry(propertyName, wrappedReturnVariant); + + return returnEntry; + } +}; template< class, class > class DBusMethodStubDispatcher; @@ -348,7 +552,7 @@ class DBusMethodWithReplyAdapterDispatcher<_StubClass, _StubAdapterClass, _In<_I template <typename _StubClass, typename _AttributeType> -class DBusGetAttributeStubDispatcher: public DBusStubAdapterHelper<_StubClass>::StubDispatcher { +class DBusGetAttributeStubDispatcher: public virtual DBusStubAdapterHelper<_StubClass>::StubDispatcher { public: typedef DBusStubAdapterHelper<_StubClass> DBusStubAdapterHelperType; typedef const _AttributeType& (_StubClass::*GetStubFunctor)(std::shared_ptr<CommonAPI::ClientId>); @@ -358,12 +562,13 @@ class DBusGetAttributeStubDispatcher: public DBusStubAdapterHelper<_StubClass>:: dbusSignature_(dbusSignature) { } + virtual ~DBusGetAttributeStubDispatcher() {}; + bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) { return sendAttributeValueReply(dbusMessage, stub, dbusStubAdapterHelper); } - protected: - inline bool sendAttributeValueReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) { + virtual bool sendAttributeValueReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) { DBusMessage dbusMessageReply = dbusMessage.createMethodReturn(dbusSignature_); DBusOutputStream dbusOutputStream(dbusMessageReply); @@ -379,9 +584,53 @@ class DBusGetAttributeStubDispatcher: public DBusStubAdapterHelper<_StubClass>:: const char* dbusSignature_; }; +template <typename _StubClass> +class DBusGetFreedesktopAttributeStubDispatcherBase { +public: + virtual ~DBusGetFreedesktopAttributeStubDispatcherBase() {} + virtual void dispatchDBusMessageAndAppendReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusOutputStream& dbusOutputStream, const std::shared_ptr<DBusClientId>& clientId) = 0; +}; template <typename _StubClass, typename _AttributeType> -class DBusSetAttributeStubDispatcher: public DBusGetAttributeStubDispatcher<_StubClass, _AttributeType> { +class DBusGetFreedesktopAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>, public virtual DBusGetFreedesktopAttributeStubDispatcherBase<_StubClass> { +public: + typedef DBusStubAdapterHelper<_StubClass> DBusStubAdapterHelperType; + typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>::GetStubFunctor GetStubFunctor; + DBusGetFreedesktopAttributeStubDispatcher(GetStubFunctor getStubFunctor) : + DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor, "v") { + } + + virtual ~DBusGetFreedesktopAttributeStubDispatcher() {}; + + void dispatchDBusMessageAndAppendReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusOutputStream& dbusOutputStream, const std::shared_ptr<DBusClientId>& clientId) { + CommonAPI::Variant<_AttributeType> returnVariant((stub.get()->*(DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>::getStubFunctor_))(clientId)); + + DBusLegacyVariantWrapper<CommonAPI::Variant<_AttributeType>> wrappedReturnVariant; + wrappedReturnVariant.contained_ = returnVariant; + + dbusOutputStream << wrappedReturnVariant; + } +protected: + virtual bool sendAttributeValueReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) { + DBusMessage dbusMessageReply = dbusMessage.createMethodReturn(DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>::dbusSignature_); + DBusOutputStream dbusOutputStream(dbusMessageReply); + + std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSenderName())); + + CommonAPI::Variant<_AttributeType> returnVariant((stub.get()->*(DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>::getStubFunctor_))(clientId)); + + DBusLegacyVariantWrapper<CommonAPI::Variant<_AttributeType>> wrappedReturnVariant; + wrappedReturnVariant.contained_ = returnVariant; + dbusOutputStream << wrappedReturnVariant; + dbusOutputStream.flush(); + + return dbusStubAdapterHelper.getDBusConnection()->sendDBusMessage(dbusMessageReply); + } +}; + + +template <typename _StubClass, typename _AttributeType> +class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatcher<_StubClass, _AttributeType> { public: typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>::DBusStubAdapterHelperType DBusStubAdapterHelperType; typedef typename DBusStubAdapterHelperType::RemoteEventHandlerType RemoteEventHandlerType; @@ -399,6 +648,8 @@ class DBusSetAttributeStubDispatcher: public DBusGetAttributeStubDispatcher<_Stu onRemoteChangedFunctor_(onRemoteChangedFunctor) { } + virtual ~DBusSetAttributeStubDispatcher() {}; + bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) { bool attributeValueChanged; @@ -412,15 +663,30 @@ class DBusSetAttributeStubDispatcher: public DBusGetAttributeStubDispatcher<_Stu } protected: + virtual _AttributeType retreiveAttributeValue(const DBusMessage& dbusMessage, bool& errorOccured) { + errorOccured = false; + + DBusInputStream dbusInputStream(dbusMessage); + _AttributeType attributeValue; + dbusInputStream >> attributeValue; + + if (dbusInputStream.hasError()) { + errorOccured = true; + } + + return attributeValue; + } + inline bool setAttributeValue(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper, bool& attributeValueChanged) { - DBusInputStream dbusInputStream(dbusMessage); - _AttributeType attributeValue; - dbusInputStream >> attributeValue; - if (dbusInputStream.hasError()) + bool errorOccured; + _AttributeType attributeValue = retreiveAttributeValue(dbusMessage, errorOccured); + + if(errorOccured) { return false; + } std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSenderName())); @@ -441,9 +707,54 @@ class DBusSetAttributeStubDispatcher: public DBusGetAttributeStubDispatcher<_Stu const OnRemoteChangedFunctor onRemoteChangedFunctor_; }; +template <typename _StubClass, typename _AttributeType> +class DBusSetFreedesktopAttributeStubDispatcher: public virtual DBusGetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>, public virtual DBusSetAttributeStubDispatcher<_StubClass, _AttributeType> { +public: + typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>::GetStubFunctor GetStubFunctor; + typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>::DBusStubAdapterHelperType DBusStubAdapterHelperType; + typedef typename DBusStubAdapterHelperType::RemoteEventHandlerType RemoteEventHandlerType; + typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr<CommonAPI::ClientId>, _AttributeType); + typedef void (RemoteEventHandlerType::*OnRemoteChangedFunctor)(); + + DBusSetFreedesktopAttributeStubDispatcher(GetStubFunctor getStubFunctor, + OnRemoteSetFunctor onRemoteSetFunctor, + OnRemoteChangedFunctor onRemoteChangedFunctor) : + DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>( + getStubFunctor, + "v"), + DBusGetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>( + getStubFunctor), + DBusSetAttributeStubDispatcher<_StubClass, _AttributeType>( + getStubFunctor, + onRemoteSetFunctor, + onRemoteChangedFunctor, + "v") { + } + + virtual ~DBusSetFreedesktopAttributeStubDispatcher() {}; +protected: + virtual _AttributeType retreiveAttributeValue(const DBusMessage& dbusMessage, bool& errorOccured) { + errorOccured = false; + std::string interfaceName; + std::string attributeName; + + DBusInputStream dbusInputStream(dbusMessage); + DBusLegacyVariantWrapper<CommonAPI::Variant<_AttributeType>> variantValue; + dbusInputStream >> interfaceName; // skip over interface and attribute name + dbusInputStream >> attributeName; + dbusInputStream >> variantValue; + _AttributeType attributeValue = variantValue.contained_.template get<_AttributeType>() ; + + if (dbusInputStream.hasError()) { + errorOccured = true; + } + + return attributeValue; + } +}; template <typename _StubClass, typename _AttributeType> -class DBusSetObservableAttributeStubDispatcher: public DBusSetAttributeStubDispatcher<_StubClass, _AttributeType> { +class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeStubDispatcher<_StubClass, _AttributeType> { public: typedef typename DBusSetAttributeStubDispatcher<_StubClass, _AttributeType>::DBusStubAdapterHelperType DBusStubAdapterHelperType; typedef typename DBusStubAdapterHelperType::StubAdapterType StubAdapterType; @@ -458,13 +769,16 @@ class DBusSetObservableAttributeStubDispatcher: public DBusSetAttributeStubDispa OnRemoteChangedFunctor onRemoteChangedFunctor, FireChangedFunctor fireChangedFunctor, const char* dbusSignature) : + DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor, dbusSignature), DBusSetAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor, - onRemoteSetFunctor, - onRemoteChangedFunctor, - dbusSignature), + onRemoteSetFunctor, + onRemoteChangedFunctor, + dbusSignature), fireChangedFunctor_(fireChangedFunctor) { } + virtual ~DBusSetObservableAttributeStubDispatcher() {}; + bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) { bool attributeValueChanged; if (!this->setAttributeValue(dbusMessage, stub, dbusStubAdapterHelper, attributeValueChanged)) @@ -477,15 +791,47 @@ class DBusSetObservableAttributeStubDispatcher: public DBusSetAttributeStubDispa } return true; } - - private: - inline void fireAttributeValueChanged(std::shared_ptr<CommonAPI::ClientId> clientId, DBusStubAdapterHelperType& dbusStubAdapterHelper, const std::shared_ptr<_StubClass> stub) { +protected: + virtual void fireAttributeValueChanged(std::shared_ptr<CommonAPI::ClientId> clientId, + DBusStubAdapterHelperType& dbusStubAdapterHelper, + const std::shared_ptr<_StubClass> stub) { (stub->StubType::getStubAdapter().get()->*fireChangedFunctor_)(this->getAttributeValue(clientId, stub)); } const FireChangedFunctor fireChangedFunctor_; }; +template <typename _StubClass, typename _AttributeType> +class DBusSetFreedesktopObservableAttributeStubDispatcher: public virtual DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>, public virtual DBusSetObservableAttributeStubDispatcher<_StubClass, _AttributeType> { +public: + typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>::DBusStubAdapterHelperType DBusStubAdapterHelperType; + typedef typename DBusStubAdapterHelperType::StubAdapterType StubAdapterType; + typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>::GetStubFunctor GetStubFunctor; + typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>::OnRemoteSetFunctor OnRemoteSetFunctor; + typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>::OnRemoteChangedFunctor OnRemoteChangedFunctor; + typedef void (StubAdapterType::*FireChangedFunctor)(const _AttributeType&); + + DBusSetFreedesktopObservableAttributeStubDispatcher(GetStubFunctor getStubFunctor, + OnRemoteSetFunctor onRemoteSetFunctor, + OnRemoteChangedFunctor onRemoteChangedFunctor, + FireChangedFunctor fireChangedFunctor) : + DBusGetAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor, "v"), + DBusGetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor), + DBusSetAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor, + onRemoteSetFunctor, + onRemoteChangedFunctor, + "v"), + DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor, + onRemoteSetFunctor, + onRemoteChangedFunctor), + DBusSetObservableAttributeStubDispatcher<_StubClass, _AttributeType>(getStubFunctor, + onRemoteSetFunctor, + onRemoteChangedFunctor, + fireChangedFunctor, + "v") { + } +}; + } // namespace DBus } // namespace CommonAPI diff --git a/src/test/DBusFreedesktopPropertiesTest.cpp b/src/test/DBusFreedesktopPropertiesTest.cpp new file mode 100644 index 0000000..a03798e --- /dev/null +++ b/src/test/DBusFreedesktopPropertiesTest.cpp @@ -0,0 +1,242 @@ +/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * 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/. */ +#include <gtest/gtest.h> +#include <commonapi/tests/DerivedTypeCollection.h> +#include <commonapi/tests/TestFreedesktopInterfaceProxy.h> +#include <commonapi/tests/TestFreedesktopInterfaceStub.h> +#include <commonapi/tests/TestFreedesktopInterfaceStubDefault.h> +#include <commonapi/tests/TestFreedesktopDerivedInterfaceProxy.h> +#include <commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.h> + + +#ifndef COMMONAPI_INTERNAL_COMPILATION +#define COMMONAPI_INTERNAL_COMPILATION +#endif +#include <CommonAPI/DBus/DBusRuntime.h> + +#ifndef COMMONAPI_INTERNAL_COMPILATION +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +static const std::string commonApiAddress = + "local:CommonAPI.DBus.tests.DBusProxyTestFreedesktopPropertiesInterface:CommonAPI.DBus.tests.DBusProxyTestFreedesktopPropertiesInterface"; + +class FreedesktopPropertiesTest: public ::testing::Test { +protected: + void SetUp() { + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); + servicePublisher_ = runtime->getServicePublisher(); + + ASSERT_TRUE(servicePublisher_ != NULL); + + serviceFactory_ = runtime->createFactory(); + proxyFactory_ = runtime->createFactory(); + + ASSERT_TRUE(serviceFactory_ != NULL); + ASSERT_TRUE(proxyFactory_ != NULL); + + proxy_ = proxyFactory_->buildProxy<commonapi::tests::TestFreedesktopInterfaceProxy>(commonApiAddress); + + registerTestStub(); + + for (unsigned int i = 0; !proxy_->isAvailable() && i < 100; ++i) { + usleep(10000); + } + ASSERT_TRUE(proxy_->isAvailable()); + } + + virtual void TearDown() { + deregisterTestStub(); + usleep(30000); + } + + void registerTestStub() { + testStub_ = std::make_shared<commonapi::tests::TestFreedesktopInterfaceStubDefault>(); + const bool isServiceRegistered = servicePublisher_->registerService(testStub_, commonApiAddress, serviceFactory_); + + ASSERT_TRUE(isServiceRegistered); + } + + + void deregisterTestStub() { + const bool isStubAdapterUnregistered = servicePublisher_->unregisterService(commonApiAddress); + ASSERT_TRUE(isStubAdapterUnregistered); + } + + std::shared_ptr<CommonAPI::Factory> serviceFactory_, proxyFactory_; + std::shared_ptr<commonapi::tests::TestFreedesktopInterfaceProxyDefault> proxy_; + std::shared_ptr<commonapi::tests::TestFreedesktopInterfaceStubDefault> testStub_; + std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher_; +}; + +TEST_F(FreedesktopPropertiesTest, GetBasicTypeAttribute) { + CommonAPI::CallStatus callStatus(CommonAPI::CallStatus::REMOTE_ERROR); + uint32_t value; + + auto& testAttribute = proxy_->getTestPredefinedTypeAttributeAttribute(); + + testAttribute.getValue(callStatus, value); + + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); +} + +TEST_F(FreedesktopPropertiesTest, GetAndSetBasicTypeAttribute) { + CommonAPI::CallStatus callStatus(CommonAPI::CallStatus::REMOTE_ERROR); + uint32_t value; + + auto& testAttribute = proxy_->getTestPredefinedTypeAttributeAttribute(); + + testAttribute.getValue(callStatus, value); + + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + + callStatus = CommonAPI::CallStatus::REMOTE_ERROR; + uint32_t newValue = 7; + + testAttribute.setValue(newValue, callStatus, value); + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + ASSERT_EQ(value, 7); + + value = 0; + callStatus = CommonAPI::CallStatus::REMOTE_ERROR; + testAttribute.getValue(callStatus, value); + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + ASSERT_EQ(value, 7); +} + +TEST_F(FreedesktopPropertiesTest, CanSendAndReceiveNotificationForSingleProperty) { + auto& testAttribute = proxy_->getTestPredefinedTypeAttributeAttribute(); + + bool callbackArrived = false; + + std::function<void(const uint32_t)> listener([&](const uint32_t value) { + ASSERT_EQ(7, value); + callbackArrived = true; + }); + + usleep(200000); + + testAttribute.getChangedEvent().subscribe(listener); + + CommonAPI::CallStatus callStatus = CommonAPI::CallStatus::REMOTE_ERROR; + uint32_t value; + uint32_t newValue = 7; + + testAttribute.setValue(newValue, callStatus, value); + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + ASSERT_EQ(value, 7); + + + uint8_t waitCounter = 0; + while(!callbackArrived && waitCounter < 10) { + usleep(50000); + waitCounter++; + } + + ASSERT_TRUE(callbackArrived); +} + +class FreedesktopPropertiesOnInheritedInterfacesTest: public ::testing::Test { +protected: + void SetUp() { + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); + servicePublisher_ = runtime->getServicePublisher(); + + ASSERT_TRUE(servicePublisher_ != NULL); + + serviceFactory_ = runtime->createFactory(); + proxyFactory_ = runtime->createFactory(); + + ASSERT_TRUE(serviceFactory_ != NULL); + ASSERT_TRUE(proxyFactory_ != NULL); + + proxy_ = proxyFactory_->buildProxy<commonapi::tests::TestFreedesktopDerivedInterfaceProxy>(commonApiAddress); + + registerTestStub(); + + for (unsigned int i = 0; !proxy_->isAvailable() && i < 100; ++i) { + usleep(10000); + } + ASSERT_TRUE(proxy_->isAvailable()); + } + + virtual void TearDown() { + deregisterTestStub(); + usleep(30000); + } + + void registerTestStub() { + testStub_ = std::make_shared<commonapi::tests::TestFreedesktopDerivedInterfaceStubDefault>(); + const bool isServiceRegistered = servicePublisher_->registerService(testStub_, commonApiAddress, serviceFactory_); + + ASSERT_TRUE(isServiceRegistered); + } + + void deregisterTestStub() { + const bool isStubAdapterUnregistered = servicePublisher_->unregisterService(commonApiAddress); + ASSERT_TRUE(isStubAdapterUnregistered); + } + + + std::shared_ptr<CommonAPI::Factory> serviceFactory_, proxyFactory_; + std::shared_ptr<commonapi::tests::TestFreedesktopDerivedInterfaceProxyDefault> proxy_; + std::shared_ptr<commonapi::tests::TestFreedesktopDerivedInterfaceStubDefault> testStub_; + std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher_; +}; + +TEST_F(FreedesktopPropertiesOnInheritedInterfacesTest, CanGetAndSetRemoteAttributeFromDerivedInterface) { + auto& testAttribute = proxy_->getTestAttributedFromDerivedInterfaceAttribute(); + + CommonAPI::CallStatus callStatus(CommonAPI::CallStatus::REMOTE_ERROR); + uint32_t value; + testAttribute.getValue(callStatus, value); + + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + + callStatus = CommonAPI::CallStatus::REMOTE_ERROR; + uint32_t newValue = 7; + + testAttribute.setValue(newValue, callStatus, value); + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + ASSERT_EQ(value, 7); + + value = 0; + callStatus = CommonAPI::CallStatus::REMOTE_ERROR; + testAttribute.getValue(callStatus, value); + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + ASSERT_EQ(value, 7); +} + +TEST_F(FreedesktopPropertiesOnInheritedInterfacesTest, CanGetAndSetRemoteAttributeFromParentInterface) { + auto& testAttribute = proxy_->getTestPredefinedTypeAttributeAttribute(); + + CommonAPI::CallStatus callStatus(CommonAPI::CallStatus::REMOTE_ERROR); + uint32_t value; + testAttribute.getValue(callStatus, value); + + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + + callStatus = CommonAPI::CallStatus::REMOTE_ERROR; + uint32_t newValue = 7; + + testAttribute.setValue(newValue, callStatus, value); + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + ASSERT_EQ(value, 7); + + value = 0; + callStatus = CommonAPI::CallStatus::REMOTE_ERROR; + testAttribute.getValue(callStatus, value); + ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); + ASSERT_EQ(value, 7); +} + +#ifndef WIN32 +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} +#endif diff --git a/src/test/DBusObjectManagerStubTest.cpp b/src/test/DBusObjectManagerStubTest.cpp index b7d1294..5c75075 100644 --- a/src/test/DBusObjectManagerStubTest.cpp +++ b/src/test/DBusObjectManagerStubTest.cpp @@ -56,6 +56,10 @@ public: return false; } + virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const CommonAPI::DBus::DBusMessage& dbusMessage) { + return false; + } + protected: TestDBusStubAdapter(const std::shared_ptr<CommonAPI::DBus::DBusFactory> factory, const std::string& dbusObjectPath, diff --git a/src/test/DBusServiceRegistryTest.cpp b/src/test/DBusServiceRegistryTest.cpp index 34a40f5..d8e60df 100644 --- a/src/test/DBusServiceRegistryTest.cpp +++ b/src/test/DBusServiceRegistryTest.cpp @@ -168,6 +168,10 @@ public: return false; } + virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const CommonAPI::DBus::DBusMessage& dbusMessage) { + return false; + } + mutable size_t introspectionCount; }; diff --git a/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp index 59cf9cd..bbfa2b8 100644 --- a/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.cpp @@ -68,9 +68,10 @@ CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher< > ExtendedInterfaceDBusStubAdapterInternal::setTestPredefinedTypeAttributeAttributeStubDispatcher( &ExtendedInterfaceStub::getTestPredefinedTypeAttributeAttribute, &ExtendedInterfaceStubRemoteEvent::onRemoteSetTestPredefinedTypeAttributeAttribute, - &ExtendedInterfaceStubRemoteEvent::onRemoteTestPredefinedTypeAttributeAttributeChanged, - &ExtendedInterfaceStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged, - "u"); + &ExtendedInterfaceStubRemoteEvent::onRemoteTestPredefinedTypeAttributeAttributeChanged + ,&ExtendedInterfaceStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged + ,"u" + ); CommonAPI::DBus::DBusGetAttributeStubDispatcher< ExtendedInterfaceStub, DerivedTypeCollection::TestStructExtended @@ -81,9 +82,10 @@ CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher< > ExtendedInterfaceDBusStubAdapterInternal::setTestDerivedStructAttributeAttributeStubDispatcher( &ExtendedInterfaceStub::getTestDerivedStructAttributeAttribute, &ExtendedInterfaceStubRemoteEvent::onRemoteSetTestDerivedStructAttributeAttribute, - &ExtendedInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged, - &ExtendedInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged, - "(sqi)"); + &ExtendedInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged + ,&ExtendedInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged + ,"(sqi)" + ); CommonAPI::DBus::DBusGetAttributeStubDispatcher< ExtendedInterfaceStub, DerivedTypeCollection::TestArrayUInt64 @@ -94,9 +96,10 @@ CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher< > ExtendedInterfaceDBusStubAdapterInternal::setTestDerivedArrayAttributeAttributeStubDispatcher( &ExtendedInterfaceStub::getTestDerivedArrayAttributeAttribute, &ExtendedInterfaceStubRemoteEvent::onRemoteSetTestDerivedArrayAttributeAttribute, - &ExtendedInterfaceStubRemoteEvent::onRemoteTestDerivedArrayAttributeAttributeChanged, - &ExtendedInterfaceStubAdapter::fireTestDerivedArrayAttributeAttributeChanged, - "at"); + &ExtendedInterfaceStubRemoteEvent::onRemoteTestDerivedArrayAttributeAttributeChanged + ,&ExtendedInterfaceStubAdapter::fireTestDerivedArrayAttributeAttributeChanged + ,"at" + ); #endif CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< @@ -188,6 +191,9 @@ const ExtendedInterfaceDBusStubAdapterHelper::StubDispatcherTable& ExtendedInter return stubDispatcherTable_; } +const CommonAPI::DBus::StubAttributeTable& ExtendedInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; +} ExtendedInterfaceDBusStubAdapterInternal::ExtendedInterfaceDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -250,7 +256,8 @@ ExtendedInterfaceDBusStubAdapterInternal::ExtendedInterfaceDBusStubAdapterIntern , { { "unsubscribeFromTestBroadcastWithOutArgsSelective", "" }, &commonapi::tests::ExtendedInterfaceDBusStubAdapterInternal::unsubscribeTestBroadcastWithOutArgsSelectiveStubDispatcher } #endif - }) { + }), + stubAttributeTable_() { #ifdef WIN32 stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::ExtendedInterfaceDBusStubAdapterInternal::getExtendedInterfaceInterfaceVersionStubDispatcher }); @@ -264,8 +271,16 @@ ExtendedInterfaceDBusStubAdapterInternal::ExtendedInterfaceDBusStubAdapterIntern } else { stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::ExtendedInterfaceDBusStubAdapterInternal::getExtendedInterfaceInterfaceVersionStubDispatcher }); } + + auto parentAttributeTable = TestInterfaceDBusStubAdapterInternal::getStubAttributeTable(); + stubAttributeTable_.insert(parentAttributeTable.begin(), parentAttributeTable.end()); + #endif } +const bool ExtendedInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return false; +} + } // namespace tests } // namespace commonapi diff --git a/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.h index 3d2f23e..5c43471 100644 --- a/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.h +++ b/src/test/commonapi/tests/ExtendedInterfaceDBusStubAdapter.h @@ -42,10 +42,13 @@ class ExtendedInterfaceDBusStubAdapterInternal: public virtual ExtendedInterface ~ExtendedInterfaceDBusStubAdapterInternal(); + virtual const bool hasFreedesktopProperties(); + const ExtendedInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); void deactivateManagedInstances(); @@ -77,6 +80,10 @@ class ExtendedInterfaceDBusStubAdapterInternal: public virtual ExtendedInterface return ExtendedInterfaceDBusStubAdapterHelper::onInterfaceDBusMessage(dbusMessage); } + virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const CommonAPI::DBus::DBusMessage& dbusMessage) { + return ExtendedInterfaceDBusStubAdapterHelper::onInterfaceDBusFreedesktopPropertiesMessage(dbusMessage); + } + static CommonAPI::DBus::DBusGetAttributeStubDispatcher< ExtendedInterfaceStub, CommonAPI::Version @@ -196,9 +203,10 @@ static CommonAPI::DBus::DBusMethodWithReplyAdapterDispatcher< protected: virtual const char* getMethodsDBusIntrospectionXmlData() const; - - private: + + private: ExtendedInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; }; class ExtendedInterfaceDBusStubAdapter: public ExtendedInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<ExtendedInterfaceDBusStubAdapter> { diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterface.h b/src/test/commonapi/tests/TestFreedesktopDerivedInterface.h new file mode 100644 index 0000000..ea40d73 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterface.h @@ -0,0 +1,60 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_H_ + + + +#include <commonapi/tests/TestFreedesktopInterface.h> + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/types.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +class TestFreedesktopDerivedInterface: public TestFreedesktopInterface { + public: + virtual ~TestFreedesktopDerivedInterface() { } + + static inline const char* getInterfaceId(); + static inline CommonAPI::Version getInterfaceVersion(); +}; + +const char* TestFreedesktopDerivedInterface::getInterfaceId() { + static const char* interfaceId = "commonapi.tests.TestFreedesktopDerivedInterface"; + return interfaceId; +} + +CommonAPI::Version TestFreedesktopDerivedInterface::getInterfaceVersion() { + return CommonAPI::Version(1, 0); +} + + +} // namespace tests +} // namespace commonapi + +namespace CommonAPI { + +} + + +namespace std { + //hashes for types + + //hashes for error types +} + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.cpp b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.cpp new file mode 100644 index 0000000..d8b2602 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.cpp @@ -0,0 +1,63 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#include "TestFreedesktopDerivedInterfaceDBusProxy.h" + +namespace commonapi { +namespace tests { + +std::shared_ptr<CommonAPI::DBus::DBusProxy> createTestFreedesktopDerivedInterfaceDBusProxy( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection) { + return std::make_shared<TestFreedesktopDerivedInterfaceDBusProxy>(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection); +} + +INITIALIZER(registerTestFreedesktopDerivedInterfaceDBusProxy) { + CommonAPI::DBus::DBusFactory::registerProxyFactoryMethod(TestFreedesktopDerivedInterface::getInterfaceId(), + &createTestFreedesktopDerivedInterfaceDBusProxy); +} + +TestFreedesktopDerivedInterfaceDBusProxy::TestFreedesktopDerivedInterfaceDBusProxy( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection): + CommonAPI::DBus::DBusProxy(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyconnection) + , TestFreedesktopInterfaceDBusProxy( + factory, + commonApiAddress, + interfaceName, + busName, + objectPath, + dbusProxyconnection) +,testAttributedFromDerivedInterface_(*this, interfaceName.c_str(), "TestAttributedFromDerivedInterface") + { + } + +TestFreedesktopDerivedInterfaceDBusProxy::TestAttributedFromDerivedInterfaceAttribute& TestFreedesktopDerivedInterfaceDBusProxy::getTestAttributedFromDerivedInterfaceAttribute() { + return testAttributedFromDerivedInterface_; +} + + + + + +void TestFreedesktopDerivedInterfaceDBusProxy::getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const { + ownVersionMajor = 1; + ownVersionMinor = 0; +} + +} // namespace tests +} // namespace commonapi diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.h b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.h new file mode 100644 index 0000000..260e3ce --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusProxy.h @@ -0,0 +1,61 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_DBUS_PROXY_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_DBUS_PROXY_H_ + +#include <commonapi/tests/TestFreedesktopDerivedInterfaceProxyBase.h> +#include <commonapi/tests/TestFreedesktopInterfaceDBusProxy.h> + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/DBus/DBusFactory.h> +#include <CommonAPI/DBus/DBusProxy.h> +#include <CommonAPI/DBus/DBusAttribute.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +#include <string> + +namespace commonapi { +namespace tests { + +class TestFreedesktopDerivedInterfaceDBusProxy: virtual public TestFreedesktopDerivedInterfaceProxyBase, virtual public TestFreedesktopInterfaceDBusProxy { + public: + TestFreedesktopDerivedInterfaceDBusProxy( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection); + + virtual ~TestFreedesktopDerivedInterfaceDBusProxy() { } + + virtual TestAttributedFromDerivedInterfaceAttribute& getTestAttributedFromDerivedInterfaceAttribute(); + + + + + virtual void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const; + + private: + CommonAPI::DBus::DBusFreedesktopObservableAttribute<CommonAPI::DBus::DBusFreedesktopAttribute<TestAttributedFromDerivedInterfaceAttribute>> testAttributedFromDerivedInterface_; + + +}; + + + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_DBUS_PROXY_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.cpp new file mode 100644 index 0000000..71ac6fe --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.cpp @@ -0,0 +1,245 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#include "TestFreedesktopDerivedInterfaceDBusStubAdapter.h" +#include <commonapi/tests/TestFreedesktopDerivedInterface.h> + +namespace commonapi { +namespace tests { + +std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createTestFreedesktopDerivedInterfaceDBusStubAdapter( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection, + const std::shared_ptr<CommonAPI::StubBase>& stubBase) { + return std::make_shared<TestFreedesktopDerivedInterfaceDBusStubAdapter>(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection, stubBase); +} + +INITIALIZER(registerTestFreedesktopDerivedInterfaceDBusStubAdapter) { + CommonAPI::DBus::DBusFactory::registerAdapterFactoryMethod(TestFreedesktopDerivedInterface::getInterfaceId(), + &createTestFreedesktopDerivedInterfaceDBusStubAdapter); +} + + + +TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::~TestFreedesktopDerivedInterfaceDBusStubAdapterInternal() { + deactivateManagedInstances(); + TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::deinit(); +} + +void TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { + +} + +const char* TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getMethodsDBusIntrospectionXmlData() const { + static const std::string introspectionData = + std::string(TestFreedesktopInterfaceDBusStubAdapterInternal::getMethodsDBusIntrospectionXmlData()) + + "<property name=\"TestAttributedFromDerivedInterface\" type=\"u\" access=\"readwrite\" />\n" + + ; + return introspectionData.c_str(); +} + +CommonAPI::DBus::DBusGetAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + CommonAPI::Version + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestFreedesktopDerivedInterfaceInterfaceVersionStubDispatcher(&TestFreedesktopDerivedInterfaceStub::getInterfaceVersion, "uu"); + +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestAttributedFromDerivedInterfaceAttributeStubDispatcher(&TestFreedesktopDerivedInterfaceStub::getTestAttributedFromDerivedInterfaceAttribute); +CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestAttributedFromDerivedInterfaceAttributeStubDispatcher( + &TestFreedesktopDerivedInterfaceStub::getTestAttributedFromDerivedInterfaceAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteSetTestAttributedFromDerivedInterfaceAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteTestAttributedFromDerivedInterfaceAttributeChanged + ,&TestFreedesktopDerivedInterfaceStubAdapter::fireTestAttributedFromDerivedInterfaceAttributeChanged + ); + +#ifdef WIN32 +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestPredefinedTypeAttributeAttributeStubDispatcher(&TestFreedesktopDerivedInterfaceStub::getTestPredefinedTypeAttributeAttribute); +CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestPredefinedTypeAttributeAttributeStubDispatcher( + &TestFreedesktopDerivedInterfaceStub::getTestPredefinedTypeAttributeAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteSetTestPredefinedTypeAttributeAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteTestPredefinedTypeAttributeAttributeChanged + ,&TestFreedesktopDerivedInterfaceStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged + ); +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestReadonlyAttributeAttributeStubDispatcher(&TestFreedesktopDerivedInterfaceStub::getTestReadonlyAttributeAttribute); +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestStructExtended + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestDerivedStructAttributeAttributeStubDispatcher(&TestFreedesktopDerivedInterfaceStub::getTestDerivedStructAttributeAttribute); +CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestStructExtended + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestDerivedStructAttributeAttributeStubDispatcher( + &TestFreedesktopDerivedInterfaceStub::getTestDerivedStructAttributeAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteSetTestDerivedStructAttributeAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged + ,&TestFreedesktopDerivedInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged + ); +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestDerivedArrayAttributeAttributeStubDispatcher(&TestFreedesktopDerivedInterfaceStub::getTestDerivedArrayAttributeAttribute); +CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestDerivedArrayAttributeAttributeStubDispatcher( + &TestFreedesktopDerivedInterfaceStub::getTestDerivedArrayAttributeAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteSetTestDerivedArrayAttributeAttribute, + &TestFreedesktopDerivedInterfaceStubRemoteEvent::onRemoteTestDerivedArrayAttributeAttributeChanged + ,&TestFreedesktopDerivedInterfaceStubAdapter::fireTestDerivedArrayAttributeAttributeChanged + ); +#endif + + +#ifdef WIN32 +#endif + +void TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::fireTestAttributedFromDerivedInterfaceAttributeChanged(const uint32_t& value) { + CommonAPI::DBus::DBusStubFreedesktopPropertiesSignalHelper<CommonAPI::DBus::DBusSerializableArguments<uint32_t>> + ::sendPropertiesChangedSignal( + *this, + "TestAttributedFromDerivedInterface", + value + ); +} + + +#ifdef WIN32 +#endif + +const TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::StubDispatcherTable& TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getStubDispatcherTable() { + return stubDispatcherTable_; +} + +const CommonAPI::DBus::StubAttributeTable& TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; +} + +TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& dbusInterfaceName, + const std::string& dbusBusName, + const std::string& dbusObjectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection, + const std::shared_ptr<CommonAPI::StubBase>& stub): + CommonAPI::DBus::DBusStubAdapter( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + false), + TestFreedesktopDerivedInterfaceDBusStubAdapterHelper( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + std::dynamic_pointer_cast<TestFreedesktopDerivedInterfaceStub>(stub), + false), + TestFreedesktopInterfaceDBusStubAdapterInternal( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + stub), + stubDispatcherTable_({ + #ifdef WIN32 + #endif + }), + stubAttributeTable_({ + { + "TestAttributedFromDerivedInterface", + { + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestAttributedFromDerivedInterfaceAttributeStubDispatcher, + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestAttributedFromDerivedInterfaceAttributeStubDispatcher + } + } + #ifdef WIN32 + , + { + "TestPredefinedTypeAttribute", + { + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestPredefinedTypeAttributeAttributeStubDispatcher, + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestPredefinedTypeAttributeAttributeStubDispatcher + } + }, + { + "TestReadonlyAttribute", + { + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestReadonlyAttributeAttributeStubDispatcher, + NULL + } + }, + { + "TestDerivedStructAttribute", + { + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestDerivedStructAttributeAttributeStubDispatcher, + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestDerivedStructAttributeAttributeStubDispatcher + } + }, + { + "TestDerivedArrayAttribute", + { + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestDerivedArrayAttributeAttributeStubDispatcher, + &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::setTestDerivedArrayAttributeAttributeStubDispatcher + } + } + #endif + } + ) { + + #ifdef WIN32 + stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestFreedesktopDerivedInterfaceInterfaceVersionStubDispatcher }); + #else + auto parentDispatcherTable = TestFreedesktopInterfaceDBusStubAdapterInternal::getStubDispatcherTable(); + stubDispatcherTable_.insert(parentDispatcherTable.begin(), parentDispatcherTable.end()); + + auto interfaceVersionGetter = stubDispatcherTable_.find({ "getInterfaceVersion", "" }); + if(interfaceVersionGetter != stubDispatcherTable_.end()) { + interfaceVersionGetter->second = &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestFreedesktopDerivedInterfaceInterfaceVersionStubDispatcher; + } else { + stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::getTestFreedesktopDerivedInterfaceInterfaceVersionStubDispatcher }); + } + + auto parentAttributeTable = TestFreedesktopInterfaceDBusStubAdapterInternal::getStubAttributeTable(); + stubAttributeTable_.insert(parentAttributeTable.begin(), parentAttributeTable.end()); + + #endif +} + +const bool TestFreedesktopDerivedInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return true; +} + +} // namespace tests +} // namespace commonapi diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.h new file mode 100644 index 0000000..c22afff --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceDBusStubAdapter.h @@ -0,0 +1,180 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_DBUS_STUB_ADAPTER_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_DBUS_STUB_ADAPTER_H_ + +#include <commonapi/tests/TestFreedesktopDerivedInterfaceStub.h> +#include <commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.h> + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/DBus/DBusStubAdapterHelper.h> +#include <CommonAPI/DBus/DBusStubAdapter.h> +#include <CommonAPI/DBus/DBusFactory.h> +#include <CommonAPI/DBus/DBusServicePublisher.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +typedef CommonAPI::DBus::DBusStubAdapterHelper<TestFreedesktopDerivedInterfaceStub> TestFreedesktopDerivedInterfaceDBusStubAdapterHelper; + +class TestFreedesktopDerivedInterfaceDBusStubAdapterInternal: public virtual TestFreedesktopDerivedInterfaceStubAdapter, public TestFreedesktopDerivedInterfaceDBusStubAdapterHelper, public TestFreedesktopInterfaceDBusStubAdapterInternal { + public: + TestFreedesktopDerivedInterfaceDBusStubAdapterInternal( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& dbusInterfaceName, + const std::string& dbusBusName, + const std::string& dbusObjectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection, + const std::shared_ptr<CommonAPI::StubBase>& stub); + + ~TestFreedesktopDerivedInterfaceDBusStubAdapterInternal(); + + virtual const bool hasFreedesktopProperties(); + + void fireTestAttributedFromDerivedInterfaceAttributeChanged(const uint32_t& value); + + + + const TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); + + void deactivateManagedInstances(); + + virtual const std::string getAddress() const { + return DBusStubAdapter::getAddress(); + } + + virtual const std::string& getDomain() const { + return DBusStubAdapter::getDomain(); + } + + virtual const std::string& getServiceId() const { + return DBusStubAdapter::getServiceId(); + } + + virtual const std::string& getInstanceId() const { + return DBusStubAdapter::getInstanceId(); + } + + virtual void init(std::shared_ptr<DBusStubAdapter> instance) { + return TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::init(instance); + } + + virtual void deinit() { + return TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::deinit(); + } + + virtual bool onInterfaceDBusMessage(const CommonAPI::DBus::DBusMessage& dbusMessage) { + return TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::onInterfaceDBusMessage(dbusMessage); + } + + virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const CommonAPI::DBus::DBusMessage& dbusMessage) { + return TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::onInterfaceDBusFreedesktopPropertiesMessage(dbusMessage); + } + +static CommonAPI::DBus::DBusGetAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + CommonAPI::Version + > getTestFreedesktopDerivedInterfaceInterfaceVersionStubDispatcher; + +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > getTestAttributedFromDerivedInterfaceAttributeStubDispatcher; +static CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > setTestAttributedFromDerivedInterfaceAttributeStubDispatcher; + +#ifdef WIN32 +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > getTestPredefinedTypeAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > setTestPredefinedTypeAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + uint32_t + > getTestReadonlyAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestStructExtended + > getTestDerivedStructAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestStructExtended + > setTestDerivedStructAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > getTestDerivedArrayAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopDerivedInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > setTestDerivedArrayAttributeAttributeStubDispatcher; +#endif + + +#ifdef WIN32 +#endif + + +#ifdef WIN32 +#endif + + protected: + virtual const char* getMethodsDBusIntrospectionXmlData() const; + + private: + TestFreedesktopDerivedInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; +}; + +class TestFreedesktopDerivedInterfaceDBusStubAdapter: public TestFreedesktopDerivedInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<TestFreedesktopDerivedInterfaceDBusStubAdapter> { +public: + TestFreedesktopDerivedInterfaceDBusStubAdapter( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& dbusInterfaceName, + const std::string& dbusBusName, + const std::string& dbusObjectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection, + const std::shared_ptr<CommonAPI::StubBase>& stub) : + CommonAPI::DBus::DBusStubAdapter( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + false), + TestFreedesktopDerivedInterfaceDBusStubAdapterInternal( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + stub) { } +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_DBUS_STUB_ADAPTER_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceProxy.h b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceProxy.h new file mode 100644 index 0000000..c449582 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceProxy.h @@ -0,0 +1,199 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_PROXY_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_PROXY_H_ + +#include "TestFreedesktopDerivedInterfaceProxyBase.h" + +#include "TestFreedesktopInterfaceProxy.h" + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/AttributeExtension.h> +#include <CommonAPI/Factory.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +template <typename ... _AttributeExtensions> +class TestFreedesktopDerivedInterfaceProxy: virtual public TestFreedesktopDerivedInterface, virtual public TestFreedesktopDerivedInterfaceProxyBase +, virtual public TestFreedesktopInterfaceProxy<_AttributeExtensions...> +, public _AttributeExtensions... { +public: + TestFreedesktopDerivedInterfaceProxy(std::shared_ptr<CommonAPI::Proxy> delegate); + ~TestFreedesktopDerivedInterfaceProxy(); + + typedef TestFreedesktopDerivedInterface InterfaceType; + + inline static const char* getInterfaceId() { + return(TestFreedesktopDerivedInterface::getInterfaceId()); + } + + /** + * Returns the wrapper class that provides access to the attribute TestAttributedFromDerivedInterface. + */ + virtual TestAttributedFromDerivedInterfaceAttribute& getTestAttributedFromDerivedInterfaceAttribute() { + return delegate_->getTestAttributedFromDerivedInterfaceAttribute(); + } + + + + + /** + * Returns the CommonAPI address of the remote partner this proxy communicates with. + */ + virtual std::string getAddress() const; + + /** + * Returns the domain of the remote partner this proxy communicates with. + */ + virtual const std::string& getDomain() const; + + /** + * Returns the service ID of the remote partner this proxy communicates with. + */ + virtual const std::string& getServiceId() const; + + /** + * Returns the instance ID of the remote partner this proxy communicates with. + */ + virtual const std::string& getInstanceId() const; + + /** + * Returns true if the remote partner for this proxy is currently known to be available. + */ + virtual bool isAvailable() const; + + /** + * Returns true if the remote partner for this proxy is available. + */ + virtual bool isAvailableBlocking() const; + + /** + * Returns the wrapper class that is used to (de-)register for notifications about + * the availability of the remote partner of this proxy. + */ + virtual CommonAPI::ProxyStatusEvent& getProxyStatusEvent(); + + /** + * Returns the wrapper class that is used to access version information of the remote + * partner of this proxy. + */ + virtual CommonAPI::InterfaceVersionAttribute& getInterfaceVersionAttribute(); + + private: + std::shared_ptr<TestFreedesktopDerivedInterfaceProxyBase> delegate_; +}; + +#ifdef WIN32 + typedef TestFreedesktopDerivedInterfaceProxy<CommonAPI::WINDummyAttributeExtension<CommonAPI::WINDummyAttribute>> TestFreedesktopDerivedInterfaceProxyDefault; +#else + typedef TestFreedesktopDerivedInterfaceProxy<> TestFreedesktopDerivedInterfaceProxyDefault; +#endif + +namespace TestFreedesktopDerivedInterfaceExtensions { + template <template <typename > class _ExtensionType> + class TestAttributedFromDerivedInterfaceAttributeExtension { + public: + typedef _ExtensionType<TestFreedesktopDerivedInterfaceProxyBase::TestAttributedFromDerivedInterfaceAttribute> extension_type; + + static_assert(std::is_base_of<typename CommonAPI::AttributeExtension<TestFreedesktopDerivedInterfaceProxyBase::TestAttributedFromDerivedInterfaceAttribute>, extension_type>::value, + "Not CommonAPI Attribute Extension!"); + #ifdef WIN32 + TestAttributedFromDerivedInterfaceAttributeExtension() {} + #endif + + TestAttributedFromDerivedInterfaceAttributeExtension(TestFreedesktopDerivedInterfaceProxyBase& proxy): attributeExtension_(proxy.getTestAttributedFromDerivedInterfaceAttribute()) { + } + + inline extension_type& getTestAttributedFromDerivedInterfaceAttributeExtension() { + return attributeExtension_; + } + + private: + extension_type attributeExtension_; + }; + +} // namespace TestFreedesktopDerivedInterfaceExtensions + +// +// TestFreedesktopDerivedInterfaceProxy Implementation +// +template <typename ... _AttributeExtensions> +TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::TestFreedesktopDerivedInterfaceProxy(std::shared_ptr<CommonAPI::Proxy> delegate): + TestFreedesktopInterfaceProxy<_AttributeExtensions...>(delegate), + _AttributeExtensions(*(std::dynamic_pointer_cast<TestFreedesktopDerivedInterfaceProxyBase>(delegate)))..., + delegate_(std::dynamic_pointer_cast<TestFreedesktopDerivedInterfaceProxyBase>(delegate)) { +} + +template <typename ... _AttributeExtensions> +TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::~TestFreedesktopDerivedInterfaceProxy() { +} + + +template <typename ... _AttributeExtensions> +std::string TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::getAddress() const { + return delegate_->getAddress(); +} + +template <typename ... _AttributeExtensions> +const std::string& TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::getDomain() const { + return delegate_->getDomain(); +} + +template <typename ... _AttributeExtensions> +const std::string& TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::getServiceId() const { + return delegate_->getServiceId(); +} + +template <typename ... _AttributeExtensions> +const std::string& TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::getInstanceId() const { + return delegate_->getInstanceId(); +} + +template <typename ... _AttributeExtensions> +bool TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::isAvailable() const { + return delegate_->isAvailable(); +} + +template <typename ... _AttributeExtensions> +bool TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::isAvailableBlocking() const { + return delegate_->isAvailableBlocking(); +} + +template <typename ... _AttributeExtensions> +CommonAPI::ProxyStatusEvent& TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::getProxyStatusEvent() { + return delegate_->getProxyStatusEvent(); +} + +template <typename ... _AttributeExtensions> +CommonAPI::InterfaceVersionAttribute& TestFreedesktopDerivedInterfaceProxy<_AttributeExtensions...>::getInterfaceVersionAttribute() { + return delegate_->getInterfaceVersionAttribute(); +} + + +} // namespace tests +} // namespace commonapi + +namespace CommonAPI { +template<template<typename > class _AttributeExtension> +struct DefaultAttributeProxyFactoryHelper<commonapi::tests::TestFreedesktopDerivedInterfaceProxy, + _AttributeExtension> { + typedef typename commonapi::tests::TestFreedesktopDerivedInterfaceProxy< + commonapi::tests::TestFreedesktopDerivedInterfaceExtensions::TestAttributedFromDerivedInterfaceAttributeExtension<_AttributeExtension> + > class_t; +}; +} + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_PROXY_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceProxyBase.h b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceProxyBase.h new file mode 100644 index 0000000..97a3c0f --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceProxyBase.h @@ -0,0 +1,44 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_PROXY_BASE_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_PROXY_BASE_H_ + +#include "TestFreedesktopDerivedInterface.h" +#include "TestFreedesktopInterfaceProxyBase.h" + + + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + + +#include <CommonAPI/Attribute.h> +#include <CommonAPI/Proxy.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +class TestFreedesktopDerivedInterfaceProxyBase: virtual public TestFreedesktopInterfaceProxyBase { + public: + typedef CommonAPI::ObservableAttribute<uint32_t> TestAttributedFromDerivedInterfaceAttribute; + + + virtual TestAttributedFromDerivedInterfaceAttribute& getTestAttributedFromDerivedInterfaceAttribute() = 0; + + +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_PROXY_BASE_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStub.h b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStub.h new file mode 100644 index 0000000..c81a7d2 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStub.h @@ -0,0 +1,102 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_STUB_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_STUB_H_ + + + +#include <commonapi/tests/TestFreedesktopInterfaceStub.h> + +#include "TestFreedesktopDerivedInterface.h" + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + + +#include <CommonAPI/Stub.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +/** + * Receives messages from remote and handles all dispatching of deserialized calls + * to a stub for the service TestFreedesktopDerivedInterface. Also provides means to send broadcasts + * and attribute-changed-notifications of observable attributes as defined by this service. + * An application developer should not need to bother with this class. + */ +class TestFreedesktopDerivedInterfaceStubAdapter: virtual public CommonAPI::StubAdapter, public TestFreedesktopDerivedInterface, public virtual TestFreedesktopInterfaceStubAdapter { + public: + ///Notifies all remote listeners about a change of value of the attribute TestAttributedFromDerivedInterface. + virtual void fireTestAttributedFromDerivedInterfaceAttributeChanged(const uint32_t& TestAttributedFromDerivedInterface) = 0; + + + + virtual void deactivateManagedInstances() = 0; +protected: + /** + * Defines properties for storing the ClientIds of clients / proxies that have + * subscribed to the selective broadcasts + */ +}; + + +/** + * Defines the necessary callbacks to handle remote set events related to the attributes + * defined in the IDL description for TestFreedesktopDerivedInterface. + * For each attribute two callbacks are defined: + * - a verification callback that allows to verify the requested value and to prevent setting + * e.g. an invalid value ("onRemoteSet<AttributeName>"). + * - an action callback to do local work after the attribute value has been changed + * ("onRemote<AttributeName>Changed"). + * + * This class and the one below are the ones an application developer needs to have + * a look at if he wants to implement a service. + */ +class TestFreedesktopDerivedInterfaceStubRemoteEvent: public virtual TestFreedesktopInterfaceStubRemoteEvent { + public: + virtual ~TestFreedesktopDerivedInterfaceStubRemoteEvent() { } + + /// Verification callback for remote set requests on the attribute TestAttributedFromDerivedInterface + virtual bool onRemoteSetTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t TestAttributedFromDerivedInterface) = 0; + /// Action callback for remote set requests on the attribute TestAttributedFromDerivedInterface + virtual void onRemoteTestAttributedFromDerivedInterfaceAttributeChanged() = 0; + +}; + + +/** + * Defines the interface that must be implemented by any class that should provide + * the service TestFreedesktopDerivedInterface to remote clients. + * This class and the one above are the ones an application developer needs to have + * a look at if he wants to implement a service. + */ +class TestFreedesktopDerivedInterfaceStub: public virtual CommonAPI::Stub<TestFreedesktopDerivedInterfaceStubAdapter, TestFreedesktopDerivedInterfaceStubRemoteEvent>, public virtual TestFreedesktopInterfaceStub { +public: + virtual ~TestFreedesktopDerivedInterfaceStub() { } + virtual const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + + /// Provides getter access to the attribute TestAttributedFromDerivedInterface + virtual const uint32_t& getTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + + + using CommonAPI::Stub<TestFreedesktopDerivedInterfaceStubAdapter, TestFreedesktopDerivedInterfaceStubRemoteEvent>::initStubAdapter; + typedef CommonAPI::Stub<TestFreedesktopDerivedInterfaceStubAdapter, TestFreedesktopDerivedInterfaceStubRemoteEvent>::StubAdapterType StubAdapterType; + typedef CommonAPI::Stub<TestFreedesktopDerivedInterfaceStubAdapter, TestFreedesktopDerivedInterfaceStubRemoteEvent>::RemoteEventHandlerType RemoteEventHandlerType; + typedef TestFreedesktopDerivedInterfaceStubRemoteEvent RemoteEventType; + typedef TestFreedesktopDerivedInterface StubInterface; +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_STUB_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.cpp b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.cpp new file mode 100644 index 0000000..44ef5a0 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.cpp @@ -0,0 +1,88 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#include <commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.h> + +namespace commonapi { +namespace tests { + +TestFreedesktopDerivedInterfaceStubDefault::TestFreedesktopDerivedInterfaceStubDefault(): + remoteEventHandler_(this), + interfaceVersion_(TestFreedesktopDerivedInterface::getInterfaceVersion()) { +} + +const CommonAPI::Version& TestFreedesktopDerivedInterfaceStubDefault::getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId) { + return interfaceVersion_; +} + +TestFreedesktopDerivedInterfaceStubRemoteEvent* TestFreedesktopDerivedInterfaceStubDefault::initStubAdapter(const std::shared_ptr<TestFreedesktopDerivedInterfaceStubAdapter>& stubAdapter) { + TestFreedesktopInterfaceStubDefault::initStubAdapter(stubAdapter); + CommonAPI::Stub<TestFreedesktopDerivedInterfaceStubAdapter, TestFreedesktopDerivedInterfaceStubRemoteEvent>::stubAdapter_ = stubAdapter; + return &remoteEventHandler_; +} + +const uint32_t& TestFreedesktopDerivedInterfaceStubDefault::getTestAttributedFromDerivedInterfaceAttribute() { + return testAttributedFromDerivedInterfaceAttributeValue_; +} + +const uint32_t& TestFreedesktopDerivedInterfaceStubDefault::getTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) { + return getTestAttributedFromDerivedInterfaceAttribute(); +} + +void TestFreedesktopDerivedInterfaceStubDefault::setTestAttributedFromDerivedInterfaceAttribute(uint32_t value) { + const bool valueChanged = trySetTestAttributedFromDerivedInterfaceAttribute(std::move(value)); + if (valueChanged) { + CommonAPI::Stub<TestFreedesktopDerivedInterfaceStubAdapter, TestFreedesktopDerivedInterfaceStubRemoteEvent>::stubAdapter_->fireTestAttributedFromDerivedInterfaceAttributeChanged(testAttributedFromDerivedInterfaceAttributeValue_); + } +} + +bool TestFreedesktopDerivedInterfaceStubDefault::trySetTestAttributedFromDerivedInterfaceAttribute(uint32_t value) { + if (!validateTestAttributedFromDerivedInterfaceAttributeRequestedValue(value)) + return false; + + const bool valueChanged = (testAttributedFromDerivedInterfaceAttributeValue_ != value); + testAttributedFromDerivedInterfaceAttributeValue_ = std::move(value); + return valueChanged; +} + +bool TestFreedesktopDerivedInterfaceStubDefault::validateTestAttributedFromDerivedInterfaceAttributeRequestedValue(const uint32_t& value) { + return true; +} + +void TestFreedesktopDerivedInterfaceStubDefault::setTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value) { + setTestAttributedFromDerivedInterfaceAttribute(value); +} + +void TestFreedesktopDerivedInterfaceStubDefault::onRemoteTestAttributedFromDerivedInterfaceAttributeChanged() { + // No operation in default +} + +void TestFreedesktopDerivedInterfaceStubDefault::RemoteEventHandler::onRemoteTestAttributedFromDerivedInterfaceAttributeChanged() { + defaultStub_->onRemoteTestAttributedFromDerivedInterfaceAttributeChanged(); +} + +bool TestFreedesktopDerivedInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestAttributedFromDerivedInterfaceAttribute(uint32_t value) { + return defaultStub_->trySetTestAttributedFromDerivedInterfaceAttribute(std::move(value)); +} + +bool TestFreedesktopDerivedInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value) { + return onRemoteSetTestAttributedFromDerivedInterfaceAttribute(value); +} + + + + + +TestFreedesktopDerivedInterfaceStubDefault::RemoteEventHandler::RemoteEventHandler(TestFreedesktopDerivedInterfaceStubDefault* defaultStub): + TestFreedesktopInterfaceStubDefault::RemoteEventHandler(defaultStub), + defaultStub_(defaultStub) { +} + +} // namespace tests +} // namespace commonapi diff --git a/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.h b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.h new file mode 100644 index 0000000..22f88d5 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopDerivedInterfaceStubDefault.h @@ -0,0 +1,74 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_STUB_DEFAULT_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_STUB_DEFAULT_H_ + +#include <commonapi/tests/TestFreedesktopInterfaceStubDefault.h> + +#include <commonapi/tests/TestFreedesktopDerivedInterfaceStub.h> +#include <sstream> + +namespace commonapi { +namespace tests { + +/** + * Provides a default implementation for TestFreedesktopDerivedInterfaceStubRemoteEvent and + * TestFreedesktopDerivedInterfaceStub. Method callbacks have an empty implementation, + * remote set calls on attributes will always change the value of the attribute + * to the one received. + * + * Override this stub if you only want to provide a subset of the functionality + * that would be defined for this service, and/or if you do not need any non-default + * behaviour. + */ +class TestFreedesktopDerivedInterfaceStubDefault : public virtual TestFreedesktopDerivedInterfaceStub, public virtual TestFreedesktopInterfaceStubDefault { +public: + TestFreedesktopDerivedInterfaceStubDefault(); + + TestFreedesktopDerivedInterfaceStubRemoteEvent* initStubAdapter(const std::shared_ptr<TestFreedesktopDerivedInterfaceStubAdapter>& stubAdapter); + + const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId); + + virtual const uint32_t& getTestAttributedFromDerivedInterfaceAttribute(); + virtual const uint32_t& getTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId); + virtual void setTestAttributedFromDerivedInterfaceAttribute(uint32_t value); + virtual void setTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value); + + + + +protected: + virtual bool trySetTestAttributedFromDerivedInterfaceAttribute(uint32_t value); + virtual bool validateTestAttributedFromDerivedInterfaceAttributeRequestedValue(const uint32_t& value); + virtual void onRemoteTestAttributedFromDerivedInterfaceAttributeChanged(); + class RemoteEventHandler: public virtual TestFreedesktopDerivedInterfaceStubRemoteEvent, public virtual TestFreedesktopInterfaceStubDefault::RemoteEventHandler { + public: + RemoteEventHandler(TestFreedesktopDerivedInterfaceStubDefault* defaultStub); + + virtual bool onRemoteSetTestAttributedFromDerivedInterfaceAttribute(uint32_t value); + virtual bool onRemoteSetTestAttributedFromDerivedInterfaceAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value); + virtual void onRemoteTestAttributedFromDerivedInterfaceAttributeChanged(); + + + private: + TestFreedesktopDerivedInterfaceStubDefault* defaultStub_; + }; +private: + TestFreedesktopDerivedInterfaceStubDefault::RemoteEventHandler remoteEventHandler_; + + uint32_t testAttributedFromDerivedInterfaceAttributeValue_; + + CommonAPI::Version interfaceVersion_; +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Derived_Interface_STUB_DEFAULT_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopInterface.h b/src/test/commonapi/tests/TestFreedesktopInterface.h new file mode 100644 index 0000000..7b97b15 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterface.h @@ -0,0 +1,59 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Interface_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Interface_H_ + + + + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/types.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +class TestFreedesktopInterface { + public: + virtual ~TestFreedesktopInterface() { } + + static inline const char* getInterfaceId(); + static inline CommonAPI::Version getInterfaceVersion(); +}; + +const char* TestFreedesktopInterface::getInterfaceId() { + static const char* interfaceId = "commonapi.tests.TestFreedesktopInterface"; + return interfaceId; +} + +CommonAPI::Version TestFreedesktopInterface::getInterfaceVersion() { + return CommonAPI::Version(1, 0); +} + + +} // namespace tests +} // namespace commonapi + +namespace CommonAPI { + +} + + +namespace std { + //hashes for types + + //hashes for error types +} + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Interface_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceDBusProxy.cpp b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusProxy.cpp new file mode 100644 index 0000000..ad98cec --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusProxy.cpp @@ -0,0 +1,68 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#include "TestFreedesktopInterfaceDBusProxy.h" + +namespace commonapi { +namespace tests { + +std::shared_ptr<CommonAPI::DBus::DBusProxy> createTestFreedesktopInterfaceDBusProxy( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection) { + return std::make_shared<TestFreedesktopInterfaceDBusProxy>(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection); +} + +INITIALIZER(registerTestFreedesktopInterfaceDBusProxy) { + CommonAPI::DBus::DBusFactory::registerProxyFactoryMethod(TestFreedesktopInterface::getInterfaceId(), + &createTestFreedesktopInterfaceDBusProxy); +} + +TestFreedesktopInterfaceDBusProxy::TestFreedesktopInterfaceDBusProxy( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection): + CommonAPI::DBus::DBusProxy(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyconnection) +,testPredefinedTypeAttribute_(*this, interfaceName.c_str(), "TestPredefinedTypeAttribute"), +testReadonlyAttribute_(*this, interfaceName.c_str(), "TestReadonlyAttribute"), +testDerivedStructAttribute_(*this, interfaceName.c_str(), "TestDerivedStructAttribute"), +testDerivedArrayAttribute_(*this, interfaceName.c_str(), "TestDerivedArrayAttribute") + { + } + +TestFreedesktopInterfaceDBusProxy::TestPredefinedTypeAttributeAttribute& TestFreedesktopInterfaceDBusProxy::getTestPredefinedTypeAttributeAttribute() { + return testPredefinedTypeAttribute_; +} +TestFreedesktopInterfaceDBusProxy::TestReadonlyAttributeAttribute& TestFreedesktopInterfaceDBusProxy::getTestReadonlyAttributeAttribute() { + return testReadonlyAttribute_; +} +TestFreedesktopInterfaceDBusProxy::TestDerivedStructAttributeAttribute& TestFreedesktopInterfaceDBusProxy::getTestDerivedStructAttributeAttribute() { + return testDerivedStructAttribute_; +} +TestFreedesktopInterfaceDBusProxy::TestDerivedArrayAttributeAttribute& TestFreedesktopInterfaceDBusProxy::getTestDerivedArrayAttributeAttribute() { + return testDerivedArrayAttribute_; +} + + + + + +void TestFreedesktopInterfaceDBusProxy::getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const { + ownVersionMajor = 1; + ownVersionMinor = 0; +} + +} // namespace tests +} // namespace commonapi diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceDBusProxy.h b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusProxy.h new file mode 100644 index 0000000..869fa29 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusProxy.h @@ -0,0 +1,66 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Interface_DBUS_PROXY_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Interface_DBUS_PROXY_H_ + +#include <commonapi/tests/TestFreedesktopInterfaceProxyBase.h> + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/DBus/DBusFactory.h> +#include <CommonAPI/DBus/DBusProxy.h> +#include <CommonAPI/DBus/DBusAttribute.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +#include <string> + +namespace commonapi { +namespace tests { + +class TestFreedesktopInterfaceDBusProxy: virtual public TestFreedesktopInterfaceProxyBase, virtual public CommonAPI::DBus::DBusProxy { + public: + TestFreedesktopInterfaceDBusProxy( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyconnection); + + virtual ~TestFreedesktopInterfaceDBusProxy() { } + + virtual TestPredefinedTypeAttributeAttribute& getTestPredefinedTypeAttributeAttribute(); + virtual TestReadonlyAttributeAttribute& getTestReadonlyAttributeAttribute(); + virtual TestDerivedStructAttributeAttribute& getTestDerivedStructAttributeAttribute(); + virtual TestDerivedArrayAttributeAttribute& getTestDerivedArrayAttributeAttribute(); + + + + + virtual void getOwnVersion(uint16_t& ownVersionMajor, uint16_t& ownVersionMinor) const; + + private: + CommonAPI::DBus::DBusFreedesktopObservableAttribute<CommonAPI::DBus::DBusFreedesktopAttribute<TestPredefinedTypeAttributeAttribute>> testPredefinedTypeAttribute_; + CommonAPI::DBus::DBusFreedesktopObservableAttribute<CommonAPI::DBus::DBusFreedesktopReadonlyAttribute<TestReadonlyAttributeAttribute>> testReadonlyAttribute_; + CommonAPI::DBus::DBusFreedesktopObservableAttribute<CommonAPI::DBus::DBusFreedesktopAttribute<TestDerivedStructAttributeAttribute>> testDerivedStructAttribute_; + CommonAPI::DBus::DBusFreedesktopObservableAttribute<CommonAPI::DBus::DBusFreedesktopAttribute<TestDerivedArrayAttributeAttribute>> testDerivedArrayAttribute_; + + +}; + + + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Interface_DBUS_PROXY_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.cpp new file mode 100644 index 0000000..22317d2 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.cpp @@ -0,0 +1,219 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#include "TestFreedesktopInterfaceDBusStubAdapter.h" +#include <commonapi/tests/TestFreedesktopInterface.h> + +namespace commonapi { +namespace tests { + +std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createTestFreedesktopInterfaceDBusStubAdapter( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& interfaceName, + const std::string& busName, + const std::string& objectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection, + const std::shared_ptr<CommonAPI::StubBase>& stubBase) { + return std::make_shared<TestFreedesktopInterfaceDBusStubAdapter>(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection, stubBase); +} + +INITIALIZER(registerTestFreedesktopInterfaceDBusStubAdapter) { + CommonAPI::DBus::DBusFactory::registerAdapterFactoryMethod(TestFreedesktopInterface::getInterfaceId(), + &createTestFreedesktopInterfaceDBusStubAdapter); +} + + + +TestFreedesktopInterfaceDBusStubAdapterInternal::~TestFreedesktopInterfaceDBusStubAdapterInternal() { + deactivateManagedInstances(); + TestFreedesktopInterfaceDBusStubAdapterHelper::deinit(); +} + +void TestFreedesktopInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { + +} + +const char* TestFreedesktopInterfaceDBusStubAdapterInternal::getMethodsDBusIntrospectionXmlData() const { + static const std::string introspectionData = + "<method name=\"getInterfaceVersion\">\n" + "<arg name=\"value\" type=\"uu\" direction=\"out\" />" + "</method>\n" + "<property name=\"TestPredefinedTypeAttribute\" type=\"u\" access=\"readwrite\" />\n" + "<property name=\"TestReadonlyAttribute\" type=\"u\" access=\"read\" />\n" + "<property name=\"TestDerivedStructAttribute\" type=\"(sqi)\" access=\"readwrite\" />\n" + "<property name=\"TestDerivedArrayAttribute\" type=\"at\" access=\"readwrite\" />\n" + + ; + return introspectionData.c_str(); +} + +CommonAPI::DBus::DBusGetAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + CommonAPI::Version + > TestFreedesktopInterfaceDBusStubAdapterInternal::getTestFreedesktopInterfaceInterfaceVersionStubDispatcher(&TestFreedesktopInterfaceStub::getInterfaceVersion, "uu"); + +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + uint32_t + > TestFreedesktopInterfaceDBusStubAdapterInternal::getTestPredefinedTypeAttributeAttributeStubDispatcher(&TestFreedesktopInterfaceStub::getTestPredefinedTypeAttributeAttribute); +CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + uint32_t + > TestFreedesktopInterfaceDBusStubAdapterInternal::setTestPredefinedTypeAttributeAttributeStubDispatcher( + &TestFreedesktopInterfaceStub::getTestPredefinedTypeAttributeAttribute, + &TestFreedesktopInterfaceStubRemoteEvent::onRemoteSetTestPredefinedTypeAttributeAttribute, + &TestFreedesktopInterfaceStubRemoteEvent::onRemoteTestPredefinedTypeAttributeAttributeChanged + ,&TestFreedesktopInterfaceStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged + ); +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + uint32_t + > TestFreedesktopInterfaceDBusStubAdapterInternal::getTestReadonlyAttributeAttributeStubDispatcher(&TestFreedesktopInterfaceStub::getTestReadonlyAttributeAttribute); +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestStructExtended + > TestFreedesktopInterfaceDBusStubAdapterInternal::getTestDerivedStructAttributeAttributeStubDispatcher(&TestFreedesktopInterfaceStub::getTestDerivedStructAttributeAttribute); +CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestStructExtended + > TestFreedesktopInterfaceDBusStubAdapterInternal::setTestDerivedStructAttributeAttributeStubDispatcher( + &TestFreedesktopInterfaceStub::getTestDerivedStructAttributeAttribute, + &TestFreedesktopInterfaceStubRemoteEvent::onRemoteSetTestDerivedStructAttributeAttribute, + &TestFreedesktopInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged + ,&TestFreedesktopInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged + ); +CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > TestFreedesktopInterfaceDBusStubAdapterInternal::getTestDerivedArrayAttributeAttributeStubDispatcher(&TestFreedesktopInterfaceStub::getTestDerivedArrayAttributeAttribute); +CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > TestFreedesktopInterfaceDBusStubAdapterInternal::setTestDerivedArrayAttributeAttributeStubDispatcher( + &TestFreedesktopInterfaceStub::getTestDerivedArrayAttributeAttribute, + &TestFreedesktopInterfaceStubRemoteEvent::onRemoteSetTestDerivedArrayAttributeAttribute, + &TestFreedesktopInterfaceStubRemoteEvent::onRemoteTestDerivedArrayAttributeAttributeChanged + ,&TestFreedesktopInterfaceStubAdapter::fireTestDerivedArrayAttributeAttributeChanged + ); + + + + +void TestFreedesktopInterfaceDBusStubAdapterInternal::fireTestPredefinedTypeAttributeAttributeChanged(const uint32_t& value) { + CommonAPI::DBus::DBusStubFreedesktopPropertiesSignalHelper<CommonAPI::DBus::DBusSerializableArguments<uint32_t>> + ::sendPropertiesChangedSignal( + *this, + "TestPredefinedTypeAttribute", + value + ); +} +void TestFreedesktopInterfaceDBusStubAdapterInternal::fireTestReadonlyAttributeAttributeChanged(const uint32_t& value) { + CommonAPI::DBus::DBusStubFreedesktopPropertiesSignalHelper<CommonAPI::DBus::DBusSerializableArguments<uint32_t>> + ::sendPropertiesChangedSignal( + *this, + "TestReadonlyAttribute", + value + ); +} +void TestFreedesktopInterfaceDBusStubAdapterInternal::fireTestDerivedStructAttributeAttributeChanged(const DerivedTypeCollection::TestStructExtended& value) { + CommonAPI::DBus::DBusStubFreedesktopPropertiesSignalHelper<CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestStructExtended>> + ::sendPropertiesChangedSignal( + *this, + "TestDerivedStructAttribute", + value + ); +} +void TestFreedesktopInterfaceDBusStubAdapterInternal::fireTestDerivedArrayAttributeAttributeChanged(const DerivedTypeCollection::TestArrayUInt64& value) { + CommonAPI::DBus::DBusStubFreedesktopPropertiesSignalHelper<CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestArrayUInt64>> + ::sendPropertiesChangedSignal( + *this, + "TestDerivedArrayAttribute", + value + ); +} + + + +const TestFreedesktopInterfaceDBusStubAdapterHelper::StubDispatcherTable& TestFreedesktopInterfaceDBusStubAdapterInternal::getStubDispatcherTable() { + return stubDispatcherTable_; +} + +const CommonAPI::DBus::StubAttributeTable& TestFreedesktopInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; +} + +TestFreedesktopInterfaceDBusStubAdapterInternal::TestFreedesktopInterfaceDBusStubAdapterInternal( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& dbusInterfaceName, + const std::string& dbusBusName, + const std::string& dbusObjectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection, + const std::shared_ptr<CommonAPI::StubBase>& stub): + CommonAPI::DBus::DBusStubAdapter( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + false), + TestFreedesktopInterfaceDBusStubAdapterHelper( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + std::dynamic_pointer_cast<TestFreedesktopInterfaceStub>(stub), + false), + stubDispatcherTable_({ + }), + stubAttributeTable_({ + { + "TestPredefinedTypeAttribute", + { + &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::getTestPredefinedTypeAttributeAttributeStubDispatcher, + &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::setTestPredefinedTypeAttributeAttributeStubDispatcher + } + }, + { + "TestReadonlyAttribute", + { + &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::getTestReadonlyAttributeAttributeStubDispatcher, + NULL + } + }, + { + "TestDerivedStructAttribute", + { + &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::getTestDerivedStructAttributeAttributeStubDispatcher, + &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::setTestDerivedStructAttributeAttributeStubDispatcher + } + }, + { + "TestDerivedArrayAttribute", + { + &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::getTestDerivedArrayAttributeAttributeStubDispatcher, + &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::setTestDerivedArrayAttributeAttributeStubDispatcher + } + } + } + ) { + + stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::TestFreedesktopInterfaceDBusStubAdapterInternal::getTestFreedesktopInterfaceInterfaceVersionStubDispatcher }); +} + +const bool TestFreedesktopInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return true; +} + +} // namespace tests +} // namespace commonapi diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.h new file mode 100644 index 0000000..23c94bb --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceDBusStubAdapter.h @@ -0,0 +1,137 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Interface_DBUS_STUB_ADAPTER_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Interface_DBUS_STUB_ADAPTER_H_ + +#include <commonapi/tests/TestFreedesktopInterfaceStub.h> + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/DBus/DBusStubAdapterHelper.h> +#include <CommonAPI/DBus/DBusStubAdapter.h> +#include <CommonAPI/DBus/DBusFactory.h> +#include <CommonAPI/DBus/DBusServicePublisher.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +typedef CommonAPI::DBus::DBusStubAdapterHelper<TestFreedesktopInterfaceStub> TestFreedesktopInterfaceDBusStubAdapterHelper; + +class TestFreedesktopInterfaceDBusStubAdapterInternal: public virtual TestFreedesktopInterfaceStubAdapter, public TestFreedesktopInterfaceDBusStubAdapterHelper { + public: + TestFreedesktopInterfaceDBusStubAdapterInternal( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& dbusInterfaceName, + const std::string& dbusBusName, + const std::string& dbusObjectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection, + const std::shared_ptr<CommonAPI::StubBase>& stub); + + ~TestFreedesktopInterfaceDBusStubAdapterInternal(); + + virtual const bool hasFreedesktopProperties(); + + void fireTestPredefinedTypeAttributeAttributeChanged(const uint32_t& value); + void fireTestReadonlyAttributeAttributeChanged(const uint32_t& value); + void fireTestDerivedStructAttributeAttributeChanged(const DerivedTypeCollection::TestStructExtended& value); + void fireTestDerivedArrayAttributeAttributeChanged(const DerivedTypeCollection::TestArrayUInt64& value); + + + + const TestFreedesktopInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); + + void deactivateManagedInstances(); + + +static CommonAPI::DBus::DBusGetAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + CommonAPI::Version + > getTestFreedesktopInterfaceInterfaceVersionStubDispatcher; + +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + uint32_t + > getTestPredefinedTypeAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + uint32_t + > setTestPredefinedTypeAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + uint32_t + > getTestReadonlyAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestStructExtended + > getTestDerivedStructAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestStructExtended + > setTestDerivedStructAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusGetFreedesktopAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > getTestDerivedArrayAttributeAttributeStubDispatcher; +static CommonAPI::DBus::DBusSetFreedesktopObservableAttributeStubDispatcher< + TestFreedesktopInterfaceStub, + DerivedTypeCollection::TestArrayUInt64 + > setTestDerivedArrayAttributeAttributeStubDispatcher; + + + + + + + protected: + virtual const char* getMethodsDBusIntrospectionXmlData() const; + + private: + TestFreedesktopInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; +}; + +class TestFreedesktopInterfaceDBusStubAdapter: public TestFreedesktopInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<TestFreedesktopInterfaceDBusStubAdapter> { +public: + TestFreedesktopInterfaceDBusStubAdapter( + const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, + const std::string& commonApiAddress, + const std::string& dbusInterfaceName, + const std::string& dbusBusName, + const std::string& dbusObjectPath, + const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection, + const std::shared_ptr<CommonAPI::StubBase>& stub) : + CommonAPI::DBus::DBusStubAdapter( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + false), + TestFreedesktopInterfaceDBusStubAdapterInternal( + factory, + commonApiAddress, + dbusInterfaceName, + dbusBusName, + dbusObjectPath, + dbusConnection, + stub) { } +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Interface_DBUS_STUB_ADAPTER_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceProxy.h b/src/test/commonapi/tests/TestFreedesktopInterfaceProxy.h new file mode 100644 index 0000000..0b4ce8d --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceProxy.h @@ -0,0 +1,280 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Interface_PROXY_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Interface_PROXY_H_ + +#include "TestFreedesktopInterfaceProxyBase.h" + + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <CommonAPI/AttributeExtension.h> +#include <CommonAPI/Factory.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +template <typename ... _AttributeExtensions> +class TestFreedesktopInterfaceProxy: virtual public TestFreedesktopInterface, virtual public TestFreedesktopInterfaceProxyBase +, public _AttributeExtensions... { +public: + TestFreedesktopInterfaceProxy(std::shared_ptr<CommonAPI::Proxy> delegate); + ~TestFreedesktopInterfaceProxy(); + + typedef TestFreedesktopInterface InterfaceType; + + + /** + * Returns the wrapper class that provides access to the attribute TestPredefinedTypeAttribute. + */ + virtual TestPredefinedTypeAttributeAttribute& getTestPredefinedTypeAttributeAttribute() { + return delegate_->getTestPredefinedTypeAttributeAttribute(); + } + /** + * Returns the wrapper class that provides access to the attribute TestReadonlyAttribute. + */ + virtual TestReadonlyAttributeAttribute& getTestReadonlyAttributeAttribute() { + return delegate_->getTestReadonlyAttributeAttribute(); + } + /** + * Returns the wrapper class that provides access to the attribute TestDerivedStructAttribute. + */ + virtual TestDerivedStructAttributeAttribute& getTestDerivedStructAttributeAttribute() { + return delegate_->getTestDerivedStructAttributeAttribute(); + } + /** + * Returns the wrapper class that provides access to the attribute TestDerivedArrayAttribute. + */ + virtual TestDerivedArrayAttributeAttribute& getTestDerivedArrayAttributeAttribute() { + return delegate_->getTestDerivedArrayAttributeAttribute(); + } + + + + + /** + * Returns the CommonAPI address of the remote partner this proxy communicates with. + */ + virtual std::string getAddress() const; + + /** + * Returns the domain of the remote partner this proxy communicates with. + */ + virtual const std::string& getDomain() const; + + /** + * Returns the service ID of the remote partner this proxy communicates with. + */ + virtual const std::string& getServiceId() const; + + /** + * Returns the instance ID of the remote partner this proxy communicates with. + */ + virtual const std::string& getInstanceId() const; + + /** + * Returns true if the remote partner for this proxy is currently known to be available. + */ + virtual bool isAvailable() const; + + /** + * Returns true if the remote partner for this proxy is available. + */ + virtual bool isAvailableBlocking() const; + + /** + * Returns the wrapper class that is used to (de-)register for notifications about + * the availability of the remote partner of this proxy. + */ + virtual CommonAPI::ProxyStatusEvent& getProxyStatusEvent(); + + /** + * Returns the wrapper class that is used to access version information of the remote + * partner of this proxy. + */ + virtual CommonAPI::InterfaceVersionAttribute& getInterfaceVersionAttribute(); + + private: + std::shared_ptr<TestFreedesktopInterfaceProxyBase> delegate_; +}; + +#ifdef WIN32 + typedef TestFreedesktopInterfaceProxy<CommonAPI::WINDummyAttributeExtension<CommonAPI::WINDummyAttribute>> TestFreedesktopInterfaceProxyDefault; +#else + typedef TestFreedesktopInterfaceProxy<> TestFreedesktopInterfaceProxyDefault; +#endif + +namespace TestFreedesktopInterfaceExtensions { + template <template <typename > class _ExtensionType> + class TestPredefinedTypeAttributeAttributeExtension { + public: + typedef _ExtensionType<TestFreedesktopInterfaceProxyBase::TestPredefinedTypeAttributeAttribute> extension_type; + + static_assert(std::is_base_of<typename CommonAPI::AttributeExtension<TestFreedesktopInterfaceProxyBase::TestPredefinedTypeAttributeAttribute>, extension_type>::value, + "Not CommonAPI Attribute Extension!"); + #ifdef WIN32 + TestPredefinedTypeAttributeAttributeExtension() {} + #endif + + TestPredefinedTypeAttributeAttributeExtension(TestFreedesktopInterfaceProxyBase& proxy): attributeExtension_(proxy.getTestPredefinedTypeAttributeAttribute()) { + } + + inline extension_type& getTestPredefinedTypeAttributeAttributeExtension() { + return attributeExtension_; + } + + private: + extension_type attributeExtension_; + }; + + template <template <typename > class _ExtensionType> + class TestReadonlyAttributeAttributeExtension { + public: + typedef _ExtensionType<TestFreedesktopInterfaceProxyBase::TestReadonlyAttributeAttribute> extension_type; + + static_assert(std::is_base_of<typename CommonAPI::AttributeExtension<TestFreedesktopInterfaceProxyBase::TestReadonlyAttributeAttribute>, extension_type>::value, + "Not CommonAPI Attribute Extension!"); + #ifdef WIN32 + TestReadonlyAttributeAttributeExtension() {} + #endif + + TestReadonlyAttributeAttributeExtension(TestFreedesktopInterfaceProxyBase& proxy): attributeExtension_(proxy.getTestReadonlyAttributeAttribute()) { + } + + inline extension_type& getTestReadonlyAttributeAttributeExtension() { + return attributeExtension_; + } + + private: + extension_type attributeExtension_; + }; + + template <template <typename > class _ExtensionType> + class TestDerivedStructAttributeAttributeExtension { + public: + typedef _ExtensionType<TestFreedesktopInterfaceProxyBase::TestDerivedStructAttributeAttribute> extension_type; + + static_assert(std::is_base_of<typename CommonAPI::AttributeExtension<TestFreedesktopInterfaceProxyBase::TestDerivedStructAttributeAttribute>, extension_type>::value, + "Not CommonAPI Attribute Extension!"); + #ifdef WIN32 + TestDerivedStructAttributeAttributeExtension() {} + #endif + + TestDerivedStructAttributeAttributeExtension(TestFreedesktopInterfaceProxyBase& proxy): attributeExtension_(proxy.getTestDerivedStructAttributeAttribute()) { + } + + inline extension_type& getTestDerivedStructAttributeAttributeExtension() { + return attributeExtension_; + } + + private: + extension_type attributeExtension_; + }; + + template <template <typename > class _ExtensionType> + class TestDerivedArrayAttributeAttributeExtension { + public: + typedef _ExtensionType<TestFreedesktopInterfaceProxyBase::TestDerivedArrayAttributeAttribute> extension_type; + + static_assert(std::is_base_of<typename CommonAPI::AttributeExtension<TestFreedesktopInterfaceProxyBase::TestDerivedArrayAttributeAttribute>, extension_type>::value, + "Not CommonAPI Attribute Extension!"); + #ifdef WIN32 + TestDerivedArrayAttributeAttributeExtension() {} + #endif + + TestDerivedArrayAttributeAttributeExtension(TestFreedesktopInterfaceProxyBase& proxy): attributeExtension_(proxy.getTestDerivedArrayAttributeAttribute()) { + } + + inline extension_type& getTestDerivedArrayAttributeAttributeExtension() { + return attributeExtension_; + } + + private: + extension_type attributeExtension_; + }; + +} // namespace TestFreedesktopInterfaceExtensions + +// +// TestFreedesktopInterfaceProxy Implementation +// +template <typename ... _AttributeExtensions> +TestFreedesktopInterfaceProxy<_AttributeExtensions...>::TestFreedesktopInterfaceProxy(std::shared_ptr<CommonAPI::Proxy> delegate): + _AttributeExtensions(*(std::dynamic_pointer_cast<TestFreedesktopInterfaceProxyBase>(delegate)))..., + delegate_(std::dynamic_pointer_cast<TestFreedesktopInterfaceProxyBase>(delegate)) { +} + +template <typename ... _AttributeExtensions> +TestFreedesktopInterfaceProxy<_AttributeExtensions...>::~TestFreedesktopInterfaceProxy() { +} + + +template <typename ... _AttributeExtensions> +std::string TestFreedesktopInterfaceProxy<_AttributeExtensions...>::getAddress() const { + return delegate_->getAddress(); +} + +template <typename ... _AttributeExtensions> +const std::string& TestFreedesktopInterfaceProxy<_AttributeExtensions...>::getDomain() const { + return delegate_->getDomain(); +} + +template <typename ... _AttributeExtensions> +const std::string& TestFreedesktopInterfaceProxy<_AttributeExtensions...>::getServiceId() const { + return delegate_->getServiceId(); +} + +template <typename ... _AttributeExtensions> +const std::string& TestFreedesktopInterfaceProxy<_AttributeExtensions...>::getInstanceId() const { + return delegate_->getInstanceId(); +} + +template <typename ... _AttributeExtensions> +bool TestFreedesktopInterfaceProxy<_AttributeExtensions...>::isAvailable() const { + return delegate_->isAvailable(); +} + +template <typename ... _AttributeExtensions> +bool TestFreedesktopInterfaceProxy<_AttributeExtensions...>::isAvailableBlocking() const { + return delegate_->isAvailableBlocking(); +} + +template <typename ... _AttributeExtensions> +CommonAPI::ProxyStatusEvent& TestFreedesktopInterfaceProxy<_AttributeExtensions...>::getProxyStatusEvent() { + return delegate_->getProxyStatusEvent(); +} + +template <typename ... _AttributeExtensions> +CommonAPI::InterfaceVersionAttribute& TestFreedesktopInterfaceProxy<_AttributeExtensions...>::getInterfaceVersionAttribute() { + return delegate_->getInterfaceVersionAttribute(); +} + + +} // namespace tests +} // namespace commonapi + +namespace CommonAPI { +template<template<typename > class _AttributeExtension> +struct DefaultAttributeProxyFactoryHelper<commonapi::tests::TestFreedesktopInterfaceProxy, + _AttributeExtension> { + typedef typename commonapi::tests::TestFreedesktopInterfaceProxy< + commonapi::tests::TestFreedesktopInterfaceExtensions::TestPredefinedTypeAttributeAttributeExtension<_AttributeExtension>, + commonapi::tests::TestFreedesktopInterfaceExtensions::TestReadonlyAttributeAttributeExtension<_AttributeExtension>, + commonapi::tests::TestFreedesktopInterfaceExtensions::TestDerivedStructAttributeAttributeExtension<_AttributeExtension>, + commonapi::tests::TestFreedesktopInterfaceExtensions::TestDerivedArrayAttributeAttributeExtension<_AttributeExtension> + > class_t; +}; +} + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Interface_PROXY_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceProxyBase.h b/src/test/commonapi/tests/TestFreedesktopInterfaceProxyBase.h new file mode 100644 index 0000000..417a157 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceProxyBase.h @@ -0,0 +1,52 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Interface_PROXY_BASE_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Interface_PROXY_BASE_H_ + +#include "TestFreedesktopInterface.h" + + +#include <commonapi/tests/DerivedTypeCollection.h> + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <cstdint> +#include <vector> + +#include <CommonAPI/Attribute.h> +#include <CommonAPI/Proxy.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +class TestFreedesktopInterfaceProxyBase: virtual public CommonAPI::Proxy { + public: + typedef CommonAPI::ObservableAttribute<uint32_t> TestPredefinedTypeAttributeAttribute; + typedef CommonAPI::ObservableReadonlyAttribute<uint32_t> TestReadonlyAttributeAttribute; + typedef CommonAPI::ObservableAttribute<DerivedTypeCollection::TestStructExtended> TestDerivedStructAttributeAttribute; + typedef CommonAPI::ObservableAttribute<DerivedTypeCollection::TestArrayUInt64> TestDerivedArrayAttributeAttribute; + + + virtual TestPredefinedTypeAttributeAttribute& getTestPredefinedTypeAttributeAttribute() = 0; + virtual TestReadonlyAttributeAttribute& getTestReadonlyAttributeAttribute() = 0; + virtual TestDerivedStructAttributeAttribute& getTestDerivedStructAttributeAttribute() = 0; + virtual TestDerivedArrayAttributeAttribute& getTestDerivedArrayAttributeAttribute() = 0; + + +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Interface_PROXY_BASE_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceStub.h b/src/test/commonapi/tests/TestFreedesktopInterfaceStub.h new file mode 100644 index 0000000..623c012 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceStub.h @@ -0,0 +1,127 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Interface_STUB_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Interface_STUB_H_ + + + +#include <commonapi/tests/DerivedTypeCollection.h> + +#include "TestFreedesktopInterface.h" + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#define COMMONAPI_INTERNAL_COMPILATION +#endif + +#include <cstdint> +#include <vector> + +#include <CommonAPI/Stub.h> + +#undef COMMONAPI_INTERNAL_COMPILATION + +namespace commonapi { +namespace tests { + +/** + * Receives messages from remote and handles all dispatching of deserialized calls + * to a stub for the service TestFreedesktopInterface. Also provides means to send broadcasts + * and attribute-changed-notifications of observable attributes as defined by this service. + * An application developer should not need to bother with this class. + */ +class TestFreedesktopInterfaceStubAdapter: virtual public CommonAPI::StubAdapter, public TestFreedesktopInterface { + public: + ///Notifies all remote listeners about a change of value of the attribute TestPredefinedTypeAttribute. + virtual void fireTestPredefinedTypeAttributeAttributeChanged(const uint32_t& TestPredefinedTypeAttribute) = 0; + ///Notifies all remote listeners about a change of value of the attribute TestReadonlyAttribute. + virtual void fireTestReadonlyAttributeAttributeChanged(const uint32_t& TestReadonlyAttribute) = 0; + ///Notifies all remote listeners about a change of value of the attribute TestDerivedStructAttribute. + virtual void fireTestDerivedStructAttributeAttributeChanged(const DerivedTypeCollection::TestStructExtended& TestDerivedStructAttribute) = 0; + ///Notifies all remote listeners about a change of value of the attribute TestDerivedArrayAttribute. + virtual void fireTestDerivedArrayAttributeAttributeChanged(const DerivedTypeCollection::TestArrayUInt64& TestDerivedArrayAttribute) = 0; + + + + virtual void deactivateManagedInstances() = 0; +protected: + /** + * Defines properties for storing the ClientIds of clients / proxies that have + * subscribed to the selective broadcasts + */ +}; + + +/** + * Defines the necessary callbacks to handle remote set events related to the attributes + * defined in the IDL description for TestFreedesktopInterface. + * For each attribute two callbacks are defined: + * - a verification callback that allows to verify the requested value and to prevent setting + * e.g. an invalid value ("onRemoteSet<AttributeName>"). + * - an action callback to do local work after the attribute value has been changed + * ("onRemote<AttributeName>Changed"). + * + * This class and the one below are the ones an application developer needs to have + * a look at if he wants to implement a service. + */ +class TestFreedesktopInterfaceStubRemoteEvent { + public: + virtual ~TestFreedesktopInterfaceStubRemoteEvent() { } + + /// Verification callback for remote set requests on the attribute TestPredefinedTypeAttribute + virtual bool onRemoteSetTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t TestPredefinedTypeAttribute) = 0; + /// Action callback for remote set requests on the attribute TestPredefinedTypeAttribute + virtual void onRemoteTestPredefinedTypeAttributeAttributeChanged() = 0; + + + /// Verification callback for remote set requests on the attribute TestDerivedStructAttribute + virtual bool onRemoteSetTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestStructExtended TestDerivedStructAttribute) = 0; + /// Action callback for remote set requests on the attribute TestDerivedStructAttribute + virtual void onRemoteTestDerivedStructAttributeAttributeChanged() = 0; + + /// Verification callback for remote set requests on the attribute TestDerivedArrayAttribute + virtual bool onRemoteSetTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestArrayUInt64 TestDerivedArrayAttribute) = 0; + /// Action callback for remote set requests on the attribute TestDerivedArrayAttribute + virtual void onRemoteTestDerivedArrayAttributeAttributeChanged() = 0; + +}; + + +/** + * Defines the interface that must be implemented by any class that should provide + * the service TestFreedesktopInterface to remote clients. + * This class and the one above are the ones an application developer needs to have + * a look at if he wants to implement a service. + */ +class TestFreedesktopInterfaceStub: public virtual CommonAPI::Stub<TestFreedesktopInterfaceStubAdapter, TestFreedesktopInterfaceStubRemoteEvent> { +public: + virtual ~TestFreedesktopInterfaceStub() { } + virtual const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + + /// Provides getter access to the attribute TestPredefinedTypeAttribute + virtual const uint32_t& getTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + /// Provides getter access to the attribute TestReadonlyAttribute + virtual const uint32_t& getTestReadonlyAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + /// Provides getter access to the attribute TestDerivedStructAttribute + virtual const DerivedTypeCollection::TestStructExtended& getTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + /// Provides getter access to the attribute TestDerivedArrayAttribute + virtual const DerivedTypeCollection::TestArrayUInt64& getTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) = 0; + + + using CommonAPI::Stub<TestFreedesktopInterfaceStubAdapter, TestFreedesktopInterfaceStubRemoteEvent>::initStubAdapter; + typedef CommonAPI::Stub<TestFreedesktopInterfaceStubAdapter, TestFreedesktopInterfaceStubRemoteEvent>::StubAdapterType StubAdapterType; + typedef CommonAPI::Stub<TestFreedesktopInterfaceStubAdapter, TestFreedesktopInterfaceStubRemoteEvent>::RemoteEventHandlerType RemoteEventHandlerType; + typedef TestFreedesktopInterfaceStubRemoteEvent RemoteEventType; + typedef TestFreedesktopInterface StubInterface; +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Interface_STUB_H_ diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceStubDefault.cpp b/src/test/commonapi/tests/TestFreedesktopInterfaceStubDefault.cpp new file mode 100644 index 0000000..3de15da --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceStubDefault.cpp @@ -0,0 +1,211 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#include <commonapi/tests/TestFreedesktopInterfaceStubDefault.h> + +namespace commonapi { +namespace tests { + +TestFreedesktopInterfaceStubDefault::TestFreedesktopInterfaceStubDefault(): + remoteEventHandler_(this), + interfaceVersion_(TestFreedesktopInterface::getInterfaceVersion()) { +} + +const CommonAPI::Version& TestFreedesktopInterfaceStubDefault::getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId) { + return interfaceVersion_; +} + +TestFreedesktopInterfaceStubRemoteEvent* TestFreedesktopInterfaceStubDefault::initStubAdapter(const std::shared_ptr<TestFreedesktopInterfaceStubAdapter>& stubAdapter) { + CommonAPI::Stub<TestFreedesktopInterfaceStubAdapter, TestFreedesktopInterfaceStubRemoteEvent>::stubAdapter_ = stubAdapter; + return &remoteEventHandler_; +} + +const uint32_t& TestFreedesktopInterfaceStubDefault::getTestPredefinedTypeAttributeAttribute() { + return testPredefinedTypeAttributeAttributeValue_; +} + +const uint32_t& TestFreedesktopInterfaceStubDefault::getTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) { + return getTestPredefinedTypeAttributeAttribute(); +} + +void TestFreedesktopInterfaceStubDefault::setTestPredefinedTypeAttributeAttribute(uint32_t value) { + const bool valueChanged = trySetTestPredefinedTypeAttributeAttribute(std::move(value)); + if (valueChanged) { + stubAdapter_->fireTestPredefinedTypeAttributeAttributeChanged(testPredefinedTypeAttributeAttributeValue_); + } +} + +bool TestFreedesktopInterfaceStubDefault::trySetTestPredefinedTypeAttributeAttribute(uint32_t value) { + if (!validateTestPredefinedTypeAttributeAttributeRequestedValue(value)) + return false; + + const bool valueChanged = (testPredefinedTypeAttributeAttributeValue_ != value); + testPredefinedTypeAttributeAttributeValue_ = std::move(value); + return valueChanged; +} + +bool TestFreedesktopInterfaceStubDefault::validateTestPredefinedTypeAttributeAttributeRequestedValue(const uint32_t& value) { + return true; +} + +void TestFreedesktopInterfaceStubDefault::setTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value) { + setTestPredefinedTypeAttributeAttribute(value); +} + +void TestFreedesktopInterfaceStubDefault::onRemoteTestPredefinedTypeAttributeAttributeChanged() { + // No operation in default +} + +void TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteTestPredefinedTypeAttributeAttributeChanged() { + defaultStub_->onRemoteTestPredefinedTypeAttributeAttributeChanged(); +} + +bool TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestPredefinedTypeAttributeAttribute(uint32_t value) { + return defaultStub_->trySetTestPredefinedTypeAttributeAttribute(std::move(value)); +} + +bool TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value) { + return onRemoteSetTestPredefinedTypeAttributeAttribute(value); +} + +const uint32_t& TestFreedesktopInterfaceStubDefault::getTestReadonlyAttributeAttribute() { + return testReadonlyAttributeAttributeValue_; +} + +const uint32_t& TestFreedesktopInterfaceStubDefault::getTestReadonlyAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) { + return getTestReadonlyAttributeAttribute(); +} + +void TestFreedesktopInterfaceStubDefault::setTestReadonlyAttributeAttribute(uint32_t value) { + const bool valueChanged = trySetTestReadonlyAttributeAttribute(std::move(value)); + if (valueChanged) { + stubAdapter_->fireTestReadonlyAttributeAttributeChanged(testReadonlyAttributeAttributeValue_); + } +} + +bool TestFreedesktopInterfaceStubDefault::trySetTestReadonlyAttributeAttribute(uint32_t value) { + if (!validateTestReadonlyAttributeAttributeRequestedValue(value)) + return false; + + const bool valueChanged = (testReadonlyAttributeAttributeValue_ != value); + testReadonlyAttributeAttributeValue_ = std::move(value); + return valueChanged; +} + +bool TestFreedesktopInterfaceStubDefault::validateTestReadonlyAttributeAttributeRequestedValue(const uint32_t& value) { + return true; +} + + +const DerivedTypeCollection::TestStructExtended& TestFreedesktopInterfaceStubDefault::getTestDerivedStructAttributeAttribute() { + return testDerivedStructAttributeAttributeValue_; +} + +const DerivedTypeCollection::TestStructExtended& TestFreedesktopInterfaceStubDefault::getTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) { + return getTestDerivedStructAttributeAttribute(); +} + +void TestFreedesktopInterfaceStubDefault::setTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value) { + const bool valueChanged = trySetTestDerivedStructAttributeAttribute(std::move(value)); + if (valueChanged) { + stubAdapter_->fireTestDerivedStructAttributeAttributeChanged(testDerivedStructAttributeAttributeValue_); + } +} + +bool TestFreedesktopInterfaceStubDefault::trySetTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value) { + if (!validateTestDerivedStructAttributeAttributeRequestedValue(value)) + return false; + + const bool valueChanged = (testDerivedStructAttributeAttributeValue_ != value); + testDerivedStructAttributeAttributeValue_ = std::move(value); + return valueChanged; +} + +bool TestFreedesktopInterfaceStubDefault::validateTestDerivedStructAttributeAttributeRequestedValue(const DerivedTypeCollection::TestStructExtended& value) { + return true; +} + +void TestFreedesktopInterfaceStubDefault::setTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestStructExtended value) { + setTestDerivedStructAttributeAttribute(value); +} + +void TestFreedesktopInterfaceStubDefault::onRemoteTestDerivedStructAttributeAttributeChanged() { + // No operation in default +} + +void TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteTestDerivedStructAttributeAttributeChanged() { + defaultStub_->onRemoteTestDerivedStructAttributeAttributeChanged(); +} + +bool TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value) { + return defaultStub_->trySetTestDerivedStructAttributeAttribute(std::move(value)); +} + +bool TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestStructExtended value) { + return onRemoteSetTestDerivedStructAttributeAttribute(value); +} + +const DerivedTypeCollection::TestArrayUInt64& TestFreedesktopInterfaceStubDefault::getTestDerivedArrayAttributeAttribute() { + return testDerivedArrayAttributeAttributeValue_; +} + +const DerivedTypeCollection::TestArrayUInt64& TestFreedesktopInterfaceStubDefault::getTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId) { + return getTestDerivedArrayAttributeAttribute(); +} + +void TestFreedesktopInterfaceStubDefault::setTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value) { + const bool valueChanged = trySetTestDerivedArrayAttributeAttribute(std::move(value)); + if (valueChanged) { + stubAdapter_->fireTestDerivedArrayAttributeAttributeChanged(testDerivedArrayAttributeAttributeValue_); + } +} + +bool TestFreedesktopInterfaceStubDefault::trySetTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value) { + if (!validateTestDerivedArrayAttributeAttributeRequestedValue(value)) + return false; + + const bool valueChanged = (testDerivedArrayAttributeAttributeValue_ != value); + testDerivedArrayAttributeAttributeValue_ = std::move(value); + return valueChanged; +} + +bool TestFreedesktopInterfaceStubDefault::validateTestDerivedArrayAttributeAttributeRequestedValue(const DerivedTypeCollection::TestArrayUInt64& value) { + return true; +} + +void TestFreedesktopInterfaceStubDefault::setTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestArrayUInt64 value) { + setTestDerivedArrayAttributeAttribute(value); +} + +void TestFreedesktopInterfaceStubDefault::onRemoteTestDerivedArrayAttributeAttributeChanged() { + // No operation in default +} + +void TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteTestDerivedArrayAttributeAttributeChanged() { + defaultStub_->onRemoteTestDerivedArrayAttributeAttributeChanged(); +} + +bool TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value) { + return defaultStub_->trySetTestDerivedArrayAttributeAttribute(std::move(value)); +} + +bool TestFreedesktopInterfaceStubDefault::RemoteEventHandler::onRemoteSetTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestArrayUInt64 value) { + return onRemoteSetTestDerivedArrayAttributeAttribute(value); +} + + + + + +TestFreedesktopInterfaceStubDefault::RemoteEventHandler::RemoteEventHandler(TestFreedesktopInterfaceStubDefault* defaultStub): + defaultStub_(defaultStub) { +} + +} // namespace tests +} // namespace commonapi diff --git a/src/test/commonapi/tests/TestFreedesktopInterfaceStubDefault.h b/src/test/commonapi/tests/TestFreedesktopInterfaceStubDefault.h new file mode 100644 index 0000000..597e176 --- /dev/null +++ b/src/test/commonapi/tests/TestFreedesktopInterfaceStubDefault.h @@ -0,0 +1,104 @@ +/* +* This file was generated by the CommonAPI Generators. +* Used org.genivi.commonapi.core 2.1.5.qualifier. +* Used org.franca.core 0.8.10.201309262002. +* +* 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/. +*/ +#ifndef COMMONAPI_TESTS_Test_Freedesktop_Interface_STUB_DEFAULT_H_ +#define COMMONAPI_TESTS_Test_Freedesktop_Interface_STUB_DEFAULT_H_ + + +#include <commonapi/tests/TestFreedesktopInterfaceStub.h> +#include <sstream> + +namespace commonapi { +namespace tests { + +/** + * Provides a default implementation for TestFreedesktopInterfaceStubRemoteEvent and + * TestFreedesktopInterfaceStub. Method callbacks have an empty implementation, + * remote set calls on attributes will always change the value of the attribute + * to the one received. + * + * Override this stub if you only want to provide a subset of the functionality + * that would be defined for this service, and/or if you do not need any non-default + * behaviour. + */ +class TestFreedesktopInterfaceStubDefault : public virtual TestFreedesktopInterfaceStub { +public: + TestFreedesktopInterfaceStubDefault(); + + TestFreedesktopInterfaceStubRemoteEvent* initStubAdapter(const std::shared_ptr<TestFreedesktopInterfaceStubAdapter>& stubAdapter); + + const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId); + + virtual const uint32_t& getTestPredefinedTypeAttributeAttribute(); + virtual const uint32_t& getTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId); + virtual void setTestPredefinedTypeAttributeAttribute(uint32_t value); + virtual void setTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value); + virtual const uint32_t& getTestReadonlyAttributeAttribute(); + virtual const uint32_t& getTestReadonlyAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId); + virtual void setTestReadonlyAttributeAttribute(uint32_t value); + virtual const DerivedTypeCollection::TestStructExtended& getTestDerivedStructAttributeAttribute(); + virtual const DerivedTypeCollection::TestStructExtended& getTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId); + virtual void setTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value); + virtual void setTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestStructExtended value); + virtual const DerivedTypeCollection::TestArrayUInt64& getTestDerivedArrayAttributeAttribute(); + virtual const DerivedTypeCollection::TestArrayUInt64& getTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId); + virtual void setTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value); + virtual void setTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestArrayUInt64 value); + + + + +protected: + virtual bool trySetTestPredefinedTypeAttributeAttribute(uint32_t value); + virtual bool validateTestPredefinedTypeAttributeAttributeRequestedValue(const uint32_t& value); + virtual void onRemoteTestPredefinedTypeAttributeAttributeChanged(); + virtual bool trySetTestReadonlyAttributeAttribute(uint32_t value); + virtual bool validateTestReadonlyAttributeAttributeRequestedValue(const uint32_t& value); + virtual bool trySetTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value); + virtual bool validateTestDerivedStructAttributeAttributeRequestedValue(const DerivedTypeCollection::TestStructExtended& value); + virtual void onRemoteTestDerivedStructAttributeAttributeChanged(); + virtual bool trySetTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value); + virtual bool validateTestDerivedArrayAttributeAttributeRequestedValue(const DerivedTypeCollection::TestArrayUInt64& value); + virtual void onRemoteTestDerivedArrayAttributeAttributeChanged(); + class RemoteEventHandler: public virtual TestFreedesktopInterfaceStubRemoteEvent { + public: + RemoteEventHandler(TestFreedesktopInterfaceStubDefault* defaultStub); + + virtual bool onRemoteSetTestPredefinedTypeAttributeAttribute(uint32_t value); + virtual bool onRemoteSetTestPredefinedTypeAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, uint32_t value); + virtual void onRemoteTestPredefinedTypeAttributeAttributeChanged(); + + + virtual bool onRemoteSetTestDerivedStructAttributeAttribute(DerivedTypeCollection::TestStructExtended value); + virtual bool onRemoteSetTestDerivedStructAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestStructExtended value); + virtual void onRemoteTestDerivedStructAttributeAttributeChanged(); + + virtual bool onRemoteSetTestDerivedArrayAttributeAttribute(DerivedTypeCollection::TestArrayUInt64 value); + virtual bool onRemoteSetTestDerivedArrayAttributeAttribute(const std::shared_ptr<CommonAPI::ClientId> clientId, DerivedTypeCollection::TestArrayUInt64 value); + virtual void onRemoteTestDerivedArrayAttributeAttributeChanged(); + + + private: + TestFreedesktopInterfaceStubDefault* defaultStub_; + }; +private: + TestFreedesktopInterfaceStubDefault::RemoteEventHandler remoteEventHandler_; + + uint32_t testPredefinedTypeAttributeAttributeValue_; + uint32_t testReadonlyAttributeAttributeValue_; + DerivedTypeCollection::TestStructExtended testDerivedStructAttributeAttributeValue_; + DerivedTypeCollection::TestArrayUInt64 testDerivedArrayAttributeAttributeValue_; + + CommonAPI::Version interfaceVersion_; +}; + +} // namespace tests +} // namespace commonapi + +#endif // COMMONAPI_TESTS_Test_Freedesktop_Interface_STUB_DEFAULT_H_ diff --git a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp index 32d2294..9cd1cf9 100644 --- a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.cpp @@ -139,9 +139,10 @@ CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher< > TestInterfaceDBusStubAdapterInternal::setTestPredefinedTypeAttributeAttributeStubDispatcher( &TestInterfaceStub::getTestPredefinedTypeAttributeAttribute, &TestInterfaceStubRemoteEvent::onRemoteSetTestPredefinedTypeAttributeAttribute, - &TestInterfaceStubRemoteEvent::onRemoteTestPredefinedTypeAttributeAttributeChanged, - &TestInterfaceStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged, - "u"); + &TestInterfaceStubRemoteEvent::onRemoteTestPredefinedTypeAttributeAttributeChanged + ,&TestInterfaceStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged + ,"u" + ); CommonAPI::DBus::DBusGetAttributeStubDispatcher< TestInterfaceStub, DerivedTypeCollection::TestStructExtended @@ -152,9 +153,10 @@ CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher< > TestInterfaceDBusStubAdapterInternal::setTestDerivedStructAttributeAttributeStubDispatcher( &TestInterfaceStub::getTestDerivedStructAttributeAttribute, &TestInterfaceStubRemoteEvent::onRemoteSetTestDerivedStructAttributeAttribute, - &TestInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged, - &TestInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged, - "(sqi)"); + &TestInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged + ,&TestInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged + ,"(sqi)" + ); CommonAPI::DBus::DBusGetAttributeStubDispatcher< TestInterfaceStub, DerivedTypeCollection::TestArrayUInt64 @@ -165,9 +167,10 @@ CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher< > TestInterfaceDBusStubAdapterInternal::setTestDerivedArrayAttributeAttributeStubDispatcher( &TestInterfaceStub::getTestDerivedArrayAttributeAttribute, &TestInterfaceStubRemoteEvent::onRemoteSetTestDerivedArrayAttributeAttribute, - &TestInterfaceStubRemoteEvent::onRemoteTestDerivedArrayAttributeAttributeChanged, - &TestInterfaceStubAdapter::fireTestDerivedArrayAttributeAttributeChanged, - "at"); + &TestInterfaceStubRemoteEvent::onRemoteTestDerivedArrayAttributeAttributeChanged + ,&TestInterfaceStubAdapter::fireTestDerivedArrayAttributeAttributeChanged + ,"at" + ); CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< @@ -397,6 +400,9 @@ const TestInterfaceDBusStubAdapterHelper::StubDispatcherTable& TestInterfaceDBus return stubDispatcherTable_; } +const CommonAPI::DBus::StubAttributeTable& TestInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; +} TestInterfaceDBusStubAdapterInternal::TestInterfaceDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -447,12 +453,17 @@ TestInterfaceDBusStubAdapterInternal::TestInterfaceDBusStubAdapterInternal( { { "subscribeForTestBroadcastWithOutArgsSelective", "" }, &commonapi::tests::TestInterfaceDBusStubAdapterInternal::subscribeTestBroadcastWithOutArgsSelectiveStubDispatcher } , { { "unsubscribeFromTestBroadcastWithOutArgsSelective", "" }, &commonapi::tests::TestInterfaceDBusStubAdapterInternal::unsubscribeTestBroadcastWithOutArgsSelectiveStubDispatcher } - }) { + }), + stubAttributeTable_() { subscribersForTestSelectiveBroadcastSelective_ = std::make_shared<CommonAPI::ClientIdList>(); subscribersForTestBroadcastWithOutArgsSelective_ = std::make_shared<CommonAPI::ClientIdList>(); stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::TestInterfaceDBusStubAdapterInternal::getTestInterfaceInterfaceVersionStubDispatcher }); } +const bool TestInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return false; +} + } // namespace tests } // namespace commonapi diff --git a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h index f0f31ff..44c87e9 100644 --- a/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h +++ b/src/test/commonapi/tests/TestInterfaceDBusStubAdapter.h @@ -41,6 +41,8 @@ class TestInterfaceDBusStubAdapterInternal: public virtual TestInterfaceStubAdap ~TestInterfaceDBusStubAdapterInternal(); + virtual const bool hasFreedesktopProperties(); + void fireTestPredefinedTypeAttributeAttributeChanged(const uint32_t& value); void fireTestDerivedStructAttributeAttributeChanged(const DerivedTypeCollection::TestStructExtended& value); void fireTestDerivedArrayAttributeAttributeChanged(const DerivedTypeCollection::TestArrayUInt64& value); @@ -59,6 +61,7 @@ class TestInterfaceDBusStubAdapterInternal: public virtual TestInterfaceStubAdap const TestInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); void deactivateManagedInstances(); @@ -171,9 +174,10 @@ static CommonAPI::DBus::DBusMethodWithReplyAdapterDispatcher< protected: virtual const char* getMethodsDBusIntrospectionXmlData() const; - - private: + + private: TestInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; }; class TestInterfaceDBusStubAdapter: public TestInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<TestInterfaceDBusStubAdapter> { diff --git a/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp index 9411f53..d6ef6c8 100644 --- a/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.cpp @@ -79,6 +79,9 @@ const BranchInterfaceDBusStubAdapterHelper::StubDispatcherTable& BranchInterface return stubDispatcherTable_; } +const CommonAPI::DBus::StubAttributeTable& BranchInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; +} BranchInterfaceDBusStubAdapterInternal::BranchInterfaceDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -107,11 +110,16 @@ BranchInterfaceDBusStubAdapterInternal::BranchInterfaceDBusStubAdapterInternal( false), stubDispatcherTable_({ { { "testBranchMethod", "is" }, &commonapi::tests::managed::BranchInterfaceDBusStubAdapterInternal::testBranchMethodStubDispatcher } - }) { + }), + stubAttributeTable_() { stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::managed::BranchInterfaceDBusStubAdapterInternal::getBranchInterfaceInterfaceVersionStubDispatcher }); } +const bool BranchInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return false; +} + } // namespace managed } // namespace tests } // namespace commonapi diff --git a/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.h index 730a0e5..d0a1d24 100644 --- a/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.h +++ b/src/test/commonapi/tests/managed/BranchInterfaceDBusStubAdapter.h @@ -42,10 +42,13 @@ class BranchInterfaceDBusStubAdapterInternal: public virtual BranchInterfaceStub ~BranchInterfaceDBusStubAdapterInternal(); + virtual const bool hasFreedesktopProperties(); + const BranchInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); void deactivateManagedInstances(); @@ -68,9 +71,10 @@ static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< protected: virtual const char* getMethodsDBusIntrospectionXmlData() const; - - private: + + private: BranchInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; }; class BranchInterfaceDBusStubAdapter: public BranchInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<BranchInterfaceDBusStubAdapter> { diff --git a/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp index 5411efa..1224eeb 100644 --- a/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.cpp @@ -79,6 +79,9 @@ const LeafInterfaceDBusStubAdapterHelper::StubDispatcherTable& LeafInterfaceDBus return stubDispatcherTable_; } +const CommonAPI::DBus::StubAttributeTable& LeafInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; +} LeafInterfaceDBusStubAdapterInternal::LeafInterfaceDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -107,11 +110,16 @@ LeafInterfaceDBusStubAdapterInternal::LeafInterfaceDBusStubAdapterInternal( false), stubDispatcherTable_({ { { "testLeafMethod", "is" }, &commonapi::tests::managed::LeafInterfaceDBusStubAdapterInternal::testLeafMethodStubDispatcher } - }) { + }), + stubAttributeTable_() { stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::managed::LeafInterfaceDBusStubAdapterInternal::getLeafInterfaceInterfaceVersionStubDispatcher }); } +const bool LeafInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return false; +} + } // namespace managed } // namespace tests } // namespace commonapi diff --git a/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.h index 4819095..6930bda 100644 --- a/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.h +++ b/src/test/commonapi/tests/managed/LeafInterfaceDBusStubAdapter.h @@ -42,10 +42,13 @@ class LeafInterfaceDBusStubAdapterInternal: public virtual LeafInterfaceStubAdap ~LeafInterfaceDBusStubAdapterInternal(); + virtual const bool hasFreedesktopProperties(); + const LeafInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); void deactivateManagedInstances(); @@ -68,9 +71,10 @@ static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< protected: virtual const char* getMethodsDBusIntrospectionXmlData() const; - - private: + + private: LeafInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; }; class LeafInterfaceDBusStubAdapter: public LeafInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<LeafInterfaceDBusStubAdapter> { diff --git a/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp index a56a381..e5e8f7c 100644 --- a/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp @@ -103,110 +103,113 @@ const RootInterfaceDBusStubAdapterHelper::StubDispatcherTable& RootInterfaceDBus return stubDispatcherTable_; } - -bool RootInterfaceDBusStubAdapterInternal::registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub> stub, const std::string& instance) { - if (registeredLeafInterfaceInstances.find(instance) == registeredLeafInterfaceInstances.end()) { - std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; - - std::string interfaceName; - std::string connectionName; - std::string objectPath; - - CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress( - commonApiAddress, - interfaceName, - connectionName, - objectPath); - - if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) { - auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.LeafInterface", - instance, "commonapi.tests.managed.LeafInterface", "local"); - - bool success = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter); - if (success) { - bool isServiceExportSuccessful = dbusConnection_->getDBusObjectManager()->exportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); - if (isServiceExportSuccessful) { - registeredLeafInterfaceInstances.insert(instance); - return true; - } else { - CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); - } - } - } - } - return false; -} - -bool RootInterfaceDBusStubAdapterInternal::deregisterManagedStubLeafInterface(const std::string& instance) { - std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; - if (registeredLeafInterfaceInstances.find(instance) != registeredLeafInterfaceInstances.end()) { - std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> dbusStubAdapter = - CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress); - if (dbusStubAdapter != nullptr) { - dbusConnection_->getDBusObjectManager()->unexportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); - CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); - registeredLeafInterfaceInstances.erase(instance); - return true; - } - } - return false; +const CommonAPI::DBus::StubAttributeTable& RootInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; } -std::set<std::string>& RootInterfaceDBusStubAdapterInternal::getLeafInterfaceInstances() { - return registeredLeafInterfaceInstances; -} - -bool RootInterfaceDBusStubAdapterInternal::registerManagedStubBranchInterface(std::shared_ptr<BranchInterfaceStub> stub, const std::string& instance) { - if (registeredBranchInterfaceInstances.find(instance) == registeredBranchInterfaceInstances.end()) { - std::string commonApiAddress = "local:commonapi.tests.managed.BranchInterface:" + instance; - - std::string interfaceName; - std::string connectionName; - std::string objectPath; - - CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress( - commonApiAddress, - interfaceName, - connectionName, - objectPath); - - if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) { - auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.BranchInterface", - instance, "commonapi.tests.managed.BranchInterface", "local"); - - bool success = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter); - if (success) { - bool isServiceExportSuccessful = dbusConnection_->getDBusObjectManager()->exportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); - if (isServiceExportSuccessful) { - registeredBranchInterfaceInstances.insert(instance); - return true; - } else { - CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); - } - } - } - } - return false; -} - -bool RootInterfaceDBusStubAdapterInternal::deregisterManagedStubBranchInterface(const std::string& instance) { - std::string commonApiAddress = "local:commonapi.tests.managed.BranchInterface:" + instance; - if (registeredBranchInterfaceInstances.find(instance) != registeredBranchInterfaceInstances.end()) { - std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> dbusStubAdapter = - CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress); - if (dbusStubAdapter != nullptr) { - dbusConnection_->getDBusObjectManager()->unexportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); - CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); - registeredBranchInterfaceInstances.erase(instance); - return true; - } - } - return false; -} - -std::set<std::string>& RootInterfaceDBusStubAdapterInternal::getBranchInterfaceInstances() { - return registeredBranchInterfaceInstances; -} + bool RootInterfaceDBusStubAdapterInternal::registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub> stub, const std::string& instance) { + if (registeredLeafInterfaceInstances.find(instance) == registeredLeafInterfaceInstances.end()) { + std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; + + std::string interfaceName; + std::string connectionName; + std::string objectPath; + + CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress( + commonApiAddress, + interfaceName, + connectionName, + objectPath); + + if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) { + auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.LeafInterface", + instance, "commonapi.tests.managed.LeafInterface", "local"); + + bool success = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter); + if (success) { + bool isServiceExportSuccessful = dbusConnection_->getDBusObjectManager()->exportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); + if (isServiceExportSuccessful) { + registeredLeafInterfaceInstances.insert(instance); + return true; + } else { + CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); + } + } + } + } + return false; + } + + bool RootInterfaceDBusStubAdapterInternal::deregisterManagedStubLeafInterface(const std::string& instance) { + std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; + if (registeredLeafInterfaceInstances.find(instance) != registeredLeafInterfaceInstances.end()) { + std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> dbusStubAdapter = + CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress); + if (dbusStubAdapter != nullptr) { + dbusConnection_->getDBusObjectManager()->unexportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); + CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); + registeredLeafInterfaceInstances.erase(instance); + return true; + } + } + return false; + } + + std::set<std::string>& RootInterfaceDBusStubAdapterInternal::getLeafInterfaceInstances() { + return registeredLeafInterfaceInstances; + } + + bool RootInterfaceDBusStubAdapterInternal::registerManagedStubBranchInterface(std::shared_ptr<BranchInterfaceStub> stub, const std::string& instance) { + if (registeredBranchInterfaceInstances.find(instance) == registeredBranchInterfaceInstances.end()) { + std::string commonApiAddress = "local:commonapi.tests.managed.BranchInterface:" + instance; + + std::string interfaceName; + std::string connectionName; + std::string objectPath; + + CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress( + commonApiAddress, + interfaceName, + connectionName, + objectPath); + + if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) { + auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.BranchInterface", + instance, "commonapi.tests.managed.BranchInterface", "local"); + + bool success = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter); + if (success) { + bool isServiceExportSuccessful = dbusConnection_->getDBusObjectManager()->exportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); + if (isServiceExportSuccessful) { + registeredBranchInterfaceInstances.insert(instance); + return true; + } else { + CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); + } + } + } + } + return false; + } + + bool RootInterfaceDBusStubAdapterInternal::deregisterManagedStubBranchInterface(const std::string& instance) { + std::string commonApiAddress = "local:commonapi.tests.managed.BranchInterface:" + instance; + if (registeredBranchInterfaceInstances.find(instance) != registeredBranchInterfaceInstances.end()) { + std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> dbusStubAdapter = + CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress); + if (dbusStubAdapter != nullptr) { + dbusConnection_->getDBusObjectManager()->unexportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); + CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); + registeredBranchInterfaceInstances.erase(instance); + return true; + } + } + return false; + } + + std::set<std::string>& RootInterfaceDBusStubAdapterInternal::getBranchInterfaceInstances() { + return registeredBranchInterfaceInstances; + } RootInterfaceDBusStubAdapterInternal::RootInterfaceDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -235,11 +238,16 @@ RootInterfaceDBusStubAdapterInternal::RootInterfaceDBusStubAdapterInternal( true), stubDispatcherTable_({ { { "testRootMethod", "is" }, &commonapi::tests::managed::RootInterfaceDBusStubAdapterInternal::testRootMethodStubDispatcher } - }) { + }), + stubAttributeTable_() { stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::managed::RootInterfaceDBusStubAdapterInternal::getRootInterfaceInterfaceVersionStubDispatcher }); } +const bool RootInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return false; +} + } // namespace managed } // namespace tests } // namespace commonapi diff --git a/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.h b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.h index 929e6c5..95b8e7e 100644 --- a/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.h +++ b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.h @@ -42,6 +42,8 @@ class RootInterfaceDBusStubAdapterInternal: public virtual RootInterfaceStubAdap ~RootInterfaceDBusStubAdapterInternal(); + virtual const bool hasFreedesktopProperties(); + bool registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub>, const std::string&); @@ -52,6 +54,7 @@ class RootInterfaceDBusStubAdapterInternal: public virtual RootInterfaceStubAdap std::set<std::string>& getBranchInterfaceInstances(); const RootInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); void deactivateManagedInstances(); @@ -74,11 +77,12 @@ static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< protected: virtual const char* getMethodsDBusIntrospectionXmlData() const; - - private: + + private: std::set<std::string> registeredLeafInterfaceInstances; std::set<std::string> registeredBranchInterfaceInstances; RootInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; }; class RootInterfaceDBusStubAdapter: public RootInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<RootInterfaceDBusStubAdapter> { diff --git a/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp index 4ddba05..d96bcf8 100644 --- a/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp +++ b/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp @@ -81,58 +81,61 @@ const SecondRootDBusStubAdapterHelper::StubDispatcherTable& SecondRootDBusStubAd return stubDispatcherTable_; } - -bool SecondRootDBusStubAdapterInternal::registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub> stub, const std::string& instance) { - if (registeredLeafInterfaceInstances.find(instance) == registeredLeafInterfaceInstances.end()) { - std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; - - std::string interfaceName; - std::string connectionName; - std::string objectPath; - - CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress( - commonApiAddress, - interfaceName, - connectionName, - objectPath); - - if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) { - auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.LeafInterface", - instance, "commonapi.tests.managed.LeafInterface", "local"); - - bool success = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter); - if (success) { - bool isServiceExportSuccessful = dbusConnection_->getDBusObjectManager()->exportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); - if (isServiceExportSuccessful) { - registeredLeafInterfaceInstances.insert(instance); - return true; - } else { - CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); - } - } - } - } - return false; -} - -bool SecondRootDBusStubAdapterInternal::deregisterManagedStubLeafInterface(const std::string& instance) { - std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; - if (registeredLeafInterfaceInstances.find(instance) != registeredLeafInterfaceInstances.end()) { - std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> dbusStubAdapter = - CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress); - if (dbusStubAdapter != nullptr) { - dbusConnection_->getDBusObjectManager()->unexportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); - CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); - registeredLeafInterfaceInstances.erase(instance); - return true; - } - } - return false; +const CommonAPI::DBus::StubAttributeTable& SecondRootDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; } -std::set<std::string>& SecondRootDBusStubAdapterInternal::getLeafInterfaceInstances() { - return registeredLeafInterfaceInstances; -} + bool SecondRootDBusStubAdapterInternal::registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub> stub, const std::string& instance) { + if (registeredLeafInterfaceInstances.find(instance) == registeredLeafInterfaceInstances.end()) { + std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; + + std::string interfaceName; + std::string connectionName; + std::string objectPath; + + CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress( + commonApiAddress, + interfaceName, + connectionName, + objectPath); + + if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) { + auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.LeafInterface", + instance, "commonapi.tests.managed.LeafInterface", "local"); + + bool success = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter); + if (success) { + bool isServiceExportSuccessful = dbusConnection_->getDBusObjectManager()->exportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); + if (isServiceExportSuccessful) { + registeredLeafInterfaceInstances.insert(instance); + return true; + } else { + CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); + } + } + } + } + return false; + } + + bool SecondRootDBusStubAdapterInternal::deregisterManagedStubLeafInterface(const std::string& instance) { + std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance; + if (registeredLeafInterfaceInstances.find(instance) != registeredLeafInterfaceInstances.end()) { + std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> dbusStubAdapter = + CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress); + if (dbusStubAdapter != nullptr) { + dbusConnection_->getDBusObjectManager()->unexportManagedDBusStubAdapter(dbusObjectPath_, dbusStubAdapter); + CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress); + registeredLeafInterfaceInstances.erase(instance); + return true; + } + } + return false; + } + + std::set<std::string>& SecondRootDBusStubAdapterInternal::getLeafInterfaceInstances() { + return registeredLeafInterfaceInstances; + } SecondRootDBusStubAdapterInternal::SecondRootDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -160,11 +163,16 @@ SecondRootDBusStubAdapterInternal::SecondRootDBusStubAdapterInternal( std::dynamic_pointer_cast<SecondRootStub>(stub), true), stubDispatcherTable_({ - }) { + }), + stubAttributeTable_() { stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::managed::SecondRootDBusStubAdapterInternal::getSecondRootInterfaceVersionStubDispatcher }); } +const bool SecondRootDBusStubAdapterInternal::hasFreedesktopProperties() { + return false; +} + } // namespace managed } // namespace tests } // namespace commonapi diff --git a/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.h b/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.h index 4a2afde..604b552 100644 --- a/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.h +++ b/src/test/commonapi/tests/managed/SecondRootDBusStubAdapter.h @@ -42,6 +42,8 @@ class SecondRootDBusStubAdapterInternal: public virtual SecondRootStubAdapter, p ~SecondRootDBusStubAdapterInternal(); + virtual const bool hasFreedesktopProperties(); + bool registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub>, const std::string&); @@ -49,6 +51,7 @@ class SecondRootDBusStubAdapterInternal: public virtual SecondRootStubAdapter, p std::set<std::string>& getLeafInterfaceInstances(); const SecondRootDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); void deactivateManagedInstances(); @@ -66,10 +69,11 @@ static CommonAPI::DBus::DBusGetAttributeStubDispatcher< protected: virtual const char* getMethodsDBusIntrospectionXmlData() const; - - private: + + private: std::set<std::string> registeredLeafInterfaceInstances; SecondRootDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; }; class SecondRootDBusStubAdapter: public SecondRootDBusStubAdapterInternal, public std::enable_shared_from_this<SecondRootDBusStubAdapter> { diff --git a/src/test/fake/legacy/service/LegacyInterfaceDBusProxy.cpp b/src/test/fake/legacy/service/LegacyInterfaceDBusProxy.cpp index e4c5d49..64d8a56 100644 --- a/src/test/fake/legacy/service/LegacyInterfaceDBusProxy.cpp +++ b/src/test/fake/legacy/service/LegacyInterfaceDBusProxy.cpp @@ -23,7 +23,7 @@ std::shared_ptr<CommonAPI::DBus::DBusProxy> createLegacyInterfaceDBusProxy( return std::make_shared<LegacyInterfaceDBusProxy>(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection); } -__attribute__((constructor)) void registerLegacyInterfaceDBusProxy(void) { +INITIALIZER(registerLegacyInterfaceDBusProxy) { CommonAPI::DBus::DBusFactory::registerProxyFactoryMethod(LegacyInterface::getInterfaceId(), &createLegacyInterfaceDBusProxy); } diff --git a/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.cpp b/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.cpp index afd7ad0..b62a0fb 100644 --- a/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.cpp +++ b/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.cpp @@ -25,7 +25,7 @@ std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createLegacyInterfaceDBusStubA return std::make_shared<LegacyInterfaceDBusStubAdapter>(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection, stubBase); } -__attribute__((constructor)) void registerLegacyInterfaceDBusStubAdapter(void) { +INITIALIZER(registerLegacyInterfaceDBusStubAdapter) { CommonAPI::DBus::DBusFactory::registerAdapterFactoryMethod(LegacyInterface::getInterfaceId(), &createLegacyInterfaceDBusStubAdapter); } @@ -38,6 +38,7 @@ LegacyInterfaceDBusStubAdapterInternal::~LegacyInterfaceDBusStubAdapterInternal( } void LegacyInterfaceDBusStubAdapterInternal::deactivateManagedInstances() { + } const char* LegacyInterfaceDBusStubAdapterInternal::getMethodsDBusIntrospectionXmlData() const { @@ -61,27 +62,30 @@ const char* LegacyInterfaceDBusStubAdapterInternal::getMethodsDBusIntrospectionX return introspectionData.c_str(); } -static CommonAPI::DBus::DBusGetAttributeStubDispatcher< +CommonAPI::DBus::DBusGetAttributeStubDispatcher< LegacyInterfaceStub, CommonAPI::Version - > getLegacyInterfaceInterfaceVersionStubDispatcher(&LegacyInterfaceStub::getInterfaceVersion, "uu"); + > LegacyInterfaceDBusStubAdapterInternal::getLegacyInterfaceInterfaceVersionStubDispatcher(&LegacyInterfaceStub::getInterfaceVersion, "uu"); + -static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< +CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< LegacyInterfaceStub, std::tuple<int32_t>, std::tuple<int32_t, int32_t> - > testMethodStubDispatcher(&LegacyInterfaceStub::TestMethod, "ii"); -static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< + > LegacyInterfaceDBusStubAdapterInternal::testMethodStubDispatcher(&LegacyInterfaceStub::TestMethod, "ii"); +CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< LegacyInterfaceStub, std::tuple<>, std::tuple<std::string, int32_t> - > otherTestMethodStubDispatcher(&LegacyInterfaceStub::OtherTestMethod, "si"); -static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< + > LegacyInterfaceDBusStubAdapterInternal::otherTestMethodStubDispatcher(&LegacyInterfaceStub::OtherTestMethod, "si"); +CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< LegacyInterfaceStub, std::tuple<>, std::tuple<> - > finishStubDispatcher(&LegacyInterfaceStub::finish, ""); + > LegacyInterfaceDBusStubAdapterInternal::finishStubDispatcher(&LegacyInterfaceStub::finish, ""); + + @@ -89,6 +93,9 @@ const LegacyInterfaceDBusStubAdapterHelper::StubDispatcherTable& LegacyInterface return stubDispatcherTable_; } +const CommonAPI::DBus::StubAttributeTable& LegacyInterfaceDBusStubAdapterInternal::getStubAttributeTable() { + return stubAttributeTable_; +} LegacyInterfaceDBusStubAdapterInternal::LegacyInterfaceDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -116,12 +123,17 @@ LegacyInterfaceDBusStubAdapterInternal::LegacyInterfaceDBusStubAdapterInternal( std::dynamic_pointer_cast<LegacyInterfaceStub>(stub), false), stubDispatcherTable_({ - { { "TestMethod", "i" }, &fake::legacy::service::testMethodStubDispatcher }, - { { "OtherTestMethod", "" }, &fake::legacy::service::otherTestMethodStubDispatcher }, - { { "finish", "" }, &fake::legacy::service::finishStubDispatcher } - }) { + { { "TestMethod", "i" }, &fake::legacy::service::LegacyInterfaceDBusStubAdapterInternal::testMethodStubDispatcher }, + { { "OtherTestMethod", "" }, &fake::legacy::service::LegacyInterfaceDBusStubAdapterInternal::otherTestMethodStubDispatcher }, + { { "finish", "" }, &fake::legacy::service::LegacyInterfaceDBusStubAdapterInternal::finishStubDispatcher } + }), + stubAttributeTable_() { + + stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &fake::legacy::service::LegacyInterfaceDBusStubAdapterInternal::getLegacyInterfaceInterfaceVersionStubDispatcher }); +} - stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &fake::legacy::service::getLegacyInterfaceInterfaceVersionStubDispatcher }); +const bool LegacyInterfaceDBusStubAdapterInternal::hasFreedesktopProperties() { + return false; } } // namespace service diff --git a/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.h b/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.h index e61e29f..a826fd8 100644 --- a/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.h +++ b/src/test/fake/legacy/service/LegacyInterfaceDBusStubAdapter.h @@ -29,7 +29,7 @@ namespace service { typedef CommonAPI::DBus::DBusStubAdapterHelper<LegacyInterfaceStub> LegacyInterfaceDBusStubAdapterHelper; -class LegacyInterfaceDBusStubAdapterInternal: public LegacyInterfaceStubAdapter, public LegacyInterfaceDBusStubAdapterHelper { +class LegacyInterfaceDBusStubAdapterInternal: public virtual LegacyInterfaceStubAdapter, public LegacyInterfaceDBusStubAdapterHelper { public: LegacyInterfaceDBusStubAdapterInternal( const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory, @@ -42,19 +42,49 @@ class LegacyInterfaceDBusStubAdapterInternal: public LegacyInterfaceStubAdapter, ~LegacyInterfaceDBusStubAdapterInternal(); + virtual const bool hasFreedesktopProperties(); + const LegacyInterfaceDBusStubAdapterHelper::StubDispatcherTable& getStubDispatcherTable(); + const CommonAPI::DBus::StubAttributeTable& getStubAttributeTable(); void deactivateManagedInstances(); +static CommonAPI::DBus::DBusGetAttributeStubDispatcher< + LegacyInterfaceStub, + CommonAPI::Version + > getLegacyInterfaceInterfaceVersionStubDispatcher; + + + +static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< + LegacyInterfaceStub, + std::tuple<int32_t>, + std::tuple<int32_t, int32_t> + > testMethodStubDispatcher; +static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< + LegacyInterfaceStub, + std::tuple<>, + std::tuple<std::string, int32_t> + > otherTestMethodStubDispatcher; +static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher< + LegacyInterfaceStub, + std::tuple<>, + std::tuple<> + > finishStubDispatcher; + + + + protected: virtual const char* getMethodsDBusIntrospectionXmlData() const; - - private: + + private: LegacyInterfaceDBusStubAdapterHelper::StubDispatcherTable stubDispatcherTable_; + CommonAPI::DBus::StubAttributeTable stubAttributeTable_; }; class LegacyInterfaceDBusStubAdapter: public LegacyInterfaceDBusStubAdapterInternal, public std::enable_shared_from_this<LegacyInterfaceDBusStubAdapter> { diff --git a/src/test/fake/legacy/service/LegacyInterfaceProxy.h b/src/test/fake/legacy/service/LegacyInterfaceProxy.h index b980f64..4c9b482 100644 --- a/src/test/fake/legacy/service/LegacyInterfaceProxy.h +++ b/src/test/fake/legacy/service/LegacyInterfaceProxy.h @@ -144,14 +144,20 @@ public: std::shared_ptr<LegacyInterfaceProxyBase> delegate_; }; +#ifdef WIN32 + typedef LegacyInterfaceProxy<CommonAPI::WINDummyAttributeExtension<CommonAPI::WINDummyAttribute>> LegacyInterfaceProxyDefault; +#else + typedef LegacyInterfaceProxy<> LegacyInterfaceProxyDefault; +#endif + // // LegacyInterfaceProxy Implementation // template <typename ... _AttributeExtensions> LegacyInterfaceProxy<_AttributeExtensions...>::LegacyInterfaceProxy(std::shared_ptr<CommonAPI::Proxy> delegate): - delegate_(std::dynamic_pointer_cast<LegacyInterfaceProxyBase>(delegate)), - _AttributeExtensions(*(std::dynamic_pointer_cast<LegacyInterfaceProxyBase>(delegate)))... { + _AttributeExtensions(*(std::dynamic_pointer_cast<LegacyInterfaceProxyBase>(delegate)))..., + delegate_(std::dynamic_pointer_cast<LegacyInterfaceProxyBase>(delegate)) { } template <typename ... _AttributeExtensions> diff --git a/src/test/fake/legacy/service/LegacyInterfaceStub.h b/src/test/fake/legacy/service/LegacyInterfaceStub.h index 980b385..69d3e22 100644 --- a/src/test/fake/legacy/service/LegacyInterfaceStub.h +++ b/src/test/fake/legacy/service/LegacyInterfaceStub.h @@ -74,7 +74,7 @@ class LegacyInterfaceStubRemoteEvent { * This class and the one above are the ones an application developer needs to have * a look at if he wants to implement a service. */ -class LegacyInterfaceStub : public virtual CommonAPI::Stub<LegacyInterfaceStubAdapter, LegacyInterfaceStubRemoteEvent> { +class LegacyInterfaceStub: public virtual CommonAPI::Stub<LegacyInterfaceStubAdapter, LegacyInterfaceStubRemoteEvent> { public: virtual ~LegacyInterfaceStub() { } virtual const CommonAPI::Version& getInterfaceVersion(std::shared_ptr<CommonAPI::ClientId> clientId) = 0; @@ -90,6 +90,8 @@ public: using CommonAPI::Stub<LegacyInterfaceStubAdapter, LegacyInterfaceStubRemoteEvent>::initStubAdapter; typedef CommonAPI::Stub<LegacyInterfaceStubAdapter, LegacyInterfaceStubRemoteEvent>::StubAdapterType StubAdapterType; typedef CommonAPI::Stub<LegacyInterfaceStubAdapter, LegacyInterfaceStubRemoteEvent>::RemoteEventHandlerType RemoteEventHandlerType; + typedef LegacyInterfaceStubRemoteEvent RemoteEventType; + typedef LegacyInterface StubInterface; }; } // namespace service diff --git a/src/test/fake/legacy/service/LegacyInterfaceStubDefault.h b/src/test/fake/legacy/service/LegacyInterfaceStubDefault.h index 893dcd6..dc8fa1f 100644 --- a/src/test/fake/legacy/service/LegacyInterfaceStubDefault.h +++ b/src/test/fake/legacy/service/LegacyInterfaceStubDefault.h @@ -50,8 +50,7 @@ public: protected: -private: - class RemoteEventHandler: public LegacyInterfaceStubRemoteEvent { + class RemoteEventHandler: public virtual LegacyInterfaceStubRemoteEvent { public: RemoteEventHandler(LegacyInterfaceStubDefault* defaultStub); @@ -59,8 +58,8 @@ private: private: LegacyInterfaceStubDefault* defaultStub_; }; - - RemoteEventHandler remoteEventHandler_; +private: + LegacyInterfaceStubDefault::RemoteEventHandler remoteEventHandler_; CommonAPI::Version interfaceVersion_; diff --git a/src/test/test-freedesktop-interface.fdepl b/src/test/test-freedesktop-interface.fdepl new file mode 100644 index 0000000..1eb84aa --- /dev/null +++ b/src/test/test-freedesktop-interface.fdepl @@ -0,0 +1,11 @@ +import "platform:/plugin/org.genivi.commonapi.dbus/deployment/CommonAPI-DBus_deployment.fdepl" +import "test-freedesktop-interface.fidl" + + +define org.genivi.commonapi.dbus.deployment.deployment for interface commonapi.tests.TestFreedesktopInterface { + PropertiesType = freedesktop +} + +define org.genivi.commonapi.dbus.deployment.deployment for interface commonapi.tests.TestFreedesktopDerivedInterface { + PropertiesType = freedesktop +}
\ No newline at end of file diff --git a/src/test/test-freedesktop-interface.fidl b/src/test/test-freedesktop-interface.fidl new file mode 100644 index 0000000..db1143f --- /dev/null +++ b/src/test/test-freedesktop-interface.fidl @@ -0,0 +1,21 @@ +/* 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/. */ +package commonapi.tests + +import commonapi.tests.* from "test-derived-types.fidl" + +interface TestFreedesktopInterface { + version { major 1 minor 0 } + + attribute UInt32 TestPredefinedTypeAttribute + attribute UInt32 TestReadonlyAttribute readonly + attribute DerivedTypeCollection.TestStructExtended TestDerivedStructAttribute + attribute DerivedTypeCollection.TestArrayUInt64 TestDerivedArrayAttribute +} + +interface TestFreedesktopDerivedInterface extends TestFreedesktopInterface { + version { major 1 minor 0 } + + attribute UInt32 TestAttributedFromDerivedInterface +}
\ No newline at end of file |