DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
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 DETWS_ENABLE_PARTITION_MONITOR
15
16#include "dwserver.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 DetWebServer *srv = nullptr;
24};
25static PartitionRoutesCtx s_partr;
26
27static void partition_handler(uint8_t slot_id, HttpReq *req)
28{
29 (void)req;
30 DetwsPartitionInfo parts[DETWS_PARTITION_MAX];
31 uint8_t n = detws_partition_collect(parts, DETWS_PARTITION_MAX);
33 detws_partition_json(parts, n, buf, sizeof(buf));
34 if (s_partr.srv)
35 s_partr.srv->send(slot_id, 200, DET_MIME_JSON, buf);
36}
37
38void detws_partition_monitor_begin(DetWebServer &server, const char *path)
39{
40 s_partr.srv = &server;
41 server.on((path && path[0]) ? path : "/partitions", HttpMethod::HTTP_GET, partition_handler);
42}
43
44#endif // DETWS_ENABLE_PARTITION_MONITOR
#define DETWS_PARTITION_MAX
Maximum partitions the monitor reports (BSS table).
#define DETWS_PARTITION_JSON_BUF
Stack buffer for the partition-map JSON (bytes).
Single-port HTTP server with deterministic, zero-allocation execution.
Definition dwserver.h:348
void on(const char *path, HttpMethod method, Handler callback)
Register a route handler.
Definition dwserver.cpp:759
Layer 7 (Application) - public HTTP routing API.
HttpMethod
HTTP request methods supported by the router.
Definition dwserver.h:77
@ HTTP_GET
Safe, idempotent read.
Shared HTTP Content-Type ("MIME") string constants (one source of truth).
Flash partition-map monitor (DETWS_ENABLE_PARTITION_MONITOR).
Fully-parsed HTTP/1.1 request.