2022-10-04 15:23:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021-2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "protobuf_serializer.h"
|
|
|
|
|
|
|
|
class RascsiResponse;
|
|
|
|
class RascsiImage;
|
|
|
|
class DeviceFactory;
|
|
|
|
class ControllerManager;
|
|
|
|
class PrimaryDevice;
|
|
|
|
class CommandContext;
|
|
|
|
|
|
|
|
class RascsiExecutor
|
|
|
|
{
|
|
|
|
RascsiResponse& rascsi_response;
|
|
|
|
|
|
|
|
RascsiImage& rascsi_image;
|
|
|
|
|
|
|
|
DeviceFactory& device_factory;
|
|
|
|
|
|
|
|
ControllerManager& controller_manager;
|
|
|
|
|
|
|
|
ProtobufSerializer serializer;
|
|
|
|
|
|
|
|
unordered_set<int> reserved_ids;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
RascsiExecutor(RascsiResponse& rascsi_response, RascsiImage& rascsi_image, DeviceFactory& device_factory,
|
|
|
|
ControllerManager& controller_manager)
|
|
|
|
: rascsi_response(rascsi_response), rascsi_image(rascsi_image), device_factory(device_factory),
|
|
|
|
controller_manager(controller_manager) {}
|
|
|
|
~RascsiExecutor() = default;
|
|
|
|
|
|
|
|
unordered_set<int> GetReservedIds() const { return reserved_ids; }
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
bool ProcessDeviceCmd(const CommandContext&, const PbDeviceDefinition&, const PbCommand&, bool);
|
2022-10-04 15:23:42 +00:00
|
|
|
bool ProcessCmd(const CommandContext&, const PbCommand&);
|
|
|
|
bool SetLogLevel(const string&) const;
|
|
|
|
bool Start(shared_ptr<PrimaryDevice>, bool) const;
|
|
|
|
bool Stop(shared_ptr<PrimaryDevice>, bool) const;
|
|
|
|
bool Eject(shared_ptr<PrimaryDevice>, bool) const;
|
|
|
|
bool Protect(shared_ptr<PrimaryDevice>, bool) const;
|
|
|
|
bool Unprotect(shared_ptr<PrimaryDevice>, bool) const;
|
|
|
|
bool Attach(const CommandContext&, const PbDeviceDefinition&, bool);
|
|
|
|
bool Insert(const CommandContext&, const PbDeviceDefinition&, shared_ptr<PrimaryDevice>, bool) const;
|
|
|
|
bool Detach(const CommandContext&, shared_ptr<PrimaryDevice>, bool) const;
|
|
|
|
void DetachAll();
|
|
|
|
bool ShutDown(const CommandContext&, const string&);
|
|
|
|
string SetReservedIds(string_view);
|
2022-10-23 19:51:39 +00:00
|
|
|
bool ValidateImageFile(const CommandContext&, shared_ptr<StorageDevice>, const string&, string&) const;
|
2022-10-04 15:23:42 +00:00
|
|
|
void PrintCommand(const PbCommand&, const PbDeviceDefinition&, bool) const;
|
|
|
|
string ValidateLunSetup(const PbCommand&) const;
|
|
|
|
bool VerifyExistingIdAndLun(const CommandContext&, int, int) const;
|
|
|
|
shared_ptr<PrimaryDevice> CreateDevice(const CommandContext&, const PbDeviceType, int, const string&) const;
|
2022-10-23 19:51:39 +00:00
|
|
|
bool SetSectorSize(const CommandContext&, shared_ptr<PrimaryDevice>, int) const;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
static bool ValidateOperationAgainstDevice(const CommandContext&, const shared_ptr<PrimaryDevice>,
|
2022-10-04 15:23:42 +00:00
|
|
|
const PbOperation&);
|
|
|
|
static bool ValidateIdAndLun(const CommandContext&, int, int);
|
|
|
|
static bool SetProductData(const CommandContext&, const PbDeviceDefinition&, shared_ptr<PrimaryDevice>);
|
|
|
|
|
|
|
|
};
|