57 lines
2.2 KiB
C++
57 lines
2.2 KiB
C++
#pragma once
|
|
#include "common/Gallery_Types.h"
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <variant>
|
|
namespace renderive::web {
|
|
enum class Gallery_Request_Error {
|
|
none,
|
|
invalid_json,
|
|
wrong_message_type,
|
|
missing_field,
|
|
invalid_field
|
|
};
|
|
template <class Value>
|
|
struct Gallery_Request_Result {
|
|
std::optional<Value> value;
|
|
Gallery_Request_Error error{};
|
|
[[nodiscard]] explicit operator bool() const noexcept {
|
|
return error == Gallery_Request_Error::none && value.has_value();
|
|
}
|
|
[[nodiscard]] const Value* operator->() const noexcept { return &*value; }
|
|
[[nodiscard]] const Value& operator*() const noexcept { return *value; }
|
|
};
|
|
struct Gallery_Open_Request {
|
|
std::string case_id;
|
|
Gallery_Frame_Mode frame_mode = Gallery_Frame_Mode::Low_Latency;
|
|
};
|
|
struct Gallery_Control_Patch_Request {
|
|
std::string target;
|
|
std::string patch_json;
|
|
};
|
|
class Gallery_Protocol final {
|
|
public:
|
|
[[nodiscard]] static std::string catalog_json();
|
|
[[nodiscard]] static bool is_case(std::string_view case_id);
|
|
[[nodiscard]] static std::string error_json(std::string_view message,
|
|
std::string_view field = {});
|
|
[[nodiscard]] static std::string observer_json(std::string_view case_id,
|
|
Gallery_Frame_Mode frame_mode,
|
|
std::string_view telemetry_json);
|
|
[[nodiscard]] static std::string case_json_from_controls(
|
|
std::string_view case_id,
|
|
std::string_view controls_json,
|
|
std::string_view telemetry_json,
|
|
std::string_view notice,
|
|
Gallery_Frame_Mode frame_mode,
|
|
bool manual_refresh);
|
|
[[nodiscard]] static Gallery_Request_Result<Gallery_Open_Request> open_request(std::string_view message);
|
|
[[nodiscard]] static Gallery_Request_Result<Gallery_Action_Request> action_request(std::string_view message);
|
|
[[nodiscard]] static Gallery_Request_Result<Gallery_Control_Patch_Request> control_patch_request(
|
|
std::string_view message);
|
|
[[nodiscard]] static bool action_available(std::string_view case_id, std::string_view action_id);
|
|
};
|
|
} // namespace renderive::web
|