//--------------------------------------------------------------------------- // // SCSI Target Emulator PiSCSI // for Raspberry Pi // // Copyright (C) 2021-2023 Uwe Seimet // //--------------------------------------------------------------------------- #pragma once #include "hal/bus.h" #include "controllers/controller_manager.h" #include "piscsi/piscsi_response.h" #include class PiscsiImage; class DeviceFactory; class PrimaryDevice; class StorageDevice; class CommandContext; using namespace spdlog; class PiscsiExecutor { public: PiscsiExecutor(PiscsiImage& piscsi_image, BUS& bus, ControllerManager& controller_manager) : piscsi_image(piscsi_image), bus(bus), controller_manager(controller_manager) {} ~PiscsiExecutor() = default; auto GetReservedIds() const { return reserved_ids; } bool ProcessDeviceCmd(const CommandContext&, const PbDeviceDefinition&, bool); bool ProcessCmd(const CommandContext&); bool Start(PrimaryDevice&, bool) const; bool Stop(PrimaryDevice&, bool) const; bool Eject(PrimaryDevice&, bool) const; bool Protect(PrimaryDevice&, bool) const; bool Unprotect(PrimaryDevice&, bool) const; bool Attach(const CommandContext&, const PbDeviceDefinition&, bool); bool Insert(const CommandContext&, const PbDeviceDefinition&, const shared_ptr&, bool) const; bool Detach(const CommandContext&, PrimaryDevice&, bool); void DetachAll(); bool ShutDown(const CommandContext&, const string&); string SetReservedIds(string_view); bool ValidateImageFile(const CommandContext&, StorageDevice&, const string&) const; string PrintCommand(const PbCommand&, const PbDeviceDefinition&) const; string EnsureLun0(const PbCommand&) const; bool VerifyExistingIdAndLun(const CommandContext&, int, int) const; shared_ptr CreateDevice(const CommandContext&, const PbDeviceType, int, const string&) const; bool SetSectorSize(const CommandContext&, shared_ptr, int) const; static bool ValidateOperationAgainstDevice(const CommandContext&, const PrimaryDevice&, PbOperation); static bool ValidateIdAndLun(const CommandContext&, int, int); static bool SetProductData(const CommandContext&, const PbDeviceDefinition&, PrimaryDevice&); private: static bool CheckForReservedFile(const CommandContext&, const string&); const PiscsiResponse piscsi_response; PiscsiImage& piscsi_image; BUS& bus; ControllerManager& controller_manager; const DeviceFactory device_factory; unordered_set reserved_ids; };