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
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
2022-10-04 15:23:42 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-06 14:15:19 +00:00
|
|
|
#include <functional>
|
2022-10-04 15:23:42 +00:00
|
|
|
#include <thread>
|
2023-10-15 06:38:15 +00:00
|
|
|
#include <string>
|
2022-10-04 15:23:42 +00:00
|
|
|
|
|
|
|
class CommandContext;
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
using namespace std;
|
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
|
|
|
{
|
2023-10-15 06:38:15 +00:00
|
|
|
using callback = function<bool(CommandContext&)>;
|
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
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string Init(const callback&, int);
|
|
|
|
void Start();
|
|
|
|
void Stop();
|
|
|
|
bool IsRunning() const { return service_socket != -1 && service_thread.joinable(); }
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2022-10-23 19:51:39 +00:00
|
|
|
private:
|
|
|
|
|
2022-10-06 14:15:19 +00:00
|
|
|
void Execute() const;
|
2023-10-15 06:38:15 +00:00
|
|
|
void ExecuteCommand(int) const;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
callback execute;
|
2022-10-04 15:23:42 +00:00
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
jthread service_thread;
|
|
|
|
|
|
|
|
int service_socket = -1;
|
2022-10-04 15:23:42 +00:00
|
|
|
};
|