From e1e451aee30f5e7f3508023aac001bcbb582f0ff Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Fri, 27 Aug 2021 19:16:56 +0200 Subject: [PATCH] Simplified protobuf interface --- src/raspberrypi/rascsi.cpp | 18 ++++--- src/raspberrypi/rascsi_interface.proto | 2 +- src/raspberrypi/rasctl.cpp | 66 ++++++++++++-------------- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 58c536de..4cb00db5 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -528,8 +528,9 @@ void GetLogLevels(PbServerInfo& serverInfo) void GetDeviceTypeFeatures(PbServerInfo& serverInfo) { PbDeviceTypeProperties *types_properties = serverInfo.add_types_properties(); - PbDeviceProperties *properties = types_properties->add_properties(); types_properties->set_type(SAHD); + PbDeviceProperties *properties = new PbDeviceProperties(); + types_properties->set_allocated_properties(properties); properties->set_supports_file(true); set block_sizes = device_factory.GetSasiSectorSizes(); for (const auto& block_size : block_sizes) { @@ -540,7 +541,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo) types_properties = serverInfo.add_types_properties(); types_properties->set_type(SCHD); - properties = types_properties->add_properties(); + properties = new PbDeviceProperties(); + types_properties->set_allocated_properties(properties); properties->set_protectable(true); properties->set_supports_file(true); for (const auto& block_size : block_sizes) { @@ -549,7 +551,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo) types_properties = serverInfo.add_types_properties(); types_properties->set_type(SCRM); - properties = types_properties->add_properties(); + properties = new PbDeviceProperties(); + types_properties->set_allocated_properties(properties); properties->set_protectable(true); properties->set_removable(true); properties->set_lockable(true); @@ -560,7 +563,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo) types_properties = serverInfo.add_types_properties(); types_properties->set_type(SCMO); - properties = types_properties->add_properties(); + properties = new PbDeviceProperties(); + types_properties->set_allocated_properties(properties); properties->set_protectable(true); properties->set_removable(true); properties->set_lockable(true); @@ -568,7 +572,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo) types_properties = serverInfo.add_types_properties(); types_properties->set_type(SCCD); - properties = types_properties->add_properties(); + properties = new PbDeviceProperties(); + types_properties->set_allocated_properties(properties); properties->set_read_only(true); properties->set_removable(true); properties->set_lockable(true); @@ -579,7 +584,8 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo) types_properties = serverInfo.add_types_properties(); types_properties->set_type(SCDP); - properties = types_properties->add_properties(); + properties = new PbDeviceProperties(); + types_properties->set_allocated_properties(properties); properties->set_supports_params(true); } diff --git a/src/raspberrypi/rascsi_interface.proto b/src/raspberrypi/rascsi_interface.proto index 45489bda..f121d91e 100644 --- a/src/raspberrypi/rascsi_interface.proto +++ b/src/raspberrypi/rascsi_interface.proto @@ -80,7 +80,7 @@ message PbDeviceStatus { // Device properties by device type message PbDeviceTypeProperties { PbDeviceType type = 1; - repeated PbDeviceProperties properties = 2; + PbDeviceProperties properties = 2; } // The image file data diff --git a/src/raspberrypi/rasctl.cpp b/src/raspberrypi/rasctl.cpp index 85cb0d56..b9c0457a 100644 --- a/src/raspberrypi/rasctl.cpp +++ b/src/raspberrypi/rasctl.cpp @@ -219,43 +219,39 @@ void CommandServerInfo(const string& hostname, int port) list block_sizes; cout << " Properties: "; - if (types_properties.properties_size()) { - for (int j = 0; j < types_properties.properties_size(); j++) { - bool has_property = false; - - PbDeviceProperties properties = types_properties.properties(j); - if (properties.read_only()) { - cout << "Read-only"; + bool has_property = false; + const PbDeviceProperties& properties = types_properties.properties(); + if (properties.read_only()) { + cout << "Read-only"; has_property = true; - } - if (properties.protectable()) { - cout << (has_property ? ", " : "") << "Protectable"; - has_property = true; - } - if (properties.removable()) { - cout << (has_property ? ", " : "") << "Removable"; - has_property = true; - } - if (properties.lockable()) { - cout << (has_property ? ", " : "") << "Lockable"; - has_property = true; - } - if (properties.supports_file()) { - cout << (has_property ? ", " : "") << "Image file support"; - } - else if (properties.supports_params()) { - cout << (has_property ? ", " : "") << "Parameter support"; - } - cout << endl; - - for (int k = 0 ; k < properties.block_sizes_size(); k++) - { - block_sizes.push_back(properties.block_sizes(k)); - } - } } - else { - cout << "None" << endl; + if (properties.protectable()) { + cout << (has_property ? ", " : "") << "Protectable"; + has_property = true; + } + if (properties.removable()) { + cout << (has_property ? ", " : "") << "Removable"; + has_property = true; + } + if (properties.lockable()) { + cout << (has_property ? ", " : "") << "Lockable"; + has_property = true; + } + if (properties.supports_file()) { + cout << (has_property ? ", " : "") << "Image file support"; + } + else if (properties.supports_params()) { + cout << (has_property ? ", " : "") << "Parameter support"; + } + + if (!has_property) { + cout << "None"; + } + cout << endl; + + for (int k = 0 ; k < properties.block_sizes_size(); k++) + { + block_sizes.push_back(properties.block_sizes(k)); } if (block_sizes.empty()) {