mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-17 03:29:30 +00:00
Split list devices function into its own file. Rasutil drove unnecessary dependencies on protobuf for scsiloop
This commit is contained in:
parent
97e63a7b01
commit
66a0448fa8
65
cpp/list_devices.cpp
Normal file
65
cpp/list_devices.cpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SCSI Target Emulator RaSCSI Reloaded
|
||||||
|
// for Raspberry Pi
|
||||||
|
//
|
||||||
|
// Copyright (C) 2021-22 Uwe Seimet
|
||||||
|
// Copyright (C) 2022 akuker
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "rascsi_version.h"
|
||||||
|
#include "rasutil.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace rascsi_interface;
|
||||||
|
|
||||||
|
string ras_util::ListDevices(const list<PbDevice>& pb_devices)
|
||||||
|
{
|
||||||
|
if (pb_devices.empty()) {
|
||||||
|
return "No devices currently attached.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
ostringstream s;
|
||||||
|
s << "+----+-----+------+-------------------------------------\n"
|
||||||
|
<< "| ID | LUN | TYPE | IMAGE FILE\n"
|
||||||
|
<< "+----+-----+------+-------------------------------------\n";
|
||||||
|
|
||||||
|
list<PbDevice> devices = pb_devices;
|
||||||
|
devices.sort([](const auto& a, const auto& b) { return a.id() < b.id() || a.unit() < b.unit(); });
|
||||||
|
|
||||||
|
for (const auto& device : devices) {
|
||||||
|
string filename;
|
||||||
|
switch (device.type()) {
|
||||||
|
case SCBR:
|
||||||
|
filename = "X68000 HOST BRIDGE";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCDP:
|
||||||
|
filename = "DaynaPort SCSI/Link";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCHS:
|
||||||
|
filename = "Host Services";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCLP:
|
||||||
|
filename = "SCSI Printer";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
filename = device.file().name();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s << "| " << device.id() << " | " << device.unit() << " | " << PbDeviceType_Name(device.type()) << " | "
|
||||||
|
<< (filename.empty() ? "NO MEDIUM" : filename)
|
||||||
|
<< (!device.status().removed() && (device.properties().read_only() || device.status().protected_()) ? " (READ-ONLY)" : "")
|
||||||
|
<< '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
s << "+----+-----+------+-------------------------------------\n";
|
||||||
|
|
||||||
|
return s.str();
|
||||||
|
}
|
24
cpp/list_devices.h
Normal file
24
cpp/list_devices.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SCSI Target Emulator RaSCSI Reloaded
|
||||||
|
// for Raspberry Pi
|
||||||
|
//
|
||||||
|
// Copyright (C) 2021 Uwe Seimet
|
||||||
|
// Copyright (C) 2022 akuker
|
||||||
|
//
|
||||||
|
// Helper method to list devices in a table for rascsi & rasctl
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
#include "rascsi_interface.pb.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace ras_util
|
||||||
|
{
|
||||||
|
string ListDevices(const list<rascsi_interface::PbDevice>&);
|
||||||
|
}
|
|
@ -39,6 +39,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace spdlog;
|
using namespace spdlog;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
// for Raspberry Pi
|
// for Raspberry Pi
|
||||||
//
|
//
|
||||||
// Copyright (C) 2021-22 Uwe Seimet
|
// Copyright (C) 2021-22 Uwe Seimet
|
||||||
|
// Copyright (C) 2022 akuker
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -48,55 +49,6 @@ string ras_util::Banner(const string& app)
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
string ras_util::ListDevices(const list<PbDevice>& pb_devices)
|
|
||||||
{
|
|
||||||
if (pb_devices.empty()) {
|
|
||||||
return "No devices currently attached.\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
ostringstream s;
|
|
||||||
s << "+----+-----+------+-------------------------------------\n"
|
|
||||||
<< "| ID | LUN | TYPE | IMAGE FILE\n"
|
|
||||||
<< "+----+-----+------+-------------------------------------\n";
|
|
||||||
|
|
||||||
list<PbDevice> devices = pb_devices;
|
|
||||||
devices.sort([](const auto& a, const auto& b) { return a.id() < b.id() || a.unit() < b.unit(); });
|
|
||||||
|
|
||||||
for (const auto& device : devices) {
|
|
||||||
string filename;
|
|
||||||
switch (device.type()) {
|
|
||||||
case SCBR:
|
|
||||||
filename = "X68000 HOST BRIDGE";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCDP:
|
|
||||||
filename = "DaynaPort SCSI/Link";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCHS:
|
|
||||||
filename = "Host Services";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCLP:
|
|
||||||
filename = "SCSI Printer";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
filename = device.file().name();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
s << "| " << device.id() << " | " << device.unit() << " | " << PbDeviceType_Name(device.type()) << " | "
|
|
||||||
<< (filename.empty() ? "NO MEDIUM" : filename)
|
|
||||||
<< (!device.status().removed() && (device.properties().read_only() || device.status().protected_()) ? " (READ-ONLY)" : "")
|
|
||||||
<< '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
s << "+----+-----+------+-------------------------------------\n";
|
|
||||||
|
|
||||||
return s.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
string ras_util::GetExtensionLowerCase(const string& filename)
|
string ras_util::GetExtensionLowerCase(const string& filename)
|
||||||
{
|
{
|
||||||
string ext;
|
string ext;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user