mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-23 20:11:49 +00:00
keep embedded-friendly config API
This commit is contained in:
1 parent
5d0d01c2c1
commit
7876d464f2
2 files changed
+8
-5
No files matched your search
@@ -5,11 +5,9 @@
|
|||||||
|
|
||||||
const char *s_listening_url = "http://0.0.0.0:80";
|
const char *s_listening_url = "http://0.0.0.0:80";
|
||||||
|
|
||||||
#if 0
|
struct mg_str config_read(void) {
|
||||||
char *config_read(void) {
|
return mg_file_read(&mg_fs_posix, FS_ROOT "/config.json");
|
||||||
return mg_file_read(&mg_fs_posix, FS_ROOT "/config.json", NULL);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void config_write(struct mg_str config) {
|
void config_write(struct mg_str config) {
|
||||||
mg_file_write(&mg_fs_posix, FS_ROOT "/config.json", config.ptr, config.len);
|
mg_file_write(&mg_fs_posix, FS_ROOT "/config.json", config.ptr, config.len);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ struct state {
|
|||||||
void uart_init(int tx, int rx, int baud);
|
void uart_init(int tx, int rx, int baud);
|
||||||
int uart_read(void *buf, size_t len);
|
int uart_read(void *buf, size_t len);
|
||||||
void uart_write(const void *buf, size_t len);
|
void uart_write(const void *buf, size_t len);
|
||||||
|
struct mg_str config_read(void);
|
||||||
void config_write(struct mg_str config);
|
void config_write(struct mg_str config);
|
||||||
|
|
||||||
// Let users define their own UART API. If they don't, use a dummy one
|
// Let users define their own UART API. If they don't, use a dummy one
|
||||||
@@ -53,6 +54,10 @@ int uart_read(void *buf, size_t len) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct mg_str config_read(void) {
|
||||||
|
return mg_file_read(&mg_fs_posix, "config.json");
|
||||||
|
}
|
||||||
|
|
||||||
void config_write(struct mg_str config) {
|
void config_write(struct mg_str config) {
|
||||||
mg_file_write(&mg_fs_posix, "config.json", config.ptr, config.len);
|
mg_file_write(&mg_fs_posix, "config.json", config.ptr, config.len);
|
||||||
}
|
}
|
||||||
@@ -182,7 +187,7 @@ static void config_apply(struct mg_str s) {
|
|||||||
// HTTP request handler function
|
// HTTP request handler function
|
||||||
void uart_bridge_fn(struct mg_connection *c, int ev, void *ev_data) {
|
void uart_bridge_fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||||
if (ev == MG_EV_OPEN && c->is_listening) {
|
if (ev == MG_EV_OPEN && c->is_listening) {
|
||||||
struct mg_str config = mg_file_read(&mg_fs_posix, "config.json");
|
struct mg_str config = config_read();
|
||||||
if (config.ptr != NULL) config_apply(config);
|
if (config.ptr != NULL) config_apply(config);
|
||||||
free((char *) config.ptr);
|
free((char *) config.ptr);
|
||||||
s_state.tcp.url = strdup(DEFAULT_TCP);
|
s_state.tcp.url = strdup(DEFAULT_TCP);
|
||||||
|
|||||||
Reference in new issue
Block a user