Add creating complementary channel

dependabot/npm_and_yarn/Src/WebController/UI/websocket-extensions-0.1.4
Grzegorz Rychlik 2019-10-29 14:18:56 +01:00
parent 7747a637a8
commit bac6392961
4 changed files with 33 additions and 1 deletions

View File

@ -68,6 +68,11 @@ try
auto createParams = form.FillForm(config.m_ChannelArguments);
auto channel = C3::Linter::MakeDevice(createParams, chInfo);
std::cout << "Create channel 2" << std::endl;
auto const& ch2Args = config.m_ComplementaryChannelArguments ? *config.m_ComplementaryChannelArguments : form.GetComplementaryArgs(createParams);
json createParams2 = form.FillForm(ch2Args);
auto ch2 = C3::Linter::MakeDevice(createParams2, chInfo);
}
catch (std::exception & e)
{

View File

@ -36,4 +36,25 @@ namespace MWR::C3::Linter
throw std::runtime_error("Failed to create channel: not enough arguments given");
}
}
StringVector Form::GetComplementaryArgs(json const& form)
{
std::vector<std::string> args;
for (auto const& arg : form)
{
if (arg.is_array())
{
for (size_t j = 0; j < arg.size(); ++j)
{
auto rotateRight = [s = arg.size()](size_t index) { return (index + 1) % s; };
args.emplace_back(arg[rotateRight(j)].at("value").get<std::string>());
}
}
else
{
args.emplace_back(arg["value"].get<std::string>());
}
}
return args;
}
}

View File

@ -9,6 +9,8 @@ namespace MWR::C3::Linter
json FillForm(InputVector input);
StringVector GetComplementaryArgs(json const& form);
private:
json m_ArgumentsForm;
};

View File

@ -10,6 +10,10 @@ namespace MWR::C3::Linter
InputContext::Config config;
config.m_ChannelName = parser.retrieve<std::string>("name");
config.m_ChannelArguments = parser.retrieve<std::vector<std::string>>("args");
if (parser.exists("complementary"))
config.m_ComplementaryChannelArguments = parser.retrieve<std::vector<std::string>>("complementary");
return config;
}
}
@ -25,7 +29,7 @@ namespace MWR::C3::Linter
{
m_ArgParser.addArgument("-n", "--name", 1, false);
m_ArgParser.addArgument("-a", "--args", '*', false);
m_ArgParser.addArgument("-c", "--complementary", '*');
}
std::string InputContext::GetUsage()