RASCSI/cpp/rascsi/rascsi_service.h
Uwe Seimet 621cc7d5a2
Code cleanup, especially casts, lambdas, data types, encapsulation (#952)
* Unit test updates

* Lambda syntax cleanup

* Use new-style casts

* Use std::none_of when saving the cache

* Use to_integer instead of casts

* Use accessors for getting CDB data

* Made ctrl_t private

* Improved encapsulation

* Replaced pointers by references

* Removed all remaining occurrences of DWORD and BYTE, making os.h obsolete
2022-11-02 07:36:25 +01:00

52 lines
1004 B
C++

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