Files
Renderive/web_server/app/Gallery_Protocol.h
T
2026-08-12 00:59:34 +08:00

52 lines
2.2 KiB
C++

#pragma once
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <variant>
namespace renderive::web {
enum class Gallery_Frame_Mode : std::uint8_t {
Manual,
Low_Latency,
Playback
};
struct Gallery_Open_Request {
std::string case_id;
Gallery_Frame_Mode frame_mode = Gallery_Frame_Mode::Low_Latency;
};
using Gallery_Value = std::variant<bool, double, std::string>;
struct Gallery_Action_Request {
std::string id;
std::optional<Gallery_Value> argument;
};
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);
[[nodiscard]] static std::optional<Gallery_Open_Request> open_request(std::string_view message);
[[nodiscard]] static std::optional<Gallery_Action_Request> action_request(std::string_view message);
[[nodiscard]] static std::optional<Gallery_Control_Patch_Request> control_patch_request(
std::string_view message);
[[nodiscard]] static std::size_t control_count(std::string_view case_id);
[[nodiscard]] static std::size_t control_count(std::string_view case_id, Gallery_Frame_Mode frame_mode);
[[nodiscard]] static std::size_t action_count(std::string_view case_id);
[[nodiscard]] static std::size_t action_count(std::string_view case_id, Gallery_Frame_Mode frame_mode);
[[nodiscard]] static bool action_available(std::string_view case_id, Gallery_Frame_Mode frame_mode, std::string_view action_id);
};
} // namespace renderive::web