2021-10-06 21:25:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-08-26 01:01:39 +00:00
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
2021-10-06 21:25:43 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2022-09-07 14:38:42 +00:00
|
|
|
// Copyright (C) 2021-2022 Uwe Seimet
|
2021-10-06 21:25:43 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "rascsi_interface.pb.h"
|
|
|
|
#include "rasutil.h"
|
|
|
|
#include "rasctl_display.h"
|
2022-10-08 17:26:04 +00:00
|
|
|
#include <sstream>
|
2021-10-06 21:25:43 +00:00
|
|
|
#include <list>
|
2022-10-08 17:26:04 +00:00
|
|
|
#include <iomanip>
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace rascsi_interface;
|
2021-10-17 06:51:14 +00:00
|
|
|
using namespace ras_util;
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::DisplayDevicesInfo(const PbDevicesInfo& devices_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
|
|
|
const list<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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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 << " ";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
bool hasProperty = false;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().read_only()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "read-only";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
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_()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "protected";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
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()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "stopped";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
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()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "removed";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
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()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "locked";
|
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 (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayParams(s, pb_device);
|
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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::DisplayVersionInfo(const PbVersionInfo& version_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "rascsi server version: " << setw(2) << setfill('0') << version_info.major_version() << "."
|
|
|
|
<< setw(2) << setfill('0') << version_info.minor_version();
|
|
|
|
|
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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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-10-08 17:26:04 +00:00
|
|
|
s << "rascsi log levels, sorted by severity:\n";
|
|
|
|
|
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-10-08 17:26:04 +00:00
|
|
|
s << "Current rascsi log level: " << log_level_info.current_log_level() << '\n';
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayAttributes(s, 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
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayDefaultParameters(s, properties);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayBlockSizes(s, 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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "Reserved device IDs: ";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
for (int i = 0; i < reserved_ids_info.ids_size(); i++) {
|
|
|
|
if(i) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << reserved_ids_info.ids(i);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << '\n';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s << "No reserved device 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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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
|
|
|
|
2021-11-14 01:36:35 +00:00
|
|
|
if (image_files_info.image_files().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " No image files available\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-11-14 01:36:35 +00:00
|
|
|
list<PbImageFile> image_files = { image_files_info.image_files().begin(), image_files_info.image_files().end() };
|
|
|
|
image_files.sort([](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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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;
|
|
|
|
|
|
|
|
s << "Available (up) network interfaces:\n";
|
|
|
|
|
|
|
|
const list<string> sorted_interfaces = { network_interfaces_info.name().begin(), network_interfaces_info.name().end() };
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
bool isFirst = true;
|
2022-10-08 17:26:04 +00:00
|
|
|
for (const auto& interface : sorted_interfaces) {
|
2021-10-06 21:25:43 +00:00
|
|
|
if (!isFirst) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
else {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
isFirst = false;
|
2022-10-08 17:26:04 +00:00
|
|
|
s << interface;
|
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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::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
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
const map<string, PbDeviceType, less<>> sorted_mappings = { mapping_info.mapping().begin(), mapping_info.mapping().end() };
|
|
|
|
|
|
|
|
for (const auto& [extension, type] : sorted_mappings) {
|
|
|
|
s << " " << extension << "->" << PbDeviceType_Name(type) << '\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-10-08 17:26:04 +00:00
|
|
|
string RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info) const
|
2021-12-21 07:43:21 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
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-10-08 17:26:04 +00:00
|
|
|
s << "Operations supported by rascsi 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';
|
|
|
|
|
|
|
|
DisplayParameters(s, 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayParams(ostringstream& s, const PbDevice& pb_device) const
|
|
|
|
{
|
|
|
|
const map<string, string, less<>> sorted_params = { pb_device.params().begin(), pb_device.params().end() };
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& [key, value] : sorted_params) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << ":";
|
|
|
|
}
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
s << key << "=" << value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayAttributes(ostringstream& s, const PbDeviceProperties& properties) const
|
|
|
|
{
|
|
|
|
if (properties.read_only() || properties.protectable() || properties.stoppable() || properties.lockable()) {
|
|
|
|
s << "Properties: ";
|
|
|
|
|
|
|
|
bool has_property = false;
|
|
|
|
|
|
|
|
if (properties.read_only()) {
|
|
|
|
s << "read-only";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (properties.protectable()) {
|
|
|
|
s << (has_property ? ", " : "") << "protectable";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.stoppable()) {
|
|
|
|
s << (has_property ? ", " : "") << "stoppable";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.removable()) {
|
|
|
|
s << (has_property ? ", " : "") << "removable";
|
|
|
|
has_property = true;
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
if (properties.lockable()) {
|
|
|
|
s << (has_property ? ", " : "") << "lockable";
|
|
|
|
}
|
|
|
|
|
|
|
|
s << "\n ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayDefaultParameters(ostringstream& s, const PbDeviceProperties& properties) const
|
|
|
|
{
|
|
|
|
if (properties.supports_params() && properties.default_params_size()) {
|
|
|
|
s << "Default parameters: ";
|
|
|
|
|
|
|
|
const map<string, string, less<>> sorted_params = { properties.default_params().begin(), properties.default_params().end() };
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& [key, value] : sorted_params) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << "\n ";
|
|
|
|
}
|
|
|
|
s << key << "=" << value;
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayBlockSizes(ostringstream& s, const PbDeviceProperties& properties) const
|
|
|
|
{
|
|
|
|
if (properties.block_sizes_size()) {
|
|
|
|
s << "Configurable block sizes in bytes: ";
|
|
|
|
|
|
|
|
const set<uint32_t> sorted_sizes = { properties.block_sizes().begin(), properties.block_sizes().end() };
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& size : sorted_sizes) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
s << size;
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayParameters(ostringstream& s, const PbOperationMetaData& meta_data) const
|
|
|
|
{
|
|
|
|
list<PbOperationParameter> sorted_parameters = { meta_data.parameters().begin(), meta_data.parameters().end() };
|
|
|
|
sorted_parameters.sort([](const auto& a, const auto& b) { return a.name() < b.name(); });
|
|
|
|
|
|
|
|
for (const auto& parameter : sorted_parameters) {
|
|
|
|
s << " " << parameter.name() << ": "
|
|
|
|
<< (parameter.is_mandatory() ? "mandatory" : "optional");
|
|
|
|
|
|
|
|
if (!parameter.description().empty()) {
|
|
|
|
s << " (" << parameter.description() << ")";
|
|
|
|
}
|
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
DisplayPermittedValues(s, parameter);
|
|
|
|
|
|
|
|
if (!parameter.default_value().empty()) {
|
|
|
|
s << " Default value: " << parameter.default_value() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayPermittedValues(ostringstream& s, const PbOperationParameter& parameter) const
|
|
|
|
{
|
|
|
|
if (parameter.permitted_values_size()) {
|
|
|
|
s << " Permitted values: ";
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
|
|
|
|
for (const auto& permitted_value : parameter.permitted_values()) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
s << permitted_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
s << '\n';
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
}
|