Shared Catalog
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include <vamp_protocol/page_control.hpp>
|
||||
#include <vamp_pico/input.hpp>
|
||||
#include <modulus/types.hpp>
|
||||
|
||||
|
||||
struct tcp_pcb;
|
||||
|
||||
namespace vamp_pico {
|
||||
|
||||
struct remote_display_state {
|
||||
@@ -19,8 +24,50 @@ struct remote_display_state {
|
||||
};
|
||||
|
||||
auto parse_remote_display_body(std::string_view body, vamp_pico::remote_display_state &state) -> std::bool_t;
|
||||
auto post_remote_command(vamp_protocol::page_command command, vamp_pico::remote_display_state &state) -> std::bool_t;
|
||||
auto heartbeat() -> std::bool_t;
|
||||
auto fetch_remote_display(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;
|
||||
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, 1024> response_buffer_{};
|
||||
std::size_t response_size_{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user