diff --git a/cpp/s2p/s2p_core.cpp b/cpp/s2p/s2p_core.cpp index 199c1b62..231990dc 100644 --- a/cpp/s2p/s2p_core.cpp +++ b/cpp/s2p/s2p_core.cpp @@ -270,8 +270,7 @@ void S2p::CreateDevices() int id = -1; int lun = -1; bool is_active = false; - const auto &properties = property_handler.GetProperties(); - for (const auto& [key, value] : properties) { + for (const auto &properties = property_handler.GetProperties(); const auto& [key, value] : properties) { if (!key.starts_with("device.")) { continue; } @@ -316,33 +315,8 @@ void S2p::CreateDevices() } const string &k = key_components[2]; - if (k == "active") { - // "active" has already been handled above - continue; - } - else if (k == "type") { - device->set_type(ParseDeviceType(value)); - } - else if (k == "block_size") { - if (int block_size; !GetAsUnsignedInt(value, block_size)) { - throw parser_exception(fmt::format("Invalid block size: {}", value)); - } - else { - assert(device); - device->set_block_size(block_size); - } - } - else if (k == "product_data") { - assert(device); - SetProductData(*device, value); - } - else if (k == "params") { - assert(device); - ParseParameters(*device, value); - } - else { - throw parser_exception(fmt::format("Unknown device definition key: '{}'", k)); - } + assert(device); + SetDeviceProperties(*device, k, value); } if (command.devices_size()) { @@ -364,6 +338,34 @@ void S2p::CreateDevices() } } +void S2p::SetDeviceProperties(PbDeviceDefinition &device, const string &key, const string &value) +{ + if (key == "active") { + // "active" has already been handled separately + return; + } + else if (key == "type") { + device.set_type(ParseDeviceType(value)); + } + else if (key == "block_size") { + if (int block_size; !GetAsUnsignedInt(value, block_size)) { + throw parser_exception(fmt::format("Invalid block size: {}", value)); + } + else { + device.set_block_size(block_size); + } + } + else if (key == "product_data") { + SetProductData(device, value); + } + else if (key == "params") { + ParseParameters(device, value); + } + else { + throw parser_exception(fmt::format("Unknown device definition key: '{}'", key)); + } +} + PbDeviceType S2p::ParseDeviceType(const string &value) { string t; diff --git a/cpp/s2p/s2p_core.h b/cpp/s2p/s2p_core.h index 1c50d9b6..3c38eb24 100644 --- a/cpp/s2p/s2p_core.h +++ b/cpp/s2p/s2p_core.h @@ -45,6 +45,7 @@ class S2p bool ExecuteCommand(CommandContext&); bool HandleDeviceListChange(const CommandContext&, PbOperation) const; + static void SetDeviceProperties(PbDeviceDefinition&, const string&, const string&); static PbDeviceType ParseDeviceType(const string&); string access_token;