ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
partition_monitor_routes.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file partition_monitor_routes.cpp
6 * @brief Partition-map monitor route (GET endpoint serving the JSON).
7 *
8 * Separated from the host-testable core (partition_monitor.cpp) so the classifier
9 * + serializer unit-test without pulling in the server.
10 */
11
13
14#if PC_ENABLE_PARTITION_MONITOR
15
16#include "protocore.h"
18
19// All partition-monitor-routes state, owned by one instance (internal linkage): the server
20// handle. (The route handler is a fixed-signature callback, so it reaches this owner directly.)
21struct PartitionRoutesCtx
22{
23 PC *srv = nullptr;
24};
25static PartitionRoutesCtx s_partr;
26
27static void partition_handler(uint8_t slot_id, HttpReq *req)
28{
29 (void)req;
30 pc_partition_info parts[PC_PARTITION_MAX];
31 uint8_t n = pc_partition_collect(parts, PC_PARTITION_MAX);
32 char buf[PC_PARTITION_JSON_BUF];
33 pc_partition_json(parts, n, buf, sizeof(buf));
34 if (s_partr.srv)
35 {
36 s_partr.srv->send(slot_id, 200, PC_MIME_JSON, buf);
37 }
38}
39
40void pc_partition_monitor_begin(PC &server, const char *path)
41{
42 s_partr.srv = &server;
43 server.on((path && path[0]) ? path : "/partitions", HttpMethod::HTTP_GET, partition_handler);
44}
45
46#endif // PC_ENABLE_PARTITION_MONITOR
Single-port HTTP server with deterministic, zero-allocation execution.
Definition protocore.h:348
void on(const char *path, HttpMethod method, Handler callback)
Register a route handler.
Shared HTTP Content-Type ("MIME") string constants (one source of truth).
Flash partition-map monitor (PC_ENABLE_PARTITION_MONITOR).
Layer 7 (Application) - public HTTP routing API.
HttpMethod
HTTP request methods supported by the router.
Definition protocore.h:77
@ HTTP_GET
Safe, idempotent read.
#define PC_PARTITION_MAX
Maximum partitions the monitor reports (BSS table).
#define PC_PARTITION_JSON_BUF
Stack buffer for the partition-map JSON (bytes).
Fully-parsed HTTP/1.1 request.