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
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
#include "devices/device_logger.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"
|
|
|
|
#include "generated/piscsi_interface.pb.h"
|
2022-11-02 22:41:45 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2022-11-09 07:40:26 +00:00
|
|
|
class BUS;
|
2022-11-04 07:22:32 +00:00
|
|
|
class ControllerManager;
|
2022-12-05 17:58:23 +00:00
|
|
|
class PiscsiExecutor;
|
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
|
|
|
{
|
2022-11-10 06:44:06 +00:00
|
|
|
using optargs_type = vector<pair<int, string>>;
|
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
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
int run(const vector<char *>&);
|
2022-11-02 22:41:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Banner(const vector<char *>&) const;
|
|
|
|
bool InitBus() const;
|
2022-11-04 07:22:32 +00:00
|
|
|
static void Cleanup();
|
2022-11-10 06:44:06 +00:00
|
|
|
void ReadAccessToken(const string&) const;
|
2022-11-02 22:41:45 +00:00
|
|
|
void LogDevices(string_view) const;
|
2022-11-11 20:08:48 +00:00
|
|
|
PbDeviceType ParseDeviceType(const string&) const;
|
2022-11-04 07:22:32 +00:00
|
|
|
static void TerminationHandler(int);
|
2022-11-10 06:44:06 +00:00
|
|
|
optargs_type ParseArguments(const vector<char *>&, int&) const;
|
|
|
|
void CreateInitialDevices(const optargs_type&) const;
|
2022-11-11 20:08:48 +00:00
|
|
|
void WaitForNotBusy() const;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
// TODO Should not be static and should be moved to PiscsiService
|
2022-11-02 22:41:45 +00:00
|
|
|
static bool ExecuteCommand(const CommandContext&, const PbCommand&);
|
|
|
|
|
2022-11-11 20:08:48 +00:00
|
|
|
DeviceLogger device_logger;
|
|
|
|
|
2022-11-10 06:44:06 +00:00
|
|
|
// A static instance is needed because of the signal handler
|
|
|
|
static inline shared_ptr<BUS> bus;
|
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
// TODO These fields should not be static
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
static inline PiscsiService service;
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
static inline PiscsiImage piscsi_image;
|
2022-11-04 07:22:32 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
const static inline PiscsiResponse piscsi_response;
|
2022-11-04 07:22:32 +00:00
|
|
|
|
|
|
|
static inline shared_ptr<ControllerManager> controller_manager;
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
static inline shared_ptr<PiscsiExecutor> executor;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
|
|
|
// Processing flag
|
|
|
|
static inline volatile bool active;
|
|
|
|
|
|
|
|
// Some versions of spdlog do not support get_log_level(), so we have to remember the level
|
|
|
|
static inline string current_log_level = "info";
|
|
|
|
|
|
|
|
static inline string access_token;
|
|
|
|
};
|