mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-01 05:52:32 +07:00
Split pack on modules
This commit is contained in:
@@ -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.*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+7
-13
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user