#include #include #include "config.h" #include "discovery.h" #include "transport.h" #include "error.h" /* * Example schema covering node identity, discovery, and transport. * Each module would normally provide its own schema table; they are * combined here for the CLI demo. */ static const struct Config_Flag_Def function_flag_defs[] = { { "source", DISCOVERY_FLAG_SOURCE }, { "relay", DISCOVERY_FLAG_RELAY }, { "sink", DISCOVERY_FLAG_SINK }, { "controller", DISCOVERY_FLAG_CONTROLLER }, { NULL, 0 } }; static const struct Config_Def schema[] = { /* section key type default */ { "node", "name", CONFIG_STRING, "unnamed:0", NULL }, { "node", "site_id", CONFIG_UINT16, "0", NULL }, { "node", "tcp_port", CONFIG_UINT16, "8000", NULL }, { "node", "function", CONFIG_FLAGS, "source", function_flag_defs }, { "discovery", "interval_ms", CONFIG_UINT32, "5000", NULL }, { "discovery", "timeout_intervals", CONFIG_UINT32, "3", NULL }, { "discovery", "connect_mask", CONFIG_FLAGS, "", function_flag_defs }, { "transport", "max_connections", CONFIG_UINT32, "16", NULL }, { "transport", "max_payload", CONFIG_UINT32, "16777216", NULL }, { NULL } }; static void usage(void) { fprintf(stderr, "usage: config_cli \n" " config_cli --defaults\n" "\n" " load config file and print effective values\n" " --defaults print schema defaults without a file\n"); } int main(int argc, char **argv) { if (argc < 2) { usage(); return 1; } struct Config *cfg; struct App_Error err; if (argv[1][0] == '-') { err = config_defaults(&cfg, schema); } else { err = config_load(&cfg, argv[1], schema); } if (!APP_IS_OK(err)) { fprintf(stderr, "config_load: errno %d\n", err.detail.syscall.err_no); return 1; } config_dump(cfg); config_free(cfg); return 0; }