Split pack on modules

This commit is contained in:
cpq
2026-04-23 14:39:29 +01:00
parent d73452cc8a
commit 4a5d2f04b3
9 changed files with 188 additions and 45 deletions
+2 -2
View File
@@ -2,7 +2,7 @@
PROG ?= example
MONGOOSE_DIR ?= ../..
SOURCES = main.c mongoose_app.c dashboard.html.c $(MONGOOSE_DIR)/mongoose.c
SOURCES = main.c mongoose_dashboard.c dashboard.html.c $(MONGOOSE_DIR)/mongoose.c
CFLAGS ?= -W -Wall -Wextra -Werror -Wundef -Wshadow -g3 -O0
PFLAGS = -I$(MONGOOSE_DIR) -DMG_DATA_SIZE=64 -DMG_TLS=MG_TLS_BUILTIN
AFLAGS ?= -fsanitize=signed-integer-overflow,address,undefined,alignment
@@ -25,7 +25,7 @@ dashboard.html.c: dashboard.html
# For development: rebuild and restart if any of the sources change
watch:
watchexec -r -w main.c -w mongoose_app.c -w $(MONGOOSE_DIR)/mongoose.h -w web_root -e c,h,html,css,js -- make
watchexec -r -w main.c -w mongoose_dashboard.c -w $(MONGOOSE_DIR)/mongoose.h -w web_root -e c,h,html,css,js -- make
clean:
rm -rf $(PROG) *.exe *.obj *.dSYM mongoose dashboard.*
+9 -4
View File
@@ -1,13 +1,18 @@
// SPDX-FileCopyrightText: 2026 Cesanta Software Limited
// SPDX-License-Identifier: GPL-2.0-only or commercial
extern void mongoose_init(void);
extern void mongoose_poll(void);
#include "mongoose.h"
int main(void) {
mongoose_init();
struct mg_mgr mgr;
mg_mgr_init(&mgr);
mg_dash_init(&mgr);
for (;;) {
mongoose_poll();
mg_mgr_poll(&mgr, 10);
mg_dash_poll(&mgr);
}
return 0;
}
@@ -114,22 +114,16 @@ static struct mg_field_set field_sets[] = {
{"chart1", fields_chart1, sync_chart1, 0, 0},
{0, 0, 0, 0, 0},
};
static struct mg_mgr s_mgr;
static struct mg_dash s_dashboard = {field_sets};
void mongoose_init(void) {
mg_mgr_init(&s_mgr);
mg_http_listen(&s_mgr, HTTP_ADDR, mg_dash_ev_handler, &s_dashboard);
void mg_dash_init(struct mg_mgr *mgr) {
mg_http_listen(mgr, HTTP_ADDR, mg_dash_ev_handler, &s_dashboard);
}
void mongoose_poll(void) {
mg_mgr_poll(&s_mgr, 1);
{
// Send metrics change periodically
static uint64_t timer = 0;
if (mg_timer_expired(&timer, 300, mg_now())) {
mg_dash_send_change(&s_mgr, &s_dashboard, "metrics");
}
void mg_dash_poll(struct mg_mgr *mgr) {
// Send metrics change periodically
static uint64_t timer = 0;
if (mg_timer_expired(&timer, 30000, mg_now())) {
mg_dash_send_change(mgr, &s_dashboard, "metrics");
}
}