2022-11-02 22:41:45 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-11-02 22:41:45 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-11-02 22:41:45 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
#include "controllers/controller_manager.h"
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "piscsi/command_context.h"
|
|
|
|
#include "piscsi/piscsi_service.h"
|
|
|
|
#include "piscsi/piscsi_image.h"
|
|
|
|
#include "piscsi/piscsi_response.h"
|
2023-10-15 06:38:15 +00:00
|
|
|
#include "piscsi/piscsi_executor.h"
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "generated/piscsi_interface.pb.h"
|
2023-10-15 06:38:15 +00:00
|
|
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
|
|
|
#include <span>
|
2022-11-02 22:41:45 +00:00
|
|
|
#include <string>
|
2023-10-30 12:57:46 +00:00
|
|
|
#include <mutex>
|
2022-11-02 22:41:45 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2022-11-09 07:40:26 +00:00
|
|
|
class BUS;
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
class Piscsi
|
2022-11-02 22:41:45 +00:00
|
|
|
{
|
|
|
|
static const int DEFAULT_PORT = 6868;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
Piscsi() = default;
|
|
|
|
~Piscsi() = default;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
int run(span<char *>);
|
2022-11-02 22:41:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
void Banner(span<char *>) const;
|
|
|
|
bool InitBus();
|
|
|
|
void CleanUp();
|
|
|
|
void ReadAccessToken(const path&);
|
2022-11-02 22:41:45 +00:00
|
|
|
void LogDevices(string_view) const;
|
2022-11-04 07:22:32 +00:00
|
|
|
static void TerminationHandler(int);
|
2023-10-15 06:38:15 +00:00
|
|
|
string ParseArguments(span<char *>, PbCommand&, int&, string&);
|
|
|
|
void Process();
|
|
|
|
bool IsNotBusy() const;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
2023-10-30 12:57:46 +00:00
|
|
|
bool ShutDown(AbstractController::piscsi_shutdown_mode);
|
|
|
|
bool ShutDown(const CommandContext&, const string&);
|
2022-11-02 22:41:45 +00:00
|
|
|
|
2023-10-30 12:57:46 +00:00
|
|
|
bool ExecuteCommand(const CommandContext&);
|
|
|
|
bool ExecuteWithLock(const CommandContext&);
|
|
|
|
bool HandleDeviceListChange(const CommandContext&, PbOperation) const;
|
2022-11-11 20:08:48 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
bool SetLogLevel(const string&) const;
|
2022-11-10 06:44:06 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
const shared_ptr<spdlog::logger> logger = spdlog::stdout_color_mt("piscsi stdout logger");
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
static PbDeviceType ParseDeviceType(const string&);
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2023-10-30 12:57:46 +00:00
|
|
|
mutex execution_locker;
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string access_token;
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
PiscsiImage piscsi_image;
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
PiscsiResponse response;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
PiscsiService service;
|
|
|
|
|
|
|
|
unique_ptr<PiscsiExecutor> executor;
|
|
|
|
|
|
|
|
ControllerManager controller_manager;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
unique_ptr<BUS> bus;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
// Required for the termination handler
|
|
|
|
static inline Piscsi *instance;
|
2022-11-02 22:41:45 +00:00
|
|
|
};
|