#pragma once #include #include #include #include #include #include #include struct tcp_pcb; namespace vamp_pico { struct remote_display_state { std::bool_t active{}; std::char_t title[96]{}; std::char_t part[48]{}; std::char_t mode[24]{}; std::char_t focus[32]{}; std::bool_t backing{}; std::bool_t backing_available{true}; std::bool_t error{}; std::array phase{}; std::bool_t metronome{}; std::bool_t solos{true}; std::bool_t editing{}; std::uint32_t bpm{120U}; std::array title_image{}; std::uint32_t page{}; std::uint32_t pages{}; auto operator==(remote_display_state const &other) const -> std::bool_t { return backing_available == other.backing_available && error == other.error && phase == other.phase && active == other.active && std::string_view{title} == other.title && std::string_view{part} == other.part && std::string_view{mode} == other.mode && std::string_view{focus} == other.focus && backing == other.backing && metronome == other.metronome && solos == other.solos && editing == other.editing && bpm == other.bpm && title_image == other.title_image && page == other.page && pages == other.pages; } }; auto parse_remote_display_body(std::string_view body, vamp_pico::remote_display_state &state) -> std::bool_t; enum class http_status { IDLE, IN_FLIGHT, READY, }; enum class http_start_result { STARTED, BUSY, }; struct http_result { remote_request request{}; std::bool_t success{}; remote_display_state display{}; }; class http_client { public: http_client() = default; ~http_client(); http_client(http_client const &) = delete; auto operator=(http_client const &) -> http_client & = delete; http_client(http_client &&) = delete; auto operator=(http_client &&) -> http_client & = delete; // Accepted requests, including immediate failures, produce exactly one result. auto start(remote_request request, std::uint64_t now_ms) -> http_start_result; auto poll(std::uint64_t now_ms) -> http_status; auto take_result() -> std::optional; // Discards the request/result and returns to IDLE. Call before Wi-Fi deinit. auto cancel() -> void; // View remains valid until start/cancel. Copy only after matching the selected ID. auto title_image() const -> std::string_view; auto current_kind() const -> request_kind; private: friend struct http_client_callbacks; tcp_pcb *pcb_{}; http_status status_{http_status::IDLE}; remote_request request_{}; std::bool_t success_{}; std::uint64_t started_ms_{}; std::uint64_t timeout_ms_{}; std::array request_buffer_{}; std::size_t request_size_{}; std::array response_buffer_{}; std::size_t response_size_{}; std::size_t title_offset_{}; }; }