mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
454c61ac0d
* Support for ID and LUN parameter for the -L option in rascsi * Added DeviceLogger class * Removed dupiicate code * Fixed SonarQube issues * Added unit tests, improved code sharing * Fixed regression (#979)
143 lines
3.8 KiB
C++
143 lines
3.8 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2021-2022 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include "shared/log.h"
|
|
#include "generated/rascsi_interface.pb.h"
|
|
#include <unordered_map>
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
using namespace rascsi_interface;
|
|
|
|
class Device //NOSONAR The number of fields and methods is justified, the complexity is low
|
|
{
|
|
const string DEFAULT_VENDOR = "RaSCSI";
|
|
|
|
PbDeviceType type;
|
|
|
|
bool ready = false;
|
|
bool reset = false;
|
|
bool attn = false;
|
|
|
|
// Device is protectable/write-protected
|
|
bool protectable = false;
|
|
bool write_protected = false;
|
|
// Device is permanently read-only
|
|
bool read_only = false;
|
|
|
|
// Device can be stopped (parked)/is stopped (parked)
|
|
bool stoppable = false;
|
|
bool stopped = false;
|
|
|
|
// Device is removable/removed
|
|
bool removable = false;
|
|
bool removed = false;
|
|
|
|
// Device is lockable/locked
|
|
bool lockable = false;
|
|
bool locked = false;
|
|
|
|
// A device can be created with parameters
|
|
bool supports_params = false;
|
|
|
|
// A device can support an image file
|
|
bool supports_file = false;
|
|
|
|
// Immutable LUN
|
|
int lun;
|
|
|
|
// Device identifier (for INQUIRY)
|
|
string vendor = DEFAULT_VENDOR;
|
|
string product;
|
|
string revision;
|
|
|
|
// The parameters the device was created with
|
|
unordered_map<string, string> params;
|
|
|
|
// The default parameters
|
|
unordered_map<string, string> default_params;
|
|
|
|
// Sense Key and ASC
|
|
// MSB Reserved (0x00)
|
|
// Sense Key
|
|
// Additional Sense Code (ASC)
|
|
int status_code = 0;
|
|
|
|
protected:
|
|
|
|
Device(PbDeviceType, int);
|
|
|
|
void SetReady(bool b) { ready = b; }
|
|
bool IsReset() const { return reset; }
|
|
void SetReset(bool b) { reset = b; }
|
|
bool IsAttn() const { return attn; }
|
|
void SetAttn(bool b) { attn = b; }
|
|
|
|
void SetRemovable(bool b) { removable = b; }
|
|
void SetStoppable(bool b) { stoppable = b; }
|
|
void SetStopped(bool b) { stopped = b; }
|
|
void SetLockable(bool b) { lockable = b; }
|
|
void SetLocked(bool b) { locked = b; }
|
|
|
|
int GetStatusCode() const { return status_code; }
|
|
|
|
string GetParam(const string&) const;
|
|
void SetParams(const unordered_map<string, string>&);
|
|
|
|
public:
|
|
|
|
virtual ~Device() = default;
|
|
|
|
PbDeviceType GetType() const { return type; }
|
|
const char *GetTypeString() const { return PbDeviceType_Name(type).c_str(); }
|
|
|
|
bool IsReady() const { return ready; }
|
|
virtual void Reset();
|
|
|
|
bool IsProtectable() const { return protectable; }
|
|
void SetProtectable(bool b) { protectable = b; }
|
|
bool IsProtected() const { return write_protected; }
|
|
void SetProtected(bool);
|
|
bool IsReadOnly() const { return read_only; }
|
|
void SetReadOnly(bool b) { read_only = b; }
|
|
bool IsStoppable() const { return stoppable; }
|
|
bool IsStopped() const { return stopped; }
|
|
bool IsRemovable() const { return removable; }
|
|
bool IsRemoved() const { return removed; }
|
|
void SetRemoved(bool b) { removed = b; }
|
|
bool IsLockable() const { return lockable; }
|
|
bool IsLocked() const { return locked; }
|
|
|
|
virtual int GetId() const = 0;
|
|
int GetLun() const { return lun; }
|
|
|
|
string GetVendor() const { return vendor; }
|
|
void SetVendor(const string&);
|
|
string GetProduct() const { return product; }
|
|
void SetProduct(const string&, bool = true);
|
|
string GetRevision() const { return revision; }
|
|
void SetRevision(const string&);
|
|
string GetPaddedName() const;
|
|
|
|
bool SupportsParams() const { return supports_params; }
|
|
bool SupportsFile() const { return supports_file; }
|
|
void SupportsParams(bool b) { supports_params = b; }
|
|
void SupportsFile(bool b) { supports_file = b; }
|
|
unordered_map<string, string> GetParams() const { return params; }
|
|
void SetDefaultParams(const unordered_map<string, string>& p) { default_params = p; }
|
|
|
|
void SetStatusCode(int s) { status_code = s; }
|
|
|
|
bool Start();
|
|
void Stop();
|
|
virtual bool Eject(bool);
|
|
};
|