Files
Renderive/web_server/app/Gallery_Protocol.h
T
2026-08-11 17:06:17 +08:00

69 lines
3.7 KiB
C++

#pragma once
#include "Gallery_Properties.h"
#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_State {
Gallery_Property_Model properties;
};
[[nodiscard]] Gallery_Value gallery_property_value(const Gallery_State& state, std::string_view id);
[[nodiscard]] bool gallery_has_property(const Gallery_State& state, std::string_view id);
[[nodiscard]] std::size_t gallery_property_count(const Gallery_State& state);
struct Gallery_Patch_Result {
std::optional<Gallery_State> candidate;
std::string response_json;
};
struct Gallery_Action_Request {
std::string id;
std::optional<Gallery_Value> argument;
};
class Gallery_Protocol final {
public:
[[nodiscard]] static std::string catalog_json();
[[nodiscard]] static bool is_case(std::string_view case_id);
[[nodiscard]] static Gallery_State default_state(std::string_view case_id);
[[nodiscard]] static Gallery_State default_state(std::string_view case_id, Gallery_Frame_Mode frame_mode);
[[nodiscard]] static std::string case_json(std::string_view case_id,
const Gallery_State& state,
std::string_view telemetry_json = "{}",
std::string_view notice = {});
[[nodiscard]] static std::string case_json(std::string_view case_id,
const Gallery_State& state,
std::string_view telemetry_json,
std::string_view notice,
Gallery_Frame_Mode frame_mode);
[[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 Gallery_Patch_Result apply_patch(std::string_view case_id,
const Gallery_State& current,
std::string_view message);
[[nodiscard]] static Gallery_Patch_Result apply_patch(std::string_view case_id,
const Gallery_State& current,
std::string_view message,
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::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