feat: implement the production HTTP API
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct { uint64_t (*now_ms)(void *context); void *context; } clock_t;
|
||||
typedef struct { uint64_t (*now_ms)(void *context); void *context; } app_clock_t;
|
||||
typedef struct { uint32_t (*next_u32)(void *context); void *context; } random_source_t;
|
||||
typedef struct { bool (*schedule_after_ms)(void *context, uint32_t delay_ms); void *context; } scheduler_t;
|
||||
typedef struct { bool (*send)(void *context, int client_id, const char *data, size_t length); void *context; } transport_t;
|
||||
|
||||
@@ -8,5 +8,13 @@
|
||||
/* The application task is the sole owner of lifecycle and game mutations. */
|
||||
typedef struct { command_queue_t command_queue; game_lifecycle_t lifecycle; } application_t;
|
||||
|
||||
void application_init(application_t *application, random_source_t random);
|
||||
bool application_enqueue(application_t *application, const app_command_t *command);
|
||||
bool application_take_next_command(application_t *application, app_command_t *command);
|
||||
lifecycle_result_t application_join(application_t *application, role_t requested_role, const char *name,
|
||||
uint8_t *session_index);
|
||||
lifecycle_result_t application_resume(application_t *application,
|
||||
const uint8_t token[kSessionTokenBytes], uint8_t *session_index);
|
||||
bool application_session_for_token(const application_t *application,
|
||||
const uint8_t token[kSessionTokenBytes], uint8_t *session_index);
|
||||
lifecycle_result_t application_submit(application_t *application, const app_command_t *command);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#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_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;
|
||||
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);
|
||||
@@ -32,6 +32,8 @@ session_result_t session_manager_join(session_manager_t *manager, role_t request
|
||||
random_source_t random, uint8_t *session_index);
|
||||
session_result_t session_manager_resume(session_manager_t *manager, const uint8_t token[kSessionTokenBytes],
|
||||
uint8_t *session_index);
|
||||
bool session_manager_find(const session_manager_t *manager, const uint8_t token[kSessionTokenBytes],
|
||||
uint8_t *session_index);
|
||||
bool session_manager_disconnect(session_manager_t *manager, uint8_t session_index);
|
||||
session_result_t session_manager_leave(session_manager_t *manager, uint8_t session_index, phase_t phase);
|
||||
bool session_manager_player_present(const session_manager_t *manager, uint8_t player_index);
|
||||
|
||||
Reference in New Issue
Block a user