2022-11-02 22:41:45 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "rascsi/command_context.h"
|
2022-11-04 07:22:32 +00:00
|
|
|
#include "rascsi/rascsi_service.h"
|
|
|
|
#include "rascsi/rascsi_image.h"
|
|
|
|
#include "rascsi/rascsi_response.h"
|
2022-11-02 22:41:45 +00:00
|
|
|
#include "rascsi_interface.pb.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
// TODO Only BUS should be known
|
|
|
|
class GPIOBUS;
|
|
|
|
class ControllerManager;
|
|
|
|
class RascsiExecutor;
|
|
|
|
|
2022-11-02 22:41:45 +00:00
|
|
|
class Rascsi
|
|
|
|
{
|
2022-11-04 07:22:32 +00:00
|
|
|
using optarg_queue_type = vector<pair<int, string>>;
|
2022-11-02 22:41:45 +00:00
|
|
|
|
|
|
|
static const int DEFAULT_PORT = 6868;
|
|
|
|
static const char COMPONENT_SEPARATOR = ':';
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Rascsi() = default;
|
|
|
|
~Rascsi() = default;
|
|
|
|
|
|
|
|
int run(const vector<char *>&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Banner(const vector<char *>&) const;
|
|
|
|
bool InitBus() const;
|
2022-11-04 07:22:32 +00:00
|
|
|
static void Cleanup();
|
2022-11-02 22:41:45 +00:00
|
|
|
bool ReadAccessToken(const char *) const;
|
|
|
|
void LogDevices(string_view) const;
|
2022-11-04 07:22:32 +00:00
|
|
|
static void TerminationHandler(int);
|
2022-11-02 22:41:45 +00:00
|
|
|
bool ProcessId(const string&, int&, int&) const;
|
|
|
|
bool ParseArguments(const vector<char *>&, int&, optarg_queue_type&) const;
|
|
|
|
bool CreateInitialDevices(const optarg_queue_type&) const;
|
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
// TODO Should not be static and should be moved to RascsiService
|
2022-11-02 22:41:45 +00:00
|
|
|
static bool ExecuteCommand(const CommandContext&, const PbCommand&);
|
|
|
|
|
2022-11-04 07:22:32 +00:00
|
|
|
// TODO These fields should not be static
|
|
|
|
|
|
|
|
static inline RascsiService service;
|
|
|
|
|
|
|
|
static inline RascsiImage rascsi_image;
|
|
|
|
|
|
|
|
const static inline RascsiResponse rascsi_response;
|
|
|
|
|
|
|
|
static inline shared_ptr<GPIOBUS> bus;
|
|
|
|
|
|
|
|
static inline shared_ptr<ControllerManager> controller_manager;
|
|
|
|
|
|
|
|
static inline shared_ptr<RascsiExecutor> 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;
|
|
|
|
};
|