Fix Interface's default "create" Command parameters.

dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
Janusz 2019-08-29 11:59:54 +02:00 committed by Grzegorz Rychlik
parent 1fc5064956
commit 11b22130a3
3 changed files with 19 additions and 23 deletions

View File

@ -42,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 <>

View File

@ -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())

View File

@ -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;