Files
product-vamp/include/vamp_pico/http_client.hpp
T
khodowany 82349cf897
ci / checks (push) Failing after 23m37s
Playback
2026-10-05 23:41:11 -05:00

90 lines
2.8 KiB
C++

#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string_view>
#include <vamp_pico/input.hpp>
#include <modulus/types.hpp>
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<std::char_t, 16> phase{};
std::bool_t metronome{};
std::bool_t editing{};
std::uint32_t bpm{120U};
std::array<std::char_t, vamp_protocol::title_id_size + 1U> 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 && 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<http_result>;
// 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<std::char_t, 384> request_buffer_{};
std::size_t request_size_{};
std::array<std::char_t, vamp_protocol::title_image_size + 1024U> response_buffer_{};
std::size_t response_size_{};
std::size_t title_offset_{};
};
}