Added support for features lists to protobuf interface

This commit is contained in:
Uwe Seimet 2021-08-24 21:52:12 +02:00
parent b53eb7c888
commit 30e05d4933
3 changed files with 92 additions and 9 deletions

View File

@ -537,19 +537,62 @@ void LogDevices(const string& devices)
}
}
void GetAvailableLogLevels(PbServerInfo& serverInfo)
void GetLogLevels(PbServerInfo& serverInfo)
{
for (auto it = available_log_levels.begin(); it != available_log_levels.end(); ++it) {
serverInfo.add_available_log_levels(*it);
}
}
void GetDeviceTypeFeatures(PbServerInfo& serverInfo)
{
PbDeviceTypeFeatures *types_features = serverInfo.add_types_features();
PbDeviceFeatures *features = types_features->add_features();
types_features->set_type(SAHD);
features->set_supports_file(true);
types_features = serverInfo.add_types_features();
features = types_features->add_features();
types_features->set_type(SCHD);
features->set_protectable(true);
features->set_supports_file(true);
types_features = serverInfo.add_types_features();
features = types_features->add_features();
types_features->set_type(SCRM);
features->set_protectable(true);
features->set_removable(true);
features->set_supports_file(true);
types_features = serverInfo.add_types_features();
features = types_features->add_features();
types_features->set_type(SCMO);
features->set_protectable(true);
features->set_removable(true);
features->set_lockable(true);
features->set_supports_file(true);
types_features = serverInfo.add_types_features();
features = types_features->add_features();
types_features->set_type(SCCD);
features->set_read_only(true);
features->set_removable(true);
features->set_lockable(true);
features->set_supports_file(true);
types_features = serverInfo.add_types_features();
types_features->set_type(SCBR);
types_features = serverInfo.add_types_features();
types_features->set_type(SCDP);
}
void GetAvailableImages(PbServerInfo& serverInfo)
{
if (access(default_image_folder.c_str(), F_OK) != -1) {
for (const auto& entry : filesystem::directory_iterator(default_image_folder)) {
if (entry.is_regular_file()) {
PbImageFile *image_file = serverInfo.add_available_image_files();
PbImageFile *image_file = serverInfo.add_image_files();
GetImageFile(image_file, entry.path().filename());
}
}
@ -1173,9 +1216,10 @@ static void *MonThread(void *param)
case SERVER_INFO: {
PbServerInfo serverInfo;
serverInfo.set_rascsi_version(rascsi_get_version_string());
GetAvailableLogLevels(serverInfo);
GetLogLevels(serverInfo);
serverInfo.set_current_log_level(current_log_level);
serverInfo.set_default_image_folder(default_image_folder);
GetDeviceTypeFeatures(serverInfo);
GetAvailableImages(serverInfo);
serverInfo.set_allocated_devices(new PbDevices(GetDevices()));
SerializeMessage(fd, serverInfo);

View File

@ -49,7 +49,7 @@ enum PbOperation {
UNPROTECT = 9;
}
// The features supported by a device type
// The features supported by a device
message PbDeviceFeatures {
// Read-only medium (e.g. CD-ROMs) are not protectable but permanently read-only
bool read_only = 1;
@ -73,6 +73,12 @@ message PbDeviceStatus {
bool locked = 3;
}
// Device features by device type
message PbDeviceTypeFeatures {
PbDeviceType type = 1;
repeated PbDeviceFeatures features = 2;
}
// The image file data
message PbImageFile {
string name = 1;
@ -143,8 +149,10 @@ message PbServerInfo {
repeated string available_log_levels = 2;
string current_log_level = 3;
string default_image_folder = 4;
// Supported device types and their features
repeated PbDeviceTypeFeatures types_features = 5;
// Files in the default folder
repeated PbImageFile available_image_files = 5;
repeated PbImageFile image_files = 6;
// The attached devices
PbDevices devices = 6;
PbDevices devices = 7;
}

View File

@ -194,13 +194,13 @@ void CommandServerInfo(const string& hostname, int port)
}
cout << "Default image file folder: " << serverInfo.default_image_folder() << endl;
if (!serverInfo.available_image_files_size()) {
if (!serverInfo.image_files_size()) {
cout << " No image files available in the default folder" << endl;
}
else {
list<PbImageFile> sorted_files;
for (int i = 0; i < serverInfo.available_image_files_size(); i++) {
sorted_files.push_back(serverInfo.available_image_files(i));
for (int i = 0; i < serverInfo.image_files_size(); i++) {
sorted_files.push_back(serverInfo.image_files(i));
}
sorted_files.sort([](const PbImageFile& a, const PbImageFile& b) { return a.name() < b.name(); });
@ -213,6 +213,37 @@ void CommandServerInfo(const string& hostname, int port)
}
}
cout << "Available device types and their features:" << endl;
for (int i = 0; i < serverInfo.types_features_size(); i++) {
PbDeviceTypeFeatures type_features = serverInfo.types_features(i);
cout << " " << PbDeviceType_Name(type_features.type());
if (type_features.features_size()) {
for (int j = 0; j < type_features.features_size(); j++) {
PbDeviceFeatures features = type_features.features(j);
if (features.read_only()) {
cout << " Read-only";
}
if (features.protectable()) {
cout << " Protectable";
}
if (features.removable()) {
cout << " Removable";
}
if (features.lockable()) {
cout << " Lockable";
}
if (features.supports_file()) {
cout << " Image file support";
}
cout << endl;
}
}
else {
cout << endl;
}
}
cout << "Available devices:" << endl;
const PbDevices& devices = serverInfo.devices();
if (!devices.devices_size()) {