diff options
author | Juergen Gehring <juergen.gehring@bmw.de> | 2014-04-14 11:42:20 +0200 |
---|---|---|
committer | Juergen Gehring <juergen.gehring@bmw.de> | 2014-04-14 11:42:20 +0200 |
commit | 50fa3c5125bfb7cac8f50285971d00c2092c0d98 (patch) | |
tree | d60e3e6de1d32627d625ccb150afee4bdb82ad5b | |
parent | 9a9c3effc9572d77e92698b438905d50f0fa11fd (diff) | |
download | genivi-common-api-runtime-50fa3c5125bfb7cac8f50285971d00c2092c0d98.tar.gz |
Final cleanup for 2.1.6 release.
-rw-r--r-- | CommonAPI-Examples/.gitignore | 1 | ||||
-rw-r--r-- | CommonAPI-Examples/e01HelloWorld/CMakeLists.txt | 13 | ||||
-rw-r--r-- | CommonAPI-Examples/e02Attributes/CMakeLists.txt | 13 | ||||
-rw-r--r-- | CommonAPI-Examples/e02Attributes/src/AttributeCacheExtension.hpp | 56 | ||||
-rw-r--r-- | CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp | 14 | ||||
-rw-r--r-- | CommonAPI-Examples/e03Methods/CMakeLists.txt | 11 | ||||
-rw-r--r-- | CommonAPI-Examples/e04PhoneBook/CMakeLists.txt | 11 | ||||
-rw-r--r-- | CommonAPI-Examples/e05Manager/CMakeLists.txt | 11 | ||||
-rw-r--r-- | CommonAPI-Examples/e06Unions/CMakeLists.txt | 11 | ||||
-rw-r--r-- | CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl | 20 | ||||
-rw-r--r-- | CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp | 4 | ||||
-rw-r--r-- | CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp | 160 | ||||
-rw-r--r-- | CommonAPI-Examples/e06Unions/src/typeUtils.hpp | 27 | ||||
-rw-r--r-- | org.genivi.commonapi.core/src-gen/org/genivi/commonapi/core/deployment/.gitignore | 2 |
14 files changed, 302 insertions, 52 deletions
diff --git a/CommonAPI-Examples/.gitignore b/CommonAPI-Examples/.gitignore index a39b383..7a50484 100644 --- a/CommonAPI-Examples/.gitignore +++ b/CommonAPI-Examples/.gitignore @@ -1,6 +1,5 @@ .cproject .project -.autotools .settings */src-gen */build
\ No newline at end of file diff --git a/CommonAPI-Examples/e01HelloWorld/CMakeLists.txt b/CommonAPI-Examples/e01HelloWorld/CMakeLists.txt index 2ed85a7..d558653 100644 --- a/CommonAPI-Examples/e01HelloWorld/CMakeLists.txt +++ b/CommonAPI-Examples/e01HelloWorld/CMakeLists.txt @@ -15,18 +15,19 @@ else() endif() project(${PRJ_NAME}) set(CMAKE_VERBOSE_MAKEFILE on) -set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") +set(CMAKE_CXX_FLAGS "-Wall -O0 -std=c++0x") set(CMAKE_BUILD_TYPE Debug) # DBus Path -if (DBUS_PATH_LOCAL) - message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) +if (DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) else() - message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath") + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") endif() # CommonAPI include(FindPkgConfig) +pkg_check_modules (DBUS "dbus-1 >= 1.4") pkg_check_modules (COMMONAPI "CommonAPI >= 2.1") pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1") @@ -45,18 +46,18 @@ set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS} set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS}) # Paths -message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR}) message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR}) include_directories( src-gen - ${DBUS_PATH_LOCAL} + ${DBUS_INCLUDE_DIRS} ${COMMONAPI_INCLUDEDIR} ${COMMONAPI_DBUS_INCLUDEDIR} ) link_directories( + ${DBUS_LIB_PATH} ${COMMONAPI_LIBDIR} ${COMMONAPI_DBUS_LIBDIR} ) diff --git a/CommonAPI-Examples/e02Attributes/CMakeLists.txt b/CommonAPI-Examples/e02Attributes/CMakeLists.txt index 73fffbc..15aa464 100644 --- a/CommonAPI-Examples/e02Attributes/CMakeLists.txt +++ b/CommonAPI-Examples/e02Attributes/CMakeLists.txt @@ -15,18 +15,19 @@ else() endif() project(${PRJ_NAME}) set(CMAKE_VERBOSE_MAKEFILE on) -set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") +set(CMAKE_CXX_FLAGS "-Wall -O0 -std=c++0x") set(CMAKE_BUILD_TYPE Debug) # DBus Path -if (DBUS_PATH_LOCAL) - message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) +if (DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) else() - message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath") + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") endif() # CommonAPI include(FindPkgConfig) +pkg_check_modules (DBUS "dbus-1 >= 1.4") pkg_check_modules (COMMONAPI "CommonAPI >= 2.1") pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1") @@ -45,18 +46,18 @@ set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS} set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS}) # Paths -message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR}) message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR}) include_directories( src-gen - ${DBUS_PATH_LOCAL} + ${DBUS_INCLUDE_DIRS} ${COMMONAPI_INCLUDEDIR} ${COMMONAPI_DBUS_INCLUDEDIR} ) link_directories( + ${DBUS_LIB_PATH} ${COMMONAPI_LIBDIR} ${COMMONAPI_DBUS_LIBDIR} ) diff --git a/CommonAPI-Examples/e02Attributes/src/AttributeCacheExtension.hpp b/CommonAPI-Examples/e02Attributes/src/AttributeCacheExtension.hpp new file mode 100644 index 0000000..d9a7870 --- /dev/null +++ b/CommonAPI-Examples/e02Attributes/src/AttributeCacheExtension.hpp @@ -0,0 +1,56 @@ +/* Copyright (C) 2014 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 <CommonAPI/CommonAPI.h> + +template<typename _AttributeType> +class AttributeCacheExtension: public CommonAPI::AttributeExtension<_AttributeType> { + typedef CommonAPI::AttributeExtension<_AttributeType> __baseClass_t; + + public: + typedef typename _AttributeType::ValueType value_t; + typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback; + + AttributeCacheExtension(_AttributeType& baseAttribute) : + CommonAPI::AttributeExtension<_AttributeType>(baseAttribute), + isCacheValid_(false) { + } + + ~AttributeCacheExtension() {} + + bool getCachedValue(value_t& value) { + + if (isCacheValid_) { + + value = cachedValue_; + + } else { + + __baseClass_t::getBaseAttribute().getChangedEvent().subscribe(std::bind( + &AttributeCacheExtension<_AttributeType>::onValueUpdate, + this, + std::placeholders::_1)); + + CommonAPI::CallStatus callStatus; + + __baseClass_t::getBaseAttribute().getValue(callStatus, value); + } + + return isCacheValid_; + } + + private: + + void onValueUpdate(const value_t& t) { + isCacheValid_ = true; + cachedValue_ = t; + } + + mutable bool isCacheValid_; + mutable value_t cachedValue_; + +}; diff --git a/CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp b/CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp index 6480c5c..a8ac509 100644 --- a/CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp +++ b/CommonAPI-Examples/e02Attributes/src/e02AttributesClient.cpp @@ -10,6 +10,8 @@ #include <CommonAPI/CommonAPI.h> #include <commonapi/examples/E02AttributesProxy.h> +#include "AttributeCacheExtension.hpp" + using namespace commonapi::examples; void recv_cb(const CommonAPI::CallStatus& callStatus, const int32_t& val) { @@ -26,7 +28,10 @@ int main() { std::shared_ptr < CommonAPI::Factory > factory = runtime->createFactory(); const std::string& serviceAddress = "local:commonapi.examples.Attributes:commonapi.examples.Attributes"; - std::shared_ptr < E02AttributesProxyDefault > myProxy = factory->buildProxy < E02AttributesProxy > (serviceAddress); + //std::shared_ptr < E02AttributesProxyDefault > myProxy = factory->buildProxy < E02AttributesProxy > (serviceAddress); + std::shared_ptr<CommonAPI::DefaultAttributeProxyFactoryHelper<E02AttributesProxy, AttributeCacheExtension>::class_t> myProxy = + factory->buildProxyWithDefaultAttributeExtension<E02AttributesProxy, AttributeCacheExtension>(serviceAddress); + while (!myProxy->isAvailable()) { usleep(10); @@ -74,6 +79,11 @@ int main() { } while (true) { - usleep(10); + + int32_t valueCached = 0; + bool r; + r = myProxy->getXAttributeExtension().getCachedValue(valueCached); + std::cout << "Got cached attribute value[" << (int)r << "]: " << valueCached << std::endl; + usleep(1000000); } } diff --git a/CommonAPI-Examples/e03Methods/CMakeLists.txt b/CommonAPI-Examples/e03Methods/CMakeLists.txt index 73fffbc..e321988 100644 --- a/CommonAPI-Examples/e03Methods/CMakeLists.txt +++ b/CommonAPI-Examples/e03Methods/CMakeLists.txt @@ -19,14 +19,15 @@ set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") set(CMAKE_BUILD_TYPE Debug) # DBus Path -if (DBUS_PATH_LOCAL) - message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) +if (DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) else() - message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath") + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") endif() # CommonAPI include(FindPkgConfig) +pkg_check_modules (DBUS "dbus-1 >= 1.4") pkg_check_modules (COMMONAPI "CommonAPI >= 2.1") pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1") @@ -45,18 +46,18 @@ set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS} set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS}) # Paths -message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR}) message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR}) include_directories( src-gen - ${DBUS_PATH_LOCAL} + ${DBUS_INCLUDE_DIRS} ${COMMONAPI_INCLUDEDIR} ${COMMONAPI_DBUS_INCLUDEDIR} ) link_directories( + ${DBUS_LIB_PATH} ${COMMONAPI_LIBDIR} ${COMMONAPI_DBUS_LIBDIR} ) diff --git a/CommonAPI-Examples/e04PhoneBook/CMakeLists.txt b/CommonAPI-Examples/e04PhoneBook/CMakeLists.txt index d0202e7..64346fb 100644 --- a/CommonAPI-Examples/e04PhoneBook/CMakeLists.txt +++ b/CommonAPI-Examples/e04PhoneBook/CMakeLists.txt @@ -19,14 +19,15 @@ set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") set(CMAKE_BUILD_TYPE Debug) # DBus Path -if (DBUS_PATH_LOCAL) - message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) +if (DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) else() - message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath") + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") endif() # CommonAPI include(FindPkgConfig) +pkg_check_modules (DBUS "dbus-1 >= 1.4") pkg_check_modules (COMMONAPI "CommonAPI >= 2.1") pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1") @@ -46,18 +47,18 @@ set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS} set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS}) # Paths -message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR}) message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR}) include_directories( src-gen - ${DBUS_PATH_LOCAL} + ${DBUS_INCLUDE_DIRS} ${COMMONAPI_INCLUDEDIR} ${COMMONAPI_DBUS_INCLUDEDIR} ) link_directories( + ${DBUS_LIB_PATH} ${COMMONAPI_LIBDIR} ${COMMONAPI_DBUS_LIBDIR} ) diff --git a/CommonAPI-Examples/e05Manager/CMakeLists.txt b/CommonAPI-Examples/e05Manager/CMakeLists.txt index d0202e7..64346fb 100644 --- a/CommonAPI-Examples/e05Manager/CMakeLists.txt +++ b/CommonAPI-Examples/e05Manager/CMakeLists.txt @@ -19,14 +19,15 @@ set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") set(CMAKE_BUILD_TYPE Debug) # DBus Path -if (DBUS_PATH_LOCAL) - message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) +if (DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) else() - message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath") + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") endif() # CommonAPI include(FindPkgConfig) +pkg_check_modules (DBUS "dbus-1 >= 1.4") pkg_check_modules (COMMONAPI "CommonAPI >= 2.1") pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1") @@ -46,18 +47,18 @@ set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS} set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS}) # Paths -message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR}) message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR}) include_directories( src-gen - ${DBUS_PATH_LOCAL} + ${DBUS_INCLUDE_DIRS} ${COMMONAPI_INCLUDEDIR} ${COMMONAPI_DBUS_INCLUDEDIR} ) link_directories( + ${DBUS_LIB_PATH} ${COMMONAPI_LIBDIR} ${COMMONAPI_DBUS_LIBDIR} ) diff --git a/CommonAPI-Examples/e06Unions/CMakeLists.txt b/CommonAPI-Examples/e06Unions/CMakeLists.txt index 73fffbc..e321988 100644 --- a/CommonAPI-Examples/e06Unions/CMakeLists.txt +++ b/CommonAPI-Examples/e06Unions/CMakeLists.txt @@ -19,14 +19,15 @@ set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") set(CMAKE_BUILD_TYPE Debug) # DBus Path -if (DBUS_PATH_LOCAL) - message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) +if (DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) else() - message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_PATH_LOCAL=yourPath") + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") endif() # CommonAPI include(FindPkgConfig) +pkg_check_modules (DBUS "dbus-1 >= 1.4") pkg_check_modules (COMMONAPI "CommonAPI >= 2.1") pkg_check_modules (COMMONAPI_DBUS "CommonAPI-DBus >= 2.1") @@ -45,18 +46,18 @@ set(PRJ_CLIENT_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_CLIENT}.cpp ${PRJ_PROXY_GEN_SRCS} set(PRJ_SERVICE_SRCS ${PRJ_SRC_PATH}/${PRJ_NAME_SERVICE}.cpp ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_IMPL_SRCS}) # Paths -message(STATUS "DBUS_PATH_LOCAL = " ${DBUS_PATH_LOCAL}) message(STATUS "COMMONAPI_INCLUDEDIR = " ${COMMONAPI_INCLUDEDIR}) message(STATUS "COMMONAPI_DBUS_INCLUDEDIR = " ${COMMONAPI_DBUS_INCLUDEDIR}) include_directories( src-gen - ${DBUS_PATH_LOCAL} + ${DBUS_INCLUDE_DIRS} ${COMMONAPI_INCLUDEDIR} ${COMMONAPI_DBUS_INCLUDEDIR} ) link_directories( + ${DBUS_LIB_PATH} ${COMMONAPI_LIBDIR} ${COMMONAPI_DBUS_LIBDIR} ) diff --git a/CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl b/CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl index 9cfb3fa..b244625 100644 --- a/CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl +++ b/CommonAPI-Examples/e06Unions/fidl/E06Unions.fidl @@ -11,6 +11,7 @@ interface E06Unions { version { major 1 minor 0 } attribute CommonTypes.SettingsUnion u + attribute CommonTypes.SettingsStruct x } typeCollection CommonTypes { @@ -29,4 +30,23 @@ typeCollection CommonTypes { UInt8 channel String name } + + struct SettingsStruct polymorphic { + } + + struct SettingsStructMyTypedef extends SettingsStruct { + MyTypedef id + } + + struct SettingsStructMyEnum extends SettingsStruct { + MyEnum status + } + + struct SettingsStructUInt8 extends SettingsStruct { + UInt8 channel + } + + struct SettingsStructString extends SettingsStruct { + String name + } }
\ No newline at end of file diff --git a/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp b/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp index 9ec5091..31f2365 100644 --- a/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp +++ b/CommonAPI-Examples/e06Unions/src/E06UnionsStubImpl.cpp @@ -28,15 +28,19 @@ void E06UnionsStubImpl::setMyValue(int n) { if (n == 0) { CommonTypes::SettingsUnion v(t0); setUAttribute(v); + setXAttribute(std::make_shared<CommonTypes::SettingsStructMyTypedef>(t0)); } else if (n == 1) { CommonTypes::SettingsUnion v(t1); setUAttribute(v); + setXAttribute(std::make_shared<CommonTypes::SettingsStructMyEnum>(t1)); } else if (n == 2) { CommonTypes::SettingsUnion v(t2); setUAttribute(v); + setXAttribute(std::make_shared<CommonTypes::SettingsStructUInt8>(t2)); } else if (n == 3) { CommonTypes::SettingsUnion v(t3); setUAttribute(v); + setXAttribute(std::make_shared<CommonTypes::SettingsStructString>(t3)); } } else { diff --git a/CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp b/CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp index eedd177..ddefcf0 100644 --- a/CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp +++ b/CommonAPI-Examples/e06Unions/src/e06UnionsClient.cpp @@ -11,8 +11,147 @@ #include <commonapi/examples/E06UnionsProxy.h> #include <commonapi/examples/CommonTypes.h> +#include "typeUtils.hpp" + using namespace commonapi::examples; +struct MyVisitor { + + explicit inline MyVisitor() { + } + + template<typename... T> + inline void eval(const CommonAPI::Variant<T...>& v) { + CommonAPI::ApplyVoidVisitor<MyVisitor, CommonAPI::Variant<T...>, T...>::visit(*this, v); + } + + void operator()(CommonTypes::MyTypedef val) { + + std::cout << "Received (C) MyTypedef with value " << (int)val << std::endl; + } + + void operator()(CommonTypes::MyEnum val) { + + std::cout << "Received (C) MyEnum with value " << (int)val << std::endl; + } + + void operator()(uint8_t val) { + + std::cout << "Received (C) uint8_t with value " << (int)val << std::endl; + } + + void operator()(std::string val) { + + std::cout << "Received (C) string " << val << std::endl; + } + + template<typename T> + void operator()(const T&) { + + std::cout << "Received (C) change message with unknown type." << std::endl; + } + + void operator()() { + + std::cout << "NOOP." << std::endl; + } + +}; + +void evalA (const CommonTypes::SettingsUnion& v) { + + if ( v.isType<CommonTypes::MyTypedef>() ) { + + std::cout << "Received (A) MyTypedef with value " << v.get<CommonTypes::MyTypedef>() << " at index " << (int)v.getValueType() << std::endl; + + } else if ( v.isType<CommonTypes::MyEnum>() ) { + + std::cout << "Received (A) MyEnum with value " << (int) (v.get<CommonTypes::MyEnum>()) << " at index " << (int)v.getValueType() << std::endl; + + } else if ( v.isType<uint8_t>() ) { + + std::cout << "Received (A) uint8_t with value " << (int) (v.get<uint8_t>()) << " at index " << (int)v.getValueType() << std::endl; + + } else if ( v.isType<std::string>() ) { + + std::cout << "Received (A) string " << v.get<std::string>() << " at index " << (int)v.getValueType() << std::endl; + + } else { + + std::cout << "Received (A) change message with unknown type." << std::endl; + } +} + +template <typename T1, typename... T> +void evalB (const CommonAPI::Variant<T1, T...>& v) { + + switch (v.getValueType()) { + + case typeIdOf<CommonTypes::MyTypedef, T1, T...>::value: + + std::cout << "Received (B) MyTypedef with value " << (int)(v.template get<CommonTypes::MyTypedef>()) << " at index " << (int)v.getValueType() << std::endl; + break; + + case typeIdOf<CommonTypes::MyEnum, T1, T...>::value: + + std::cout << "Received (B) MyEnum with value " << (int)(v.template get<CommonTypes::MyEnum>()) << " at index " << (int)v.getValueType() << std::endl; + break; + + case typeIdOf<uint8_t, T1, T...>::value: + + std::cout << "Received (B) uint8_t with value " << (int)(v.template get<uint8_t>()) << " at index " << (int)v.getValueType() << std::endl; + break; + + case typeIdOf<std::string, T1, T...>::value: + + std::cout << "Received (B) string " << v.template get<std::string>() << " at index " << (int)v.getValueType() << std::endl; + break; + + default: + + std::cout << "Received (B) change message with unknown type." << std::endl; + break; + } +} + +void evalC(const CommonTypes::SettingsUnion& v) { + + MyVisitor visitor; + visitor.eval(v); +} + +void recv_msg(const CommonTypes::SettingsUnion& v) { + + evalA(v); + evalB(v); + evalC(v); +} + +void recv_msg1(std::shared_ptr<CommonTypes::SettingsStruct> x) { + + if ( std::shared_ptr<CommonTypes::SettingsStructMyTypedef> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructMyTypedef>(x) ) { + + std::cout << "Received (D) MyTypedef with value " << (int)sp->id << std::endl; + + } else if ( std::shared_ptr<CommonTypes::SettingsStructMyEnum> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructMyEnum>(x) ) { + + std::cout << "Received (D) MyEnum with value " << (int)sp->status << std::endl; + + } else if ( std::shared_ptr<CommonTypes::SettingsStructUInt8> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructUInt8>(x) ) { + + std::cout << "Received (D) uint8_t with value " << (int)sp->channel << std::endl; + + } else if ( std::shared_ptr<CommonTypes::SettingsStructString> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructString>(x) ) { + + std::cout << "Received (D) string " << sp->name << std::endl; + + } else { + + std::cout << "Received (D) change message with unknown type." << std::endl; + } +} + + int main() { std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); @@ -24,24 +163,11 @@ int main() { usleep(10); } - myProxy->getUAttribute().getChangedEvent().subscribe([&](const CommonTypes::SettingsUnion& v) { - - std::cout << "Received change message." << std::endl; - - if ( v.isType<CommonTypes::MyTypedef>() ) { - - std::cout << "Received MyTypedef with value " << v.get<CommonTypes::MyTypedef>() << std::endl; - } else if ( v.isType<CommonTypes::MyEnum>() ) { - - std::cout << "Received MyEnum with value " << (int) (v.get<CommonTypes::MyEnum>()) << std::endl; - } else if ( v.isType<uint8_t>() ) { - - std::cout << "Received uint8_t with value " << (int) (v.get<uint8_t>()) << std::endl; - } else if ( v.isType<std::string>() ) { + std::function<void (CommonTypes::SettingsUnion)> f = recv_msg; + myProxy->getUAttribute().getChangedEvent().subscribe(f); - std::cout << "Received string with value " << v.get<std::string>() << std::endl; - } - }); + std::function<void (std::shared_ptr<CommonTypes::SettingsStruct>)> f1 = recv_msg1; + myProxy->getXAttribute().getChangedEvent().subscribe(f1); while (true) { usleep(10); diff --git a/CommonAPI-Examples/e06Unions/src/typeUtils.hpp b/CommonAPI-Examples/e06Unions/src/typeUtils.hpp new file mode 100644 index 0000000..0dfb0f2 --- /dev/null +++ b/CommonAPI-Examples/e06Unions/src/typeUtils.hpp @@ -0,0 +1,27 @@ +/* Copyright (C) 2014 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/. */ + +#ifndef DE_BMW_EXAMPLES_TYPE_UTILS_H_ +#define DE_BMW_EXAMPLES_TYPE_UTILS_H_ + +#include <type_traits> + +template <typename SearchT, typename... T> +struct typeIdOf; + +template <typename SearchT, typename T> +struct typeIdOf<SearchT, T> { + + static const int value = std::is_same<SearchT, T>::value ? 1 : -1; +}; + +template <typename SearchT, typename T1, typename... T> +struct typeIdOf<SearchT, T1, T...> { + static const int value = std::is_same<SearchT, T1>::value ? sizeof...(T)+1 : typeIdOf<SearchT, T...>::value; +}; + +#endif // DE_BMW_EXAMPLES_TYPE_UTILS_H_ diff --git a/org.genivi.commonapi.core/src-gen/org/genivi/commonapi/core/deployment/.gitignore b/org.genivi.commonapi.core/src-gen/org/genivi/commonapi/core/deployment/.gitignore new file mode 100644 index 0000000..6f676af --- /dev/null +++ b/org.genivi.commonapi.core/src-gen/org/genivi/commonapi/core/deployment/.gitignore @@ -0,0 +1,2 @@ +/DeploymentInterfacePropertyAccessor.java +/DeploymentProviderPropertyAccessor.java |