mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-14 09:48:01 +08:00
keep embedded-friendly config API
This commit is contained in:
parent
5d0d01c2c1
commit
7876d464f2
@ -5,11 +5,9 @@
|
||||
|
||||
const char *s_listening_url = "http://0.0.0.0:80";
|
||||
|
||||
#if 0
|
||||
char *config_read(void) {
|
||||
return mg_file_read(&mg_fs_posix, FS_ROOT "/config.json", NULL);
|
||||
struct mg_str config_read(void) {
|
||||
return mg_file_read(&mg_fs_posix, FS_ROOT "/config.json");
|
||||
}
|
||||
#endif
|
||||
|
||||
void config_write(struct mg_str config) {
|
||||
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);
|
||||
int uart_read(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);
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
struct mg_str config_read(void) {
|
||||
return mg_file_read(&mg_fs_posix, "config.json");
|
||||
}
|
||||
|
||||
void config_write(struct mg_str config) {
|
||||
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
|
||||
void uart_bridge_fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
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);
|
||||
free((char *) config.ptr);
|
||||
s_state.tcp.url = strdup(DEFAULT_TCP);
|
||||
|
Loading…
x
Reference in New Issue
Block a user