File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,10 @@ void mgos_config_reset(int level);
86
86
*/
87
87
typedef bool (* mgos_config_validator_fn )(const struct mgos_config * cfg ,
88
88
char * * msg );
89
- void mgos_register_config_validator (mgos_config_validator_fn fn );
89
+ void mgos_sys_config_register_validator (mgos_config_validator_fn fn );
90
+
91
+ /* Run validators on the specified config. */
92
+ bool mgos_config_validate (const struct mgos_config * cfg , char * * msg );
90
93
91
94
void device_get_mac_address (uint8_t mac [6 ]);
92
95
Original file line number Diff line number Diff line change @@ -109,17 +109,21 @@ bool load_config_defaults(struct mgos_config *cfg) {
109
109
return true;
110
110
}
111
111
112
+ bool mgos_config_validate (const struct mgos_config * cfg , char * * msg ) {
113
+ * msg = NULL ;
114
+ for (int i = 0 ; i < s_num_validators ; i ++ ) {
115
+ if (!s_validators [i ](cfg , msg )) return false;
116
+ }
117
+ return true;
118
+ }
119
+
112
120
bool save_cfg (const struct mgos_config * cfg , char * * msg ) {
113
121
bool result = false;
114
122
struct mgos_config * defaults = calloc (1 , sizeof (* defaults ));
115
123
char * ptr = NULL ;
116
124
if (defaults == NULL ) goto clean ;
117
125
if (msg == NULL ) msg = & ptr ;
118
- * msg = NULL ;
119
- int i ;
120
- for (i = 0 ; i < s_num_validators ; i ++ ) {
121
- if (!s_validators [i ](cfg , msg )) goto clean ;
122
- }
126
+ if (!mgos_config_validate (cfg , msg )) goto clean ;
123
127
if (!load_config_defaults (defaults )) {
124
128
* msg = strdup ("failed to load defaults" );
125
129
goto clean ;
@@ -299,7 +303,7 @@ enum mgos_init_result mgos_sys_config_init(void) {
299
303
return MGOS_INIT_OK ;
300
304
}
301
305
302
- void mgos_register_config_validator (mgos_config_validator_fn fn ) {
306
+ void mgos_sys_config_register_validator (mgos_config_validator_fn fn ) {
303
307
s_validators = (mgos_config_validator_fn * ) realloc (
304
308
s_validators , (s_num_validators + 1 ) * sizeof (* s_validators ));
305
309
if (s_validators == NULL ) return ;
You can’t perform that action at this time.
0 commit comments