diff options
Diffstat (limited to 'CommonAPI-Examples/E06Unions/src/E06UnionsClient.cpp')
-rw-r--r-- | CommonAPI-Examples/E06Unions/src/E06UnionsClient.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/CommonAPI-Examples/E06Unions/src/E06UnionsClient.cpp b/CommonAPI-Examples/E06Unions/src/E06UnionsClient.cpp index ea6618a..8998ac8 100644 --- a/CommonAPI-Examples/E06Unions/src/E06UnionsClient.cpp +++ b/CommonAPI-Examples/E06Unions/src/E06UnionsClient.cpp @@ -19,162 +19,162 @@ using namespace commonapi::examples; struct MyVisitor { - explicit inline 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); - } + 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) { + void operator()(CommonTypes::MyTypedef val) { - std::cout << "Received (C) MyTypedef with value " << (int)val << std::endl; - } + std::cout << "Received (C) MyTypedef with value " << (int)val << std::endl; + } - void operator()(CommonTypes::MyEnum val) { + void operator()(CommonTypes::MyEnum val) { - std::cout << "Received (C) MyEnum with value " << (int)val << std::endl; - } + std::cout << "Received (C) MyEnum with value " << (int)val << std::endl; + } - void operator()(uint8_t val) { + void operator()(uint8_t val) { - std::cout << "Received (C) uint8_t with value " << (int)val << std::endl; - } + std::cout << "Received (C) uint8_t with value " << (int)val << std::endl; + } - void operator()(std::string val) { + void operator()(std::string val) { - std::cout << "Received (C) string " << val << std::endl; - } + std::cout << "Received (C) string " << val << std::endl; + } - template<typename T> - void operator()(const T&) { + template<typename T> + void operator()(const T&) { - std::cout << "Received (C) change message with unknown type." << std::endl; - } + std::cout << "Received (C) change message with unknown type." << std::endl; + } - void operator()() { + void operator()() { - std::cout << "NOOP." << std::endl; - } + std::cout << "NOOP." << std::endl; + } }; void evalA (const CommonTypes::SettingsUnion& v) { - if ( v.isType<CommonTypes::MyTypedef>() ) { + if ( v.isType<CommonTypes::MyTypedef>() ) { - std::cout << "Received (A) MyTypedef with value " << v.get<CommonTypes::MyTypedef>() << " at index " << (int)v.getValueType() << std::endl; + std::cout << "Received (A) MyTypedef with value " << v.get<CommonTypes::MyTypedef>() << " at index " << (int)v.getValueType() << std::endl; - } else if ( v.isType<CommonTypes::MyEnum>() ) { + } 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; + 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>() ) { + } 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; + 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>() ) { + } else if ( v.isType<std::string>() ) { - std::cout << "Received (A) string " << v.get<std::string>() << " at index " << (int)v.getValueType() << std::endl; + std::cout << "Received (A) string " << v.get<std::string>() << " at index " << (int)v.getValueType() << std::endl; - } else { + } else { - std::cout << "Received (A) change message with unknown type." << std::endl; - } + 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()) { + switch (v.getValueType()) { - case typeIdOf<CommonTypes::MyTypedef, T1, T...>::value: + 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; + 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: + 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; + 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: + 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; + 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: + 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; + std::cout << "Received (B) string " << v.template get<std::string>() << " at index " << (int)v.getValueType() << std::endl; + break; - default: + default: - std::cout << "Received (B) change message with unknown type." << std::endl; - break; - } + std::cout << "Received (B) change message with unknown type." << std::endl; + break; + } } void evalC(const CommonTypes::SettingsUnion& v) { - MyVisitor visitor; - visitor.eval(v); + MyVisitor visitor; + visitor.eval(v); } void recv_msg(const CommonTypes::SettingsUnion& v) { - evalA(v); - evalB(v); - evalC(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) ) { + if ( std::shared_ptr<CommonTypes::SettingsStructMyTypedef> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructMyTypedef>(x) ) { - std::cout << "Received (D) MyTypedef with value " << (int)sp->getId() << std::endl; + std::cout << "Received (D) MyTypedef with value " << (int)sp->getId() << std::endl; - } else if ( std::shared_ptr<CommonTypes::SettingsStructMyEnum> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructMyEnum>(x) ) { + } else if ( std::shared_ptr<CommonTypes::SettingsStructMyEnum> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructMyEnum>(x) ) { - std::cout << "Received (D) MyEnum with value " << (int)sp->getStatus() << std::endl; + std::cout << "Received (D) MyEnum with value " << (int)sp->getStatus() << std::endl; - } else if ( std::shared_ptr<CommonTypes::SettingsStructUInt8> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructUInt8>(x) ) { + } 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->getChannel() << std::endl; + std::cout << "Received (D) uint8_t with value " << (int)sp->getChannel() << std::endl; - } else if ( std::shared_ptr<CommonTypes::SettingsStructString> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructString>(x) ) { + } else if ( std::shared_ptr<CommonTypes::SettingsStructString> sp = std::dynamic_pointer_cast<CommonTypes::SettingsStructString>(x) ) { - std::cout << "Received (D) string " << sp->getName() << std::endl; + std::cout << "Received (D) string " << sp->getName() << std::endl; - } else { + } else { - std::cout << "Received (D) change message with unknown type." << std::endl; - } + std::cout << "Received (D) change message with unknown type." << std::endl; + } } int main() { - CommonAPI::Runtime::setProperty("LogContext", "E06C"); - CommonAPI::Runtime::setProperty("LibraryBase", "E06Unions"); + CommonAPI::Runtime::setProperty("LogContext", "E06C"); + CommonAPI::Runtime::setProperty("LibraryBase", "E06Unions"); std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get(); const std::string &domain = "local"; - const std::string &instance = "commonapi.examples.Unions"; - std::string connection = "client-sample"; + const std::string &instance = "commonapi.examples.Unions"; + std::string connection = "client-sample"; - std::shared_ptr<E06UnionsProxy<>> myProxy = runtime->buildProxy<E06UnionsProxy>(domain, instance, connection); + std::shared_ptr<E06UnionsProxy<>> myProxy = runtime->buildProxy<E06UnionsProxy>(domain, instance, connection); while (!myProxy->isAvailable()) { usleep(10); } - std::function<void (CommonTypes::SettingsUnion)> f = recv_msg; - myProxy->getUAttribute().getChangedEvent().subscribe(f); + std::function<void (CommonTypes::SettingsUnion)> f = recv_msg; + myProxy->getUAttribute().getChangedEvent().subscribe(f); - std::function<void (std::shared_ptr<CommonTypes::SettingsStruct>)> f1 = recv_msg1; - myProxy->getXAttribute().getChangedEvent().subscribe(f1); + std::function<void (std::shared_ptr<CommonTypes::SettingsStruct>)> f1 = recv_msg1; + myProxy->getXAttribute().getChangedEvent().subscribe(f1); while (true) { usleep(10); |