2021-10-06 21:25:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2021-10-06 21:25:43 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2021-2023 Uwe Seimet
|
2021-10-06 21:25:43 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
#include "shared/piscsi_util.h"
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "shared/protobuf_util.h"
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "scsictl_display.h"
|
2022-10-08 17:26:04 +00:00
|
|
|
#include <sstream>
|
2023-10-15 06:38:15 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2022-10-08 17:26:04 +00:00
|
|
|
#include <iomanip>
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2022-12-05 17:58:23 +00:00
|
|
|
using namespace piscsi_interface;
|
2023-10-15 06:38:15 +00:00
|
|
|
using namespace piscsi_util;
|
2022-11-10 06:44:06 +00:00
|
|
|
using namespace protobuf_util;
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayDevicesInfo(const PbDevicesInfo& devices_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
const vector<PbDevice> devices(devices_info.devices().begin(), devices_info.devices().end());
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << ListDevices(devices);
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayDeviceInfo(const PbDevice& pb_device) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << " " << pb_device.id() << ":" << pb_device.unit() << " " << PbDeviceType_Name(pb_device.type())
|
2021-10-06 21:25:43 +00:00
|
|
|
<< " " << pb_device.vendor() << ":" << pb_device.product() << ":" << pb_device.revision();
|
|
|
|
|
|
|
|
if (pb_device.block_size()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << pb_device.block_size() << " bytes per sector";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.block_count()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << pb_device.block_size() * pb_device.block_count() << " bytes capacity";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pb_device.properties().supports_file() && !pb_device.file().name().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << pb_device.file().name();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
vector<string> properties;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().read_only()) {
|
2023-10-15 06:38:15 +00:00
|
|
|
properties.emplace_back("read-only");
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().protectable() && pb_device.status().protected_()) {
|
2023-10-15 06:38:15 +00:00
|
|
|
properties.emplace_back("protected");
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().stoppable() && pb_device.status().stopped()) {
|
2023-10-15 06:38:15 +00:00
|
|
|
properties.emplace_back("stopped");
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().removable() && pb_device.status().removed()) {
|
2023-10-15 06:38:15 +00:00
|
|
|
properties.emplace_back("removed");
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().lockable() && pb_device.status().locked()) {
|
2023-10-15 06:38:15 +00:00
|
|
|
properties.emplace_back("locked");
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
if (!properties.empty()) {
|
|
|
|
s << Join(properties) << " ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << DisplayParams(pb_device) << '\n';
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayVersionInfo(const PbVersionInfo& version_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << "piscsi server version: " << setfill('0') << setw(2) << version_info.major_version() << "."
|
|
|
|
<< setw(2) << version_info.minor_version();
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (version_info.patch_version() > 0) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "." << version_info.patch_version();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else if (version_info.patch_version() < 0) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " (development version)";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayLogLevelInfo(const PbLogLevelInfo& log_level_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (!log_level_info.log_levels_size()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " No log level settings available\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-12-05 17:58:23 +00:00
|
|
|
s << "piscsi log levels, sorted by severity:\n";
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
for (const auto& log_level : log_level_info.log_levels()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << log_level << '\n';
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
s << "Current piscsi log level: " << log_level_info.current_log_level() << '\n';
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayDeviceTypesInfo(const PbDeviceTypesInfo& device_types_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Supported device types and their properties:";
|
|
|
|
|
2021-11-14 01:36:35 +00:00
|
|
|
for (const auto& device_type_info : device_types_info.properties()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "\n " << PbDeviceType_Name(device_type_info.type()) << " ";
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2021-11-14 01:36:35 +00:00
|
|
|
const PbDeviceProperties& properties = device_type_info.properties();
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << DisplayAttributes(properties);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
if (properties.supports_file()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "Image file support\n ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
if (properties.supports_params()) {
|
|
|
|
s << "Parameter support\n ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << DisplayDefaultParameters(properties);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << DisplayBlockSizes(properties);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-10-12 20:10:56 +00:00
|
|
|
s << '\n';
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayReservedIdsInfo(const PbReservedIdsInfo& reserved_ids_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (reserved_ids_info.ids_size()) {
|
2023-10-15 06:38:15 +00:00
|
|
|
const set<int32_t> sorted_ids(reserved_ids_info.ids().begin(), reserved_ids_info.ids().end());
|
|
|
|
s << "Reserved device IDs: " << Join(sorted_ids) << '\n';
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayImageFile(const PbImageFile& image_file_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << image_file_info.name() << " " << image_file_info.size() << " bytes";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (image_file_info.read_only()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " read-only";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (image_file_info.type() != UNDEFINED) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << PbDeviceType_Name(image_file_info.type());
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayImageFilesInfo(const PbImageFilesInfo& image_files_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Default image file folder: " << image_files_info.default_image_folder() << '\n';
|
|
|
|
s << "Supported folder depth: " << image_files_info.depth() << '\n';
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
if (!image_files_info.image_files().empty()) {
|
|
|
|
vector<PbImageFile> image_files(image_files_info.image_files().begin(), image_files_info.image_files().end());
|
|
|
|
ranges::sort(image_files, [](const auto& a, const auto& b) { return a.name() < b.name(); });
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "Available image files:\n";
|
2021-11-14 01:36:35 +00:00
|
|
|
for (const auto& image_file : image_files) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
|
|
|
|
|
|
|
s << DisplayImageFile(image_file);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayNetworkInterfaces(const PbNetworkInterfacesInfo& network_interfaces_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
const set<string, less<>> sorted_interfaces(network_interfaces_info.name().begin(), network_interfaces_info.name().end());
|
|
|
|
s << "Available (up) network interfaces: " << Join(sorted_interfaces) << '\n';
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Supported image file extension to device type mappings:\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
for (const map<string, PbDeviceType, less<>> sorted_mappings(mapping_info.mapping().begin(), mapping_info.mapping().end());
|
|
|
|
const auto& [extension, type] : sorted_mappings) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << extension << "->" << PbDeviceType_Name(type) << '\n';
|
2023-10-30 12:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
string ScsictlDisplay::DisplayStatisticsInfo(const PbStatisticsInfo& statistics_info) const
|
|
|
|
{
|
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Statistics:\n";
|
|
|
|
|
|
|
|
// Sort by ascending ID, LUN and key and by descending category
|
|
|
|
vector<PbStatistics> sorted_statistics = { statistics_info.statistics().begin(), statistics_info.statistics().end() };
|
|
|
|
ranges::sort(sorted_statistics, [] (const PbStatistics& a, const PbStatistics& b) {
|
|
|
|
if (a.category() > b.category()) return true;
|
|
|
|
if (a.category() < b.category()) return false;
|
|
|
|
if (a.id() < b.id()) return true;
|
|
|
|
if (a.id() > b.id()) return false;
|
|
|
|
if (a.unit() < b.unit()) return true;
|
|
|
|
if (a.unit() > b.unit()) return false;
|
|
|
|
return a.key() < b.key();
|
|
|
|
});
|
|
|
|
|
|
|
|
PbStatisticsCategory prev_category = PbStatisticsCategory::CATEGORY_NONE;
|
|
|
|
for (const auto& statistics : sorted_statistics) {
|
|
|
|
if (statistics.category() != prev_category) {
|
|
|
|
// Strip leading "CATEGORY_"
|
|
|
|
s << " " << PbStatisticsCategory_Name(statistics.category()).substr(9) << '\n';
|
|
|
|
prev_category = statistics.category();
|
|
|
|
}
|
|
|
|
|
|
|
|
s << " " << statistics.id() << ":" << statistics.unit() << " " << statistics.key() << ": " << statistics.value() << '\n';
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2021-12-21 07:43:21 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info) const
|
2021-12-21 07:43:21 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
const map<int, PbOperationMetaData, less<>> operations(operation_info.operations().begin(), operation_info.operations().end());
|
2021-12-21 07:43:21 +00:00
|
|
|
|
|
|
|
// Copies result into a map sorted by operation name
|
2022-10-08 17:26:04 +00:00
|
|
|
auto unknown_operation = make_unique<PbOperationMetaData>();
|
|
|
|
map<string, PbOperationMetaData, less<>> sorted_operations;
|
|
|
|
|
2022-09-07 14:38:42 +00:00
|
|
|
for (const auto& [ordinal, meta_data] : operations) {
|
|
|
|
if (PbOperation_IsValid(static_cast<PbOperation>(ordinal))) {
|
|
|
|
sorted_operations[PbOperation_Name(static_cast<PbOperation>(ordinal))] = meta_data;
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If the server-side operation is unknown for the client use the server-provided operation name
|
|
|
|
// No further operation information is available in this case
|
2022-09-07 14:38:42 +00:00
|
|
|
sorted_operations[meta_data.server_side_name()] = *unknown_operation;
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
s << "Operations supported by piscsi server and their parameters:\n";
|
2022-09-07 14:38:42 +00:00
|
|
|
for (const auto& [name, meta_data] : sorted_operations) {
|
|
|
|
if (!meta_data.server_side_name().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << name;
|
2022-09-07 14:38:42 +00:00
|
|
|
if (!meta_data.description().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " (" << meta_data.description() << ")";
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << '\n';
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << DisplayParameters(meta_data);
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << name << " (Unknown server-side operation)\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string ScsictlDisplay::DisplayParams(const PbDevice& pb_device) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
ostringstream s;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
set<string, less<>> params;
|
|
|
|
for (const auto& [key, value] : pb_device.params()) {
|
|
|
|
params.insert(key + "=" + value);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << Join(params, ":");
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
return s.str();
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string ScsictlDisplay::DisplayAttributes(const PbDeviceProperties& props) const
|
|
|
|
{
|
|
|
|
ostringstream s;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
vector<string> properties;
|
|
|
|
if (props.read_only()) {
|
|
|
|
properties.emplace_back("read-only");
|
|
|
|
}
|
|
|
|
if (props.protectable()) {
|
|
|
|
properties.emplace_back("protectable");
|
|
|
|
}
|
|
|
|
if (props.stoppable()) {
|
|
|
|
properties.emplace_back("stoppable");
|
|
|
|
}
|
|
|
|
if (props.removable()) {
|
|
|
|
properties.emplace_back("removable");
|
|
|
|
}
|
|
|
|
if (props.lockable()) {
|
|
|
|
properties.emplace_back("lockable");
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
if (!properties.empty()) {
|
|
|
|
s << "Properties: " << Join(properties) << "\n ";
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
2023-10-15 06:38:15 +00:00
|
|
|
|
|
|
|
return s.str();
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string ScsictlDisplay::DisplayDefaultParameters(const PbDeviceProperties& properties) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
ostringstream s;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
if (!properties.default_params().empty()) {
|
|
|
|
set<string, less<>> params;
|
|
|
|
for (const auto& [key, value] : properties.default_params()) {
|
|
|
|
params.insert(key + "=" + value);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
2023-10-15 06:38:15 +00:00
|
|
|
|
|
|
|
s << "Default parameters: " << Join(params, "\n ");
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
return s.str();
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string ScsictlDisplay::DisplayBlockSizes(const PbDeviceProperties& properties) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
ostringstream s;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
if (properties.block_sizes_size()) {
|
|
|
|
const set<uint32_t> sorted_sizes(properties.block_sizes().begin(), properties.block_sizes().end());
|
|
|
|
s << "Configurable block sizes in bytes: " << Join(sorted_sizes);
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
2023-10-15 06:38:15 +00:00
|
|
|
|
|
|
|
return s.str();
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string ScsictlDisplay::DisplayParameters(const PbOperationMetaData& meta_data) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
vector<PbOperationParameter> sorted_parameters(meta_data.parameters().begin(), meta_data.parameters().end());
|
|
|
|
ranges::sort(sorted_parameters, [](const auto& a, const auto& b) { return a.name() < b.name(); });
|
|
|
|
|
|
|
|
ostringstream s;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
for (const auto& parameter : sorted_parameters) {
|
|
|
|
s << " " << parameter.name() << ": "
|
|
|
|
<< (parameter.is_mandatory() ? "mandatory" : "optional");
|
|
|
|
|
|
|
|
if (!parameter.description().empty()) {
|
|
|
|
s << " (" << parameter.description() << ")";
|
|
|
|
}
|
|
|
|
s << '\n';
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
s << DisplayPermittedValues(parameter);
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
if (!parameter.default_value().empty()) {
|
|
|
|
s << " Default value: " << parameter.default_value() << '\n';
|
|
|
|
}
|
|
|
|
}
|
2023-10-15 06:38:15 +00:00
|
|
|
|
|
|
|
return s.str();
|
2022-10-08 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string ScsictlDisplay::DisplayPermittedValues(const PbOperationParameter& parameter) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
ostringstream s;
|
2022-10-08 17:26:04 +00:00
|
|
|
if (parameter.permitted_values_size()) {
|
2023-10-15 06:38:15 +00:00
|
|
|
const set<string, less<>> sorted_values(parameter.permitted_values().begin(), parameter.permitted_values().end());
|
|
|
|
s << " Permitted values: " << Join(parameter.permitted_values()) << '\n';
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
2023-10-15 06:38:15 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|