From 6f94296866b7e759222c5db5b2663570a76a19e5 Mon Sep 17 00:00:00 2001 From: Janusz Date: Tue, 27 Aug 2019 11:16:09 +0200 Subject: [PATCH 1/3] Put Channel<> and rest of CRTPs to Interfaces namespace. --- .../MWR/C3/Internals/AutomaticRegistrator.h | 86 ++++++++++--------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h b/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h index ef0e42e..20a008d 100644 --- a/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h +++ b/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h @@ -6,7 +6,6 @@ namespace MWR::C3 { - /// Template class handling registration of Interface before main function. /// @tparam Iface. Interface to be registered. template @@ -104,56 +103,59 @@ namespace MWR::C3 constexpr HashT Register::s_InterfaceHash = Hash::Fnv1aType(); #pragma warning( pop ) - /// Specialization of Registration mechanism for Channel type Interface. - template - class Channel : public Register + namespace Interfaces { - public: - constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 30ms; - constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 30ms; - - Channel() + /// Specialization of Registration mechanism for Channel type Interface. + template + class Channel : public Register { - static_assert(Iface::s_MinUpdateFrequency >= 30ms && Iface::s_MinUpdateFrequency <= Iface::s_MaxUpdateFrequency, "The frequency is set incorrectly"); - m_MinUpdateFrequency = Iface::s_MinUpdateFrequency; - m_MaxUpdateFrequency = Iface::s_MaxUpdateFrequency; - } - }; + public: + constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 30ms; + constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 30ms; + + Channel() + { + static_assert(Iface::s_MinUpdateFrequency >= 30ms && Iface::s_MinUpdateFrequency <= Iface::s_MaxUpdateFrequency, "The frequency is set incorrectly"); + m_MinUpdateFrequency = Iface::s_MinUpdateFrequency; + m_MaxUpdateFrequency = Iface::s_MaxUpdateFrequency; + } + }; #ifdef C3_IS_GATEWAY - /// Specialization of Registration mechanism for Connector type Interface. - template - class Connector : public Register - { - public: - // connector in fact does not need those values. They are here to satisfy template requirements. - constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 0ms; - constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 0ms; - }; + /// Specialization of Registration mechanism for Connector type Interface. + template + class Connector : public Register + { + public: + // connector in fact does not need those values. They are here to satisfy template requirements. + constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 0ms; + constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 0ms; + }; #else - /// Don't register the connectors in node builds - template - class Connector : public AbstractConnector - { - }; + /// Don't register the connectors in node builds + template + class Connector : public AbstractConnector + { + }; #endif C3_IS_GATEWAY #pragma warning( push ) #pragma warning( disable : 4307) - /// Specialization of Registration mechanism for Peripheral type Interface. - template - class Peripheral : public Register()> - { - public: - constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 30ms; - constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 30ms; - - Peripheral() + /// Specialization of Registration mechanism for Peripheral type Interface. + template + class Peripheral : public Register()> { - static_assert(Iface::s_MinUpdateFrequency >= 30ms && Iface::s_MinUpdateFrequency <= Iface::s_MaxUpdateFrequency, "The frequency is set incorrectly"); - m_MinUpdateFrequency = Iface::s_MinUpdateFrequency; - m_MaxUpdateFrequency = Iface::s_MaxUpdateFrequency; - } - }; + public: + constexpr static std::chrono::milliseconds s_MinUpdateFrequency = 30ms; + constexpr static std::chrono::milliseconds s_MaxUpdateFrequency = 30ms; + + Peripheral() + { + static_assert(Iface::s_MinUpdateFrequency >= 30ms && Iface::s_MinUpdateFrequency <= Iface::s_MaxUpdateFrequency, "The frequency is set incorrectly"); + m_MinUpdateFrequency = Iface::s_MinUpdateFrequency; + m_MaxUpdateFrequency = Iface::s_MaxUpdateFrequency; + } + }; #pragma warning( pop ) + } } From 1fc506495661ac18721c325a5b34e2a2e1c40502 Mon Sep 17 00:00:00 2001 From: Janusz Date: Tue, 27 Aug 2019 13:28:14 +0200 Subject: [PATCH 2/3] Fix Command name "UpdateDelayJitter" -> "Set UpdateDelayJitter" --- Src/Core/Profiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Core/Profiler.cpp b/Src/Core/Profiler.cpp index aa32b78..5d0c477 100644 --- a/Src/Core/Profiler.cpp +++ b/Src/Core/Profiler.cpp @@ -860,7 +860,7 @@ json MWR::C3::Core::Profiler::Gateway::GetCapability() initialPacket[interfaceType][idToErase].erase("create"); initialPacket[interfaceType][idToErase]["commands"].push_back(json{ {"name", isDevice ? "Close" : "TurnOff"}, {"id", static_cast>(NodeRelay::Command::Close) }, {"arguments", json::array()} }); if (isDevice) - initialPacket[interfaceType][idToErase]["commands"].push_back(json{ {"name", "UpdateDelayJitter"}, {"description", "Set delay between receiving function calls."}, {"id", static_cast>(NodeRelay::Command::UpdateJitter) }, + initialPacket[interfaceType][idToErase]["commands"].push_back(json{ {"name", "Set UpdateDelayJitter"}, {"description", "Set delay between receiving function calls."}, {"id", static_cast>(NodeRelay::Command::UpdateJitter) }, {"arguments", { {{"type", "float"}, {"name", "Min"}, {"description", "Minimal delay in seconds"}, {"min", 0.03}}, {{"type", "float"}, {"name", "Max"}, {"description", "Maximal delay in seconds. "}, {"min", 0.03}} From 11b22130a3d0160956e4007a62522dd3cd8d405e Mon Sep 17 00:00:00 2001 From: Janusz Date: Thu, 29 Aug 2019 11:59:54 +0200 Subject: [PATCH 3/3] Fix Interface's default "create" Command parameters. --- .../MWR/C3/Internals/AutomaticRegistrator.h | 16 +------------ .../MWR/C3/Internals/InterfaceFactory.cpp | 3 --- Src/Core/Profiler.cpp | 23 +++++++++++++++---- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h b/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h index 20a008d..12ee658 100644 --- a/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h +++ b/Src/Common/MWR/C3/Internals/AutomaticRegistrator.h @@ -42,21 +42,7 @@ namespace MWR::C3 template <> static std::string GetCapability() { - return R"_( -{ - "create": - { - "arguments": - [ - { - "type": "binary", - "description": "Blob of data that will be provided to Channel constructor.", - "name": "arguments" - } - ] - }, - "commands": [] -})_"; + return "{}"; } template <> diff --git a/Src/Common/MWR/C3/Internals/InterfaceFactory.cpp b/Src/Common/MWR/C3/Internals/InterfaceFactory.cpp index f6e0542..08906f8 100644 --- a/Src/Common/MWR/C3/Internals/InterfaceFactory.cpp +++ b/Src/Common/MWR/C3/Internals/InterfaceFactory.cpp @@ -23,9 +23,6 @@ std::string MWR::C3::InterfaceFactory::GetCapability() { json entry; entry["type"] = e.first; - if (e.second.m_Capability.empty() || e.second.m_Name.empty()) - continue; - entry["name"] = e.second.m_Name; auto pin = json::parse(e.second.m_Capability); for (const auto& j : pin.items()) diff --git a/Src/Core/Profiler.cpp b/Src/Core/Profiler.cpp index 5d0c477..2d0360c 100644 --- a/Src/Core/Profiler.cpp +++ b/Src/Core/Profiler.cpp @@ -119,7 +119,7 @@ MWR::ByteVector MWR::C3::Core::Profiler::TranslateArguments(json const& argument if (!argument.is_array()) translate(argument); else - for (auto subargument : argument) + for (auto const subargument : argument) translate(subargument); } @@ -825,6 +825,20 @@ json MWR::C3::Core::Profiler::Gateway::GetCapability() // Construct the InitialPacket. json initialPacket = json::parse(gateway->m_InterfaceFactory.GetCapability()); + for (auto& interface : initialPacket["channels"]) + if (!interface.contains("create")) + interface["create"] = json::parse(R"( + { + "arguments" : + [ + { + "type": "binary", + "description": "Blob of data that will be provided to Channel constructor.", + "name": "arguments" + } + ] + })"); + // Create method in interface is constructor. It must be a relay/gateway command. // initialPacket is copied to original to prevent iterator invalidation. // last 256 commands will be reserved for common commands. @@ -833,14 +847,13 @@ json MWR::C3::Core::Profiler::Gateway::GetCapability() auto idToErase = 0; std::vector>> buffer; buffer.resize(prefix.size()); - for (auto&& e : oryginal[interfaceType]) + for (auto&& element : oryginal[interfaceType]) { try { for (auto i = 0u; i < prefix.size(); ++i) { - - auto arguments = e.at("create").at("arguments"); + auto arguments = element.at("create").at("arguments"); if (i) // NegotiationChannel command { if (arguments.empty() || arguments[0].size() != 2) @@ -850,7 +863,7 @@ json MWR::C3::Core::Profiler::Gateway::GetCapability() } for (auto&& relayType : relayTypes) - buffer[i][relayType].push_back(json{ {"name", prefix[i] + e["name"].get()}, {"arguments", arguments}, {"id", id} }); + buffer[i][relayType].push_back(json{ {"name", prefix[i] + element["name"].get()}, {"arguments", arguments}, {"id", id} }); m_CreateCommands.push_back({ id, initialPacket[interfaceType][idToErase]["type"].get(), isDevice, !!i }); // store command id and hash. --id;