@@ -231,7 +231,36 @@ static bool parseModuleJsonObject(const char* type, yyjson_val* module)
231231 }
232232}
233233
234- static const char * printJsonConfig (void )
234+ static void prepareModuleJsonObject (const char * type , yyjson_val * module )
235+ {
236+ FFconfig * cfg = & instance .config ;
237+ switch (type [0 ])
238+ {
239+ case 'b' : case 'B' : {
240+ if (ffStrEqualsIgnCase (type , FF_CPUUSAGE_MODULE_NAME ))
241+ ffPrepareCPUUsage ();
242+ break ;
243+ }
244+ case 'p' : case 'P' : {
245+ if (ffStrEqualsIgnCase (type , FF_PUBLICIP_MODULE_NAME ))
246+ {
247+ if (module ) ffParsePublicIpJsonObject (& cfg -> publicIP , module );
248+ ffPreparePublicIp (& cfg -> publicIP );
249+ }
250+ break ;
251+ }
252+ case 'w' : case 'W' : {
253+ if (ffStrEqualsIgnCase (type , FF_WEATHER_MODULE_NAME ))
254+ {
255+ if (module ) ffParseWeatherJsonObject (& cfg -> weather , module );
256+ ffPrepareWeather (& cfg -> weather );
257+ }
258+ break ;
259+ }
260+ }
261+ }
262+
263+ static const char * printJsonConfig (bool prepare )
235264{
236265 yyjson_val * const root = yyjson_doc_get_root (instance .state .configDoc );
237266 assert (root );
@@ -248,7 +277,7 @@ static const char* printJsonConfig(void)
248277 yyjson_arr_foreach (modules , idx , max , item )
249278 {
250279 uint64_t ms = 0 ;
251- if (__builtin_expect ( instance .config .stat , false) )
280+ if (! prepare && instance .config .stat )
252281 ms = ffTimeGetTick ();
253282
254283 yyjson_val * module = item ;
@@ -265,10 +294,12 @@ static const char* printJsonConfig(void)
265294 else
266295 return "modules must be an array of strings or objects" ;
267296
268- if (!parseModuleJsonObject (type , module ))
297+ if (prepare )
298+ prepareModuleJsonObject (type , module );
299+ else if (!parseModuleJsonObject (type , module ))
269300 return "Unknown module type" ;
270301
271- if (__builtin_expect ( instance .config .stat , false) )
302+ if (! prepare && instance .config .stat )
272303 {
273304 char str [32 ];
274305 int len = snprintf (str , sizeof str , "%" PRIu64 "ms" , ffTimeGetTick () - ms );
@@ -548,9 +579,9 @@ const char* ffParseLibraryJsonConfig(void)
548579 return NULL ;
549580}
550581
551- void ffPrintJsonConfig (void )
582+ void ffPrintJsonConfig (bool prepare )
552583{
553- const char * error = printJsonConfig ();
584+ const char * error = printJsonConfig (prepare );
554585 if (error )
555586 ffPrintErrorString ("JsonConfig" , 0 , NULL , FF_PRINT_TYPE_NO_CUSTOM_KEY , "%s" , error );
556587}
0 commit comments