2022-10-04 15:23:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "rascsi_interface.pb.h"
|
2022-10-06 14:15:19 +00:00
|
|
|
#include <functional>
|
2022-10-04 15:23:42 +00:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
class CommandContext;
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2022-10-23 19:51:39 +00:00
|
|
|
using namespace rascsi_interface;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
class RascsiService
|
|
|
|
{
|
2022-10-06 14:15:19 +00:00
|
|
|
using callback = function<bool(const CommandContext&, rascsi_interface::PbCommand&)>;
|
|
|
|
|
|
|
|
callback execute;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
int service_socket = -1;
|
|
|
|
|
|
|
|
thread monthread;
|
|
|
|
|
2022-11-02 06:36:25 +00:00
|
|
|
static inline volatile bool running = false;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
RascsiService() = default;
|
2022-10-06 14:15:19 +00:00
|
|
|
~RascsiService() = default;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2022-10-06 14:15:19 +00:00
|
|
|
bool Init(const callback&, int);
|
|
|
|
void Cleanup() const;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
bool IsRunning() const { return running; }
|
|
|
|
void SetRunning(bool b) const { running = b; }
|
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
private:
|
|
|
|
|
2022-10-06 14:15:19 +00:00
|
|
|
void Execute() const;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2022-10-06 14:15:19 +00:00
|
|
|
PbCommand ReadCommand(CommandContext&) const;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
static void KillHandler(int) { running = false; }
|
|
|
|
};
|