Files
battleship/include/http_api.h
T

57 lines
1.4 KiB
C

#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "application.h"
#include "app_config.h"
typedef enum { HTTP_API_GET, HTTP_API_POST } http_api_method_t;
typedef enum {
HTTP_API_ROUTE_INFO,
HTTP_API_ROUTE_HEALTH,
HTTP_API_ROUTE_JOIN,
HTTP_API_ROUTE_RESUME,
HTTP_API_ROUTE_CONFIG,
HTTP_API_ROUTE_START,
HTTP_API_ROUTE_SHOT,
HTTP_API_ROUTE_REMATCH,
HTTP_API_ROUTE_ABORT,
HTTP_API_ROUTE_STATE,
HTTP_API_ROUTE_STATISTICS,
} http_api_route_t;
typedef struct {
uint32_t uptime_ms;
uint32_t free_heap_bytes;
uint32_t minimum_free_heap_bytes;
uint32_t largest_free_block_bytes;
uint8_t connected_clients;
uint16_t rejected_input;
int8_t reset_reason;
const char *wifi_state;
} http_api_health_t;
typedef struct {
http_api_method_t method;
http_api_route_t route;
bool content_type_json;
bool target_too_large;
const char *body;
size_t body_length;
const char *session_token;
} http_api_request_t;
typedef struct {
uint16_t status;
char body[kStateMessageCapacity];
size_t body_length;
} http_api_response_t;
typedef struct { application_t *application; http_api_health_t health; } http_api_t;
void http_api_init(http_api_t *api, application_t *application);
void http_api_set_health(http_api_t *api, const http_api_health_t *health);
bool http_api_handle(http_api_t *api, const http_api_request_t *request, http_api_response_t *response);