mirror of https://github.com/infosecn1nja/C3.git
Merge branch 'DefaultCreateCommand' into 'master'
Default create command See merge request C3/C3!129dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
commit
70b4d6c17a
|
@ -6,7 +6,6 @@
|
|||
|
||||
namespace MWR::C3
|
||||
{
|
||||
|
||||
/// Template class handling registration of Interface before main function.
|
||||
/// @tparam Iface. Interface to be registered.
|
||||
template <typename Iface, typename AbstractType, HashT clousureConnectorHash = 0>
|
||||
|
@ -43,21 +42,7 @@ namespace MWR::C3
|
|||
template <>
|
||||
static std::string GetCapability<false>()
|
||||
{
|
||||
return R"_(
|
||||
{
|
||||
"create":
|
||||
{
|
||||
"arguments":
|
||||
[
|
||||
{
|
||||
"type": "binary",
|
||||
"description": "Blob of data that will be provided to Channel constructor.",
|
||||
"name": "arguments"
|
||||
}
|
||||
]
|
||||
},
|
||||
"commands": []
|
||||
})_";
|
||||
return "{}";
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -104,56 +89,59 @@ namespace MWR::C3
|
|||
constexpr HashT Register<T, T2, u32>::s_InterfaceHash = Hash::Fnv1aType<T>();
|
||||
#pragma warning( pop )
|
||||
|
||||
/// Specialization of Registration mechanism for Channel type Interface.
|
||||
template <typename Iface>
|
||||
class Channel : public Register<Iface, AbstractChannel>
|
||||
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 <typename Iface>
|
||||
class Channel : public Register<Iface, AbstractChannel>
|
||||
{
|
||||
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 <typename Iface>
|
||||
class Connector : public Register<Iface, AbstractConnector>
|
||||
{
|
||||
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 <typename Iface>
|
||||
class Connector : public Register<Iface, AbstractConnector>
|
||||
{
|
||||
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 <typename Iface>
|
||||
class Connector : public AbstractConnector
|
||||
{
|
||||
};
|
||||
/// Don't register the connectors in node builds
|
||||
template <typename Iface>
|
||||
class Connector : public AbstractConnector
|
||||
{
|
||||
};
|
||||
#endif C3_IS_GATEWAY
|
||||
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4307)
|
||||
/// Specialization of Registration mechanism for Peripheral type Interface.
|
||||
template <typename Iface, typename Closure>
|
||||
class Peripheral : public Register<Iface, AbstractPeripheral, Hash::Fnv1aType<Closure>()>
|
||||
{
|
||||
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 <typename Iface, typename Closure>
|
||||
class Peripheral : public Register<Iface, AbstractPeripheral, Hash::Fnv1aType<Closure>()>
|
||||
{
|
||||
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 )
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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<std::unordered_map<std::string, std::vector<json>>> 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<std::string>()}, {"arguments", arguments}, {"id", id} });
|
||||
buffer[i][relayType].push_back(json{ {"name", prefix[i] + element["name"].get<std::string>()}, {"arguments", arguments}, {"id", id} });
|
||||
|
||||
m_CreateCommands.push_back({ id, initialPacket[interfaceType][idToErase]["type"].get<uint32_t>(), isDevice, !!i }); // store command id and hash.
|
||||
--id;
|
||||
|
@ -860,7 +873,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<std::underlying_type_t<NodeRelay::Command>>(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<std::underlying_type_t<NodeRelay::Command>>(NodeRelay::Command::UpdateJitter) },
|
||||
initialPacket[interfaceType][idToErase]["commands"].push_back(json{ {"name", "Set UpdateDelayJitter"}, {"description", "Set delay between receiving function calls."}, {"id", static_cast<std::underlying_type_t<NodeRelay::Command>>(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}}
|
||||
|
|
Loading…
Reference in New Issue