2022-10-04 17:23:42 +02:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 09:58:23 -08:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-04 17:23:42 +02:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 08:38:15 +02:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-04 17:23:42 +02:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-06 16:15:19 +02:00
|
|
|
#include <functional>
|
2022-10-04 17:23:42 +02:00
|
|
|
#include <thread>
|
2023-10-15 08:38:15 +02:00
|
|
|
#include <string>
|
2022-10-04 17:23:42 +02:00
|
|
|
|
|
|
|
class CommandContext;
|
2022-10-06 16:15:19 +02:00
|
|
|
|
|
|
|
using namespace std;
|
2022-10-04 17:23:42 +02:00
|
|
|
|
2022-12-05 09:58:23 -08:00
|
|
|
class PiscsiService
|
2022-10-04 17:23:42 +02:00
|
|
|
{
|
2023-10-15 08:38:15 +02:00
|
|
|
using callback = function<bool(CommandContext&)>;
|
2022-10-04 17:23:42 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2022-12-05 09:58:23 -08:00
|
|
|
PiscsiService() = default;
|
|
|
|
~PiscsiService() = default;
|
2022-10-04 17:23:42 +02:00
|
|
|
|
2023-10-15 08:38:15 +02:00
|
|
|
string Init(const callback&, int);
|
|
|
|
void Start();
|
|
|
|
void Stop();
|
|
|
|
bool IsRunning() const { return service_socket != -1 && service_thread.joinable(); }
|
2022-10-04 17:23:42 +02:00
|
|
|
|
2022-10-23 21:51:39 +02:00
|
|
|
private:
|
|
|
|
|
2022-10-06 16:15:19 +02:00
|
|
|
void Execute() const;
|
2023-10-15 08:38:15 +02:00
|
|
|
void ExecuteCommand(int) const;
|
2022-10-04 17:23:42 +02:00
|
|
|
|
2023-10-15 08:38:15 +02:00
|
|
|
callback execute;
|
2022-10-04 17:23:42 +02:00
|
|
|
|
2023-10-15 08:38:15 +02:00
|
|
|
jthread service_thread;
|
|
|
|
|
|
|
|
int service_socket = -1;
|
2022-10-04 17:23:42 +02:00
|
|
|
};
|