2022-10-06 14:15:19 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2022-10-06 14:15:19 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2023-10-15 06:38:15 +00:00
|
|
|
// Copyright (C) 2021-2023 Uwe Seimet
|
2022-10-06 14:15:19 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "localizer.h"
|
2023-10-15 06:38:15 +00:00
|
|
|
#include "generated/piscsi_interface.pb.h"
|
2022-10-06 14:15:19 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std;
|
2022-12-05 17:58:23 +00:00
|
|
|
using namespace piscsi_interface;
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
class CommandContext
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
CommandContext(const PbCommand& cmd, string_view f, string_view l) : command(cmd), default_folder(f), locale(l) {}
|
|
|
|
explicit CommandContext(int f) : fd(f) {}
|
2022-10-06 14:15:19 +00:00
|
|
|
~CommandContext() = default;
|
|
|
|
|
2023-10-15 06:38:15 +00:00
|
|
|
string GetDefaultFolder() const { return default_folder; }
|
|
|
|
void SetDefaultFolder(string_view f) { default_folder = f; }
|
|
|
|
bool ReadCommand();
|
|
|
|
void WriteResult(const PbResult&) const;
|
2023-10-30 12:57:46 +00:00
|
|
|
bool WriteSuccessResult(PbResult&) const;
|
2023-10-15 06:38:15 +00:00
|
|
|
const PbCommand& GetCommand() const { return command; }
|
2022-10-06 14:15:19 +00:00
|
|
|
|
|
|
|
bool ReturnLocalizedError(LocalizationKey, const string& = "", const string& = "", const string& = "") const;
|
|
|
|
bool ReturnLocalizedError(LocalizationKey, PbErrorCode, const string& = "", const string& = "", const string& = "") const;
|
2023-10-15 06:38:15 +00:00
|
|
|
bool ReturnSuccessStatus() const;
|
|
|
|
bool ReturnErrorStatus(const string&) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool ReturnStatus(bool, const string&, PbErrorCode, bool) const;
|
|
|
|
|
|
|
|
const Localizer localizer;
|
|
|
|
|
|
|
|
PbCommand command;
|
|
|
|
|
|
|
|
string default_folder;
|
|
|
|
|
|
|
|
string locale;
|
|
|
|
|
|
|
|
int fd = -1;
|
2022-10-06 14:15:19 +00:00
|
|
|
};
|