DAPSpecs: Update parseRequiredParamAsInt to support all param lists
This commit is contained in:
@@ -81,28 +81,29 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse a required integer parameter from provider parameters
|
||||
* @param spec The device attachment specification
|
||||
* @brief Parse a required integer parameter from a parameter list
|
||||
* @param params The parameter vector to search in
|
||||
* @param paramName The name of the parameter to parse
|
||||
* @return The parsed integer value
|
||||
* @throws std::runtime_error if parameter is not found or cannot be parsed
|
||||
*/
|
||||
static int parseRequiredParamAsInt(
|
||||
const DeviceAttachmentSpec& spec, const std::string& paramName
|
||||
const std::vector<std::pair<std::string,std::string>>& params,
|
||||
const std::string& paramName
|
||||
)
|
||||
{
|
||||
auto it = std::find_if(
|
||||
spec.providerParams.begin(),
|
||||
spec.providerParams.end(),
|
||||
params.begin(),
|
||||
params.end(),
|
||||
[¶mName](const auto& param) {
|
||||
return param.first == paramName;
|
||||
}
|
||||
);
|
||||
|
||||
if (it == spec.providerParams.end())
|
||||
if (it == params.end())
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"No " + paramName + " specified in provider params");
|
||||
"No " + paramName + " specified in params");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ std::string OptionParser::stringifyOptions(void) const
|
||||
oss << "Verbose mode is on" << std::endl;
|
||||
}
|
||||
|
||||
oss << "DAP Specs: " << dapSpecs << std::endl;
|
||||
oss << "Cmdline DAP Specs: " << dapSpecs << std::endl;
|
||||
|
||||
oss << "DAP Spec Files: ";
|
||||
for (const auto& file : dapSpecFiles) {
|
||||
|
||||
@@ -554,31 +554,34 @@ extern "C" void livoxGen1_attachDeviceReq(
|
||||
if (param.first == "handshake-timeout-ms")
|
||||
{
|
||||
handshakeTimeoutMs = smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*desc, "handshake-timeout-ms");
|
||||
::parseRequiredParamAsInt(
|
||||
desc->providerParams, "handshake-timeout-ms");
|
||||
} else if (param.first == "retry-delay-ms")
|
||||
{
|
||||
retryDelayMs = smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*desc, "retry-delay-ms");
|
||||
::parseRequiredParamAsInt(
|
||||
desc->providerParams, "retry-delay-ms");
|
||||
} else if (param.first == "smo-subnet-nbits")
|
||||
{
|
||||
smoSubnetNbits = static_cast<uint8_t>(
|
||||
smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*desc, "smo-subnet-nbits"));
|
||||
::parseRequiredParamAsInt(
|
||||
desc->providerParams, "smo-subnet-nbits"));
|
||||
} else if (param.first == "data-port")
|
||||
{
|
||||
dataPort = static_cast<uint16_t>(
|
||||
smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*desc, "data-port"));
|
||||
::parseRequiredParamAsInt(desc->providerParams, "data-port"));
|
||||
} else if (param.first == "cmd-port")
|
||||
{
|
||||
cmdPort = static_cast<uint16_t>(
|
||||
smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*desc, "cmd-port"));
|
||||
::parseRequiredParamAsInt(desc->providerParams, "cmd-port"));
|
||||
} else if (param.first == "imu-port")
|
||||
{
|
||||
imuPort = static_cast<uint16_t>(
|
||||
smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*desc, "imu-port"));
|
||||
::parseRequiredParamAsInt(desc->providerParams, "imu-port"));
|
||||
} else if (param.first == "smo-ip")
|
||||
{
|
||||
if (param.second.empty())
|
||||
|
||||
@@ -71,9 +71,9 @@ AttachedWindow::AttachedWindow(
|
||||
}
|
||||
|
||||
windowSelector.display = smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*spec, "display");
|
||||
::parseRequiredParamAsInt(spec->providerParams, "display");
|
||||
windowSelector.screen = smo::device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(*spec, "screen");
|
||||
::parseRequiredParamAsInt(spec->providerParams, "screen");
|
||||
|
||||
parseWindowSelector(*spec);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user