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