Separated device features and status in protobuf interface

This commit is contained in:
Uwe Seimet 2021-08-24 20:45:32 +02:00
parent 106d2d50d1
commit b53eb7c888
3 changed files with 46 additions and 30 deletions

View File

@ -290,13 +290,18 @@ const PbDevices GetDevices()
PbDeviceType_Parse(device->GetType(), &type);
pbDevice->set_type(type);
pbDevice->set_read_only(device->IsReadOnly());
pbDevice->set_protectable(device->IsProtectable());
pbDevice->set_protected_(device->IsProtectable() && device->IsProtected());
pbDevice->set_removable(device->IsRemovable());
pbDevice->set_removed(device->IsRemoved());
pbDevice->set_lockable(device->IsLockable());
pbDevice->set_locked(device->IsLocked());
PbDeviceFeatures *features = new PbDeviceFeatures();
pbDevice->set_allocated_features(features);
features->set_read_only(device->IsReadOnly());
features->set_protectable(device->IsProtectable());
features->set_removable(device->IsRemovable());
features->set_lockable(device->IsLockable());
PbDeviceStatus *status = new PbDeviceStatus();
pbDevice->set_allocated_status(status);
status->set_protected_(device->IsProtected());
status->set_removed(device->IsRemoved());
status->set_locked(device->IsLocked());
const Disk *disk = dynamic_cast<Disk*>(device);
if (disk) {
@ -329,7 +334,7 @@ const PbDevices GetDevices()
PbImageFile *image_file = new PbImageFile();
GetImageFile(image_file, device->IsRemovable() && !device->IsReady() ? "" : filepath.GetPath());
pbDevice->set_allocated_file(image_file);
pbDevice->set_supports_file(true);
features->set_supports_file(true);
}
}

View File

@ -49,6 +49,30 @@ enum PbOperation {
UNPROTECT = 9;
}
// The features supported by a device type
message PbDeviceFeatures {
// Read-only medium (e.g. CD-ROMs) are not protectable but permanently read-only
bool read_only = 1;
// Medium can be write-protected
bool protectable = 2;
// Medium can be removed
bool removable = 3;
// Medium can be locked
bool lockable = 4;
// Device supports image file
bool supports_file = 5;
}
// The status of a device
message PbDeviceStatus {
// Medium is write-protected
bool protected = 1;
// Medium is removed
bool removed = 2;
// Medium is locked
bool locked = 3;
}
// The image file data
message PbImageFile {
string name = 1;
@ -82,27 +106,13 @@ message PbDevice {
int32 id = 1;
int32 unit = 2;
PbDeviceType type = 3;
PbImageFile file = 4;
string vendor = 5;
string product = 6;
string revision = 7;
int32 block_size = 8;
// Read-only media (e.g. CD-ROMs) are not protectable but read-only all the time
bool read_only = 9;
// Media can be write-protected
bool protectable = 10;
// Media is write-protected
bool protected = 11;
// Media can be removed
bool removable = 12;
// Media is removed
bool removed = 13;
// Media can be locked
bool lockable = 14;
// Media is locked
bool locked = 15;
// Device supports image file
bool supports_file = 16;
PbDeviceFeatures features = 4;
PbDeviceStatus status = 5;
PbImageFile file = 6;
string vendor = 7;
string product = 8;
string revision = 9;
int32 block_size = 10;
}
message PbDevices {

View File

@ -59,7 +59,8 @@ string ListDevices(const PbDevices& devices)
s << "| " << device.id() << " | " << device.unit() << " | " << PbDeviceType_Name(device.type()) << " | "
<< (filename.empty() ? "NO MEDIA" : filename)
<< (!device.removed() && (device.read_only() || device.protected_()) ? " (WRITEPROTECT)" : "") << endl;
<< (!device.status().removed() && (device.features().read_only() || device.status().protected_()) ? " (WRITEPROTECT)" : "")
<< endl;
}
s << "+----+----+------+-------------------------------------";