mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-11 09:29:53 +00:00
rasctl server info display available devices
This commit is contained in:
parent
b44eae0fd5
commit
22fd98167a
@ -106,8 +106,7 @@ bool ReceiveResult(int fd)
|
|||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
void CommandList(const string& hostname, int port)
|
const PbServerInfo GetServerInfo(const string&hostname, int port) {
|
||||||
{
|
|
||||||
PbCommand command;
|
PbCommand command;
|
||||||
command.set_cmd(SERVER_INFO);
|
command.set_cmd(SERVER_INFO);
|
||||||
|
|
||||||
@ -127,6 +126,13 @@ void CommandList(const string& hostname, int port)
|
|||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
return serverInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandList(const string& hostname, int port)
|
||||||
|
{
|
||||||
|
PbServerInfo serverInfo = GetServerInfo(hostname, port);
|
||||||
|
|
||||||
cout << ListDevices(serverInfo.devices()) << endl;
|
cout << ListDevices(serverInfo.devices()) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,10 +206,33 @@ void CommandServerInfo(const string& hostname, int port)
|
|||||||
|
|
||||||
cout << "Image files available in the default folder:" << endl;
|
cout << "Image files available in the default folder:" << endl;
|
||||||
for (auto it = sorted_files.begin(); it != sorted_files.end(); ++it) {
|
for (auto it = sorted_files.begin(); it != sorted_files.end(); ++it) {
|
||||||
cout << " " << (*it).name() << " (" << (*it).size() << " bytes)" << ((*it).read_only() ? ", read-only": "")
|
const PbImageFile& file = *it;
|
||||||
|
|
||||||
|
cout << " " << file.name() << " (" << file.size() << " bytes)" << (file.read_only() ? ", read-only": "")
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cout << "Available devices:" << endl;
|
||||||
|
const PbDevices& devices = serverInfo.devices();
|
||||||
|
if (!devices.devices_size()) {
|
||||||
|
cout << "No devices available" << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
list<PbDevice> sorted_devices;
|
||||||
|
for (int i = 0; i < devices.devices_size(); i++) {
|
||||||
|
sorted_devices.push_back(devices.devices(i));
|
||||||
|
}
|
||||||
|
sorted_devices.sort([](const PbDevice& a, const PbDevice& b) { return a.id() < b.id(); });
|
||||||
|
|
||||||
|
for (auto it = sorted_devices.begin(); it != sorted_devices.end(); ++it) {
|
||||||
|
const PbDevice& device = *it;
|
||||||
|
|
||||||
|
cout << " " << device.id() << ":" << device.unit() << " " << PbDeviceType_Name(device.type())
|
||||||
|
<< " " << device.vendor() << ":" << device.product() << ":" << device.revision()
|
||||||
|
<< (device.file().name().empty() ? "" : " " + device.file().name()) << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PbOperation ParseOperation(const char *optarg)
|
PbOperation ParseOperation(const char *optarg)
|
||||||
@ -271,7 +300,7 @@ int main(int argc, char* argv[])
|
|||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
cerr << "SCSI Target Emulator RaSCSI Controller" << endl;
|
cerr << "SCSI Target Emulator RaSCSI Controller" << endl;
|
||||||
cerr << "version " << rascsi_get_version_string() << " (" << __DATE__ << ", " << __TIME__ << ")" << endl;
|
cerr << "version " << rascsi_get_version_string() << " (" << __DATE__ << ", " << __TIME__ << ")" << endl;
|
||||||
cerr << "Usage: " << argv[0] << " -i ID [-u UNIT] [-c CMD] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE] [-d DEFAULT_IMAGE_FOLDER] [-g LOG_LEVEL] [-h HOST] [-p PORT] [-v]" << endl;
|
cerr << "Usage: " << argv[0] << " -i ID [-u UNIT] [-c CMD] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE] [-d DEFAULT_IMAGE_FOLDER] [-g LOG_LEVEL] [-h HOST] [-p PORT] [-l] [-v]" << endl;
|
||||||
cerr << " where ID := {0|1|2|3|4|5|6|7}" << endl;
|
cerr << " where ID := {0|1|2|3|4|5|6|7}" << endl;
|
||||||
cerr << " UNIT := {0|1}, default setting is 0." << endl;
|
cerr << " UNIT := {0|1}, default setting is 0." << endl;
|
||||||
cerr << " CMD := {attach|detach|insert|eject|protect|unprotect}" << endl;
|
cerr << " CMD := {attach|detach|insert|eject|protect|unprotect}" << endl;
|
||||||
@ -304,7 +333,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
opterr = 1;
|
opterr = 1;
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "b:i:u:c:t:f:d:h:n:p:u:g:lsv")) != -1) {
|
while ((opt = getopt(argc, argv, "b:c:d:f:g:h:i:n:p:t:u:lsv")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'i':
|
case 'i':
|
||||||
device->set_id(optarg[0] - '0');
|
device->set_id(optarg[0] - '0');
|
||||||
@ -322,17 +351,22 @@ int main(int argc, char* argv[])
|
|||||||
command.set_cmd(ParseOperation(optarg));
|
command.set_cmd(ParseOperation(optarg));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 'd':
|
||||||
device->set_type(ParseType(optarg));
|
command.set_cmd(DEFAULT_FOLDER);
|
||||||
|
default_folder = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
device->set_file(optarg);
|
device->set_file(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 't':
|
||||||
command.set_cmd(DEFAULT_FOLDER);
|
device->set_type(ParseType(optarg));
|
||||||
default_folder = optarg;
|
break;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
command.set_cmd(LOG_LEVEL);
|
||||||
|
log_level = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -380,11 +414,6 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
|
||||||
command.set_cmd(LOG_LEVEL);
|
|
||||||
log_level = optarg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
command.set_cmd(SERVER_INFO);
|
command.set_cmd(SERVER_INFO);
|
||||||
break;
|
break;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "rascsi_interface.pb.h"
|
#include "rascsi_interface.pb.h"
|
||||||
#include "rasutil.h"
|
#include "rasutil.h"
|
||||||
@ -32,8 +33,14 @@ string ListDevices(const PbDevices& devices)
|
|||||||
return "No images currently attached.";
|
return "No images currently attached.";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < devices.devices_size() ; i++) {
|
list<PbDevice> sorted_devices;
|
||||||
PbDevice device = devices.devices(i);
|
for (int i = 0; i < devices.devices_size(); i++) {
|
||||||
|
sorted_devices.push_back(devices.devices(i));
|
||||||
|
}
|
||||||
|
sorted_devices.sort([](const PbDevice& a, const PbDevice& b) { return a.id() < b.id(); });
|
||||||
|
|
||||||
|
for (auto it = sorted_devices.begin(); it != sorted_devices.end(); ++it) {
|
||||||
|
const PbDevice& device = *it;
|
||||||
|
|
||||||
string filename;
|
string filename;
|
||||||
switch (device.type()) {
|
switch (device.type()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user