2022-10-04 15:23:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-04 15:23:42 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "generated/piscsi_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-12-05 17:58:23 +00:00
|
|
|
using namespace piscsi_interface;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
class PiscsiService
|
2022-10-04 15:23:42 +00:00
|
|
|
{
|
2022-12-05 17:58:23 +00:00
|
|
|
using callback = function<bool(const CommandContext&, piscsi_interface::PbCommand&)>;
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
PiscsiService() = default;
|
|
|
|
~PiscsiService() = 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; }
|
|
|
|
};
|