mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-10 17:29:35 +00:00
Add param_map
This commit is contained in:
parent
f13ccbe166
commit
c40afec04f
|
@ -68,12 +68,12 @@ string ip_link(int fd, const char* ifname, bool up) {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool CTapDriver::Init(const unordered_map<string, string>& const_params)
|
||||
bool CTapDriver::Init(const param_map& const_params)
|
||||
{
|
||||
#ifndef __linux__
|
||||
return false;
|
||||
#else
|
||||
unordered_map<string, string> params = const_params;
|
||||
param_map params = const_params;
|
||||
stringstream s(params["interface"]);
|
||||
string interface;
|
||||
while (getline(s, interface, ',')) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "devices/device.h"
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -37,7 +38,7 @@ public:
|
|||
CTapDriver(CTapDriver&) = default;
|
||||
CTapDriver& operator=(const CTapDriver&) = default;
|
||||
|
||||
bool Init(const unordered_map<string, string>&);
|
||||
bool Init(const param_map&);
|
||||
void CleanUp() const;
|
||||
|
||||
void GetMacAddr(uint8_t *) const;
|
||||
|
|
|
@ -87,7 +87,7 @@ string Device::GetParam(const string& key) const
|
|||
return it == params.end() ? "" : it->second;
|
||||
}
|
||||
|
||||
void Device::SetParams(const unordered_map<string, string>& set_params)
|
||||
void Device::SetParams(const param_map& set_params)
|
||||
{
|
||||
params = default_params;
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ using namespace piscsi_interface;
|
|||
|
||||
using id_set = pair<int, int>;
|
||||
|
||||
using param_map = unordered_map<string, string>;
|
||||
|
||||
class Device //NOSONAR The number of fields and methods is justified, the complexity is low
|
||||
{
|
||||
const string DEFAULT_VENDOR = "PiSCSI";
|
||||
|
@ -61,10 +63,10 @@ class Device //NOSONAR The number of fields and methods is justified, the comple
|
|||
string revision;
|
||||
|
||||
// The parameters the device was created with
|
||||
unordered_map<string, string> params;
|
||||
param_map params;
|
||||
|
||||
// The default parameters
|
||||
unordered_map<string, string> default_params;
|
||||
param_map default_params;
|
||||
|
||||
// Sense Key and ASC
|
||||
// MSB Reserved (0x00)
|
||||
|
@ -91,7 +93,7 @@ protected:
|
|||
int GetStatusCode() const { return status_code; }
|
||||
|
||||
string GetParam(const string&) const;
|
||||
void SetParams(const unordered_map<string, string>&);
|
||||
void SetParams(const param_map&);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -134,7 +136,7 @@ public:
|
|||
void SupportsParams(bool b) { supports_params = b; }
|
||||
void SupportsFile(bool b) { supports_file = b; }
|
||||
auto GetParams() const { return params; }
|
||||
void SetDefaultParams(const unordered_map<string, string>& p) { default_params = p; }
|
||||
void SetDefaultParams(const param_map& p) { default_params = p; }
|
||||
|
||||
void SetStatusCode(int s) { status_code = s; }
|
||||
|
||||
|
|
|
@ -151,11 +151,11 @@ shared_ptr<PrimaryDevice> DeviceFactory::CreateDevice(PbDeviceType type, int lun
|
|||
const unordered_set<uint32_t>& DeviceFactory::GetSectorSizes(PbDeviceType type) const
|
||||
{
|
||||
const auto& it = sector_sizes.find(type);
|
||||
return it != sector_sizes.end() ? it->second : empty_set;
|
||||
return it != sector_sizes.end() ? it->second : EMPTY_SET;
|
||||
}
|
||||
|
||||
const unordered_map<string, string>& DeviceFactory::GetDefaultParams(PbDeviceType type) const
|
||||
const param_map& DeviceFactory::GetDefaultParams(PbDeviceType type) const
|
||||
{
|
||||
const auto& it = default_params.find(type);
|
||||
return it != default_params.end() ? it->second : empty_map;
|
||||
return it != default_params.end() ? it->second : EMPTY_PARAM_MAP;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "devices/device.h"
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
@ -33,19 +34,19 @@ public:
|
|||
shared_ptr<PrimaryDevice> CreateDevice(PbDeviceType, int, const string&) const;
|
||||
PbDeviceType GetTypeForFile(const string&) const;
|
||||
const unordered_set<uint32_t>& GetSectorSizes(PbDeviceType type) const;
|
||||
const unordered_map<string, string>& GetDefaultParams(PbDeviceType type) const;
|
||||
const param_map& GetDefaultParams(PbDeviceType type) const;
|
||||
const auto& GetExtensionMapping() const { return extension_mapping; }
|
||||
|
||||
private:
|
||||
|
||||
unordered_map<PbDeviceType, unordered_set<uint32_t>> sector_sizes;
|
||||
|
||||
unordered_map<PbDeviceType, unordered_map<string, string>> default_params;
|
||||
unordered_map<PbDeviceType, param_map> default_params;
|
||||
|
||||
unordered_map<string, PbDeviceType> extension_mapping;
|
||||
|
||||
unordered_map<string, PbDeviceType> device_mapping;
|
||||
|
||||
unordered_set<uint32_t> empty_set;
|
||||
unordered_map<string, string> empty_map;
|
||||
inline static const unordered_set<uint32_t> EMPTY_SET;
|
||||
inline static const param_map EMPTY_PARAM_MAP;
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
using namespace scsi_defs;
|
||||
using namespace scsi_command_util;
|
||||
|
||||
bool Disk::Init(const unordered_map<string, string>& params)
|
||||
bool Disk::Init(const param_map& params)
|
||||
{
|
||||
StorageDevice::Init(params);
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
using StorageDevice::StorageDevice;
|
||||
|
||||
bool Init(const unordered_map<string, string>&) override;
|
||||
bool Init(const param_map&) override;
|
||||
void CleanUp() override;
|
||||
|
||||
void Dispatch(scsi_command) override;
|
||||
|
|
|
@ -31,7 +31,7 @@ using namespace std::chrono;
|
|||
using namespace scsi_defs;
|
||||
using namespace scsi_command_util;
|
||||
|
||||
bool HostServices::Init(const unordered_map<string, string>& params)
|
||||
bool HostServices::Init(const param_map& params)
|
||||
{
|
||||
ModePageDevice::Init(params);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
explicit HostServices(int lun) : ModePageDevice(SCHS, lun) {}
|
||||
~HostServices() override = default;
|
||||
|
||||
bool Init(const unordered_map<string, string>&) override;
|
||||
bool Init(const param_map&) override;
|
||||
|
||||
vector<uint8_t> InquiryInternal() const override;
|
||||
void TestUnitReady() override;
|
||||
|
|
|
@ -20,7 +20,7 @@ using namespace std;
|
|||
using namespace scsi_defs;
|
||||
using namespace scsi_command_util;
|
||||
|
||||
bool ModePageDevice::Init(const unordered_map<string, string>& params)
|
||||
bool ModePageDevice::Init(const param_map& params)
|
||||
{
|
||||
PrimaryDevice::Init(params);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
|
||||
using PrimaryDevice::PrimaryDevice;
|
||||
|
||||
bool Init(const unordered_map<string, string>&) override;
|
||||
bool Init(const param_map&) override;
|
||||
|
||||
virtual void ModeSelect(scsi_defs::scsi_command, cdb_t, span<const uint8_t>, int) const;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ using namespace std;
|
|||
using namespace scsi_defs;
|
||||
using namespace scsi_command_util;
|
||||
|
||||
bool PrimaryDevice::Init(const unordered_map<string, string>& params)
|
||||
bool PrimaryDevice::Init(const param_map& params)
|
||||
{
|
||||
// Mandatory SCSI primary commands
|
||||
AddCommand(scsi_command::eCmdTestUnitReady, [this] { TestUnitReady(); });
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
PrimaryDevice(PbDeviceType type, int lun) : Device(type, lun) {}
|
||||
~PrimaryDevice() override = default;
|
||||
|
||||
virtual bool Init(const unordered_map<string, string>&);
|
||||
virtual bool Init(const param_map&);
|
||||
virtual void CleanUp() {
|
||||
// Override if cleanup work is required for a derived device
|
||||
};
|
||||
|
|
|
@ -38,7 +38,7 @@ SCSIDaynaPort::SCSIDaynaPort(int lun) : PrimaryDevice(SCDP, lun)
|
|||
SupportsParams(true);
|
||||
}
|
||||
|
||||
bool SCSIDaynaPort::Init(const unordered_map<string, string>& params)
|
||||
bool SCSIDaynaPort::Init(const param_map& params)
|
||||
{
|
||||
PrimaryDevice::Init(params);
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
explicit SCSIDaynaPort(int);
|
||||
~SCSIDaynaPort() override = default;
|
||||
|
||||
bool Init(const unordered_map<string, string>&) override;
|
||||
bool Init(const param_map&) override;
|
||||
void CleanUp() override;
|
||||
|
||||
// Commands
|
||||
|
|
|
@ -30,7 +30,7 @@ SCSIBR::SCSIBR(int lun) : PrimaryDevice(SCBR, lun)
|
|||
SupportsParams(true);
|
||||
}
|
||||
|
||||
bool SCSIBR::Init(const unordered_map<string, string>& params)
|
||||
bool SCSIBR::Init(const param_map& params)
|
||||
{
|
||||
PrimaryDevice::Init(params);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
explicit SCSIBR(int);
|
||||
~SCSIBR() override = default;
|
||||
|
||||
bool Init(const unordered_map<string, string>&) override;
|
||||
bool Init(const param_map&) override;
|
||||
void CleanUp() override;
|
||||
|
||||
// Commands
|
||||
|
|
|
@ -44,7 +44,7 @@ SCSIPrinter::SCSIPrinter(int lun) : PrimaryDevice(SCLP, lun)
|
|||
SupportsParams(true);
|
||||
}
|
||||
|
||||
bool SCSIPrinter::Init(const unordered_map<string, string>& params)
|
||||
bool SCSIPrinter::Init(const param_map& params)
|
||||
{
|
||||
PrimaryDevice::Init(params);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
explicit SCSIPrinter(int);
|
||||
~SCSIPrinter() override = default;
|
||||
|
||||
bool Init(const unordered_map<string, string>&) override;
|
||||
bool Init(const param_map&) override;
|
||||
void CleanUp() override;
|
||||
|
||||
vector<uint8_t> InquiryInternal() const override;
|
||||
|
|
|
@ -31,7 +31,7 @@ SCSICD::SCSICD(int lun, const unordered_set<uint32_t>& sector_sizes, scsi_defs::
|
|||
SetLockable(true);
|
||||
}
|
||||
|
||||
bool SCSICD::Init(const unordered_map<string, string>& params)
|
||||
bool SCSICD::Init(const param_map& params)
|
||||
{
|
||||
Disk::Init(params);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
SCSICD(int, const unordered_set<uint32_t>&, scsi_defs::scsi_level = scsi_level::scsi_2);
|
||||
~SCSICD() override = default;
|
||||
|
||||
bool Init(const unordered_map<string, string>&) override;
|
||||
bool Init(const param_map&) override;
|
||||
|
||||
void Open() override;
|
||||
|
||||
|
|
|
@ -277,7 +277,7 @@ bool PiscsiExecutor::Attach(const CommandContext& context, const PbDeviceDefinit
|
|||
return true;
|
||||
}
|
||||
|
||||
unordered_map<string, string> params = { pb_device.params().begin(), pb_device.params().end() };
|
||||
param_map params = { pb_device.params().begin(), pb_device.params().end() };
|
||||
if (!device->SupportsFile()) {
|
||||
// Clients like scsictl might have sent both "file" and "interfaces"
|
||||
params.erase("file");
|
||||
|
|
Loading…
Reference in New Issue
Block a user