DAPSpecs: Update parseRequiredParamAsInt to support all param lists

This commit is contained in:
2025-11-01 01:11:34 -04:00
parent e824685c19
commit 67af9f02da
4 changed files with 20 additions and 16 deletions
+8 -7
View File
@@ -81,28 +81,29 @@ public:
} }
/** /**
* @brief Parse a required integer parameter from provider parameters * @brief Parse a required integer parameter from a parameter list
* @param spec The device attachment specification * @param params The parameter vector to search in
* @param paramName The name of the parameter to parse * @param paramName The name of the parameter to parse
* @return The parsed integer value * @return The parsed integer value
* @throws std::runtime_error if parameter is not found or cannot be parsed * @throws std::runtime_error if parameter is not found or cannot be parsed
*/ */
static int parseRequiredParamAsInt( 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( auto it = std::find_if(
spec.providerParams.begin(), params.begin(),
spec.providerParams.end(), params.end(),
[&paramName](const auto& param) { [&paramName](const auto& param) {
return param.first == paramName; return param.first == paramName;
} }
); );
if (it == spec.providerParams.end()) if (it == params.end())
{ {
throw std::runtime_error( throw std::runtime_error(
"No " + paramName + " specified in provider params"); "No " + paramName + " specified in params");
} }
try { try {
+1 -1
View File
@@ -121,7 +121,7 @@ std::string OptionParser::stringifyOptions(void) const
oss << "Verbose mode is on" << std::endl; oss << "Verbose mode is on" << std::endl;
} }
oss << "DAP Specs: " << dapSpecs << std::endl; oss << "Cmdline DAP Specs: " << dapSpecs << std::endl;
oss << "DAP Spec Files: "; oss << "DAP Spec Files: ";
for (const auto& file : dapSpecFiles) { for (const auto& file : dapSpecFiles) {
+9 -6
View File
@@ -554,31 +554,34 @@ extern "C" void livoxGen1_attachDeviceReq(
if (param.first == "handshake-timeout-ms") if (param.first == "handshake-timeout-ms")
{ {
handshakeTimeoutMs = smo::device::DeviceAttachmentSpec handshakeTimeoutMs = smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*desc, "handshake-timeout-ms"); ::parseRequiredParamAsInt(
desc->providerParams, "handshake-timeout-ms");
} else if (param.first == "retry-delay-ms") } else if (param.first == "retry-delay-ms")
{ {
retryDelayMs = smo::device::DeviceAttachmentSpec retryDelayMs = smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*desc, "retry-delay-ms"); ::parseRequiredParamAsInt(
desc->providerParams, "retry-delay-ms");
} else if (param.first == "smo-subnet-nbits") } else if (param.first == "smo-subnet-nbits")
{ {
smoSubnetNbits = static_cast<uint8_t>( smoSubnetNbits = static_cast<uint8_t>(
smo::device::DeviceAttachmentSpec smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*desc, "smo-subnet-nbits")); ::parseRequiredParamAsInt(
desc->providerParams, "smo-subnet-nbits"));
} else if (param.first == "data-port") } else if (param.first == "data-port")
{ {
dataPort = static_cast<uint16_t>( dataPort = static_cast<uint16_t>(
smo::device::DeviceAttachmentSpec smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*desc, "data-port")); ::parseRequiredParamAsInt(desc->providerParams, "data-port"));
} else if (param.first == "cmd-port") } else if (param.first == "cmd-port")
{ {
cmdPort = static_cast<uint16_t>( cmdPort = static_cast<uint16_t>(
smo::device::DeviceAttachmentSpec smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*desc, "cmd-port")); ::parseRequiredParamAsInt(desc->providerParams, "cmd-port"));
} else if (param.first == "imu-port") } else if (param.first == "imu-port")
{ {
imuPort = static_cast<uint16_t>( imuPort = static_cast<uint16_t>(
smo::device::DeviceAttachmentSpec smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*desc, "imu-port")); ::parseRequiredParamAsInt(desc->providerParams, "imu-port"));
} else if (param.first == "smo-ip") } else if (param.first == "smo-ip")
{ {
if (param.second.empty()) if (param.second.empty())
+2 -2
View File
@@ -71,9 +71,9 @@ AttachedWindow::AttachedWindow(
} }
windowSelector.display = smo::device::DeviceAttachmentSpec windowSelector.display = smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*spec, "display"); ::parseRequiredParamAsInt(spec->providerParams, "display");
windowSelector.screen = smo::device::DeviceAttachmentSpec windowSelector.screen = smo::device::DeviceAttachmentSpec
::parseRequiredParamAsInt(*spec, "screen"); ::parseRequiredParamAsInt(spec->providerParams, "screen");
parseWindowSelector(*spec); parseWindowSelector(*spec);