1 #include "vlp/config.h"
23 bool Config::load(const char * configFilePath)
25 file = fopen(configFilePath, "rt");
28 "Error: Cannot load configuration file: %s!\n",
34 if (!config_read(&cfg, file)) {
36 "%s! In file %s, line %d\n",
37 config_error_text(&cfg),
38 config_error_file(&cfg),
39 config_error_line(&cfg));
46 bool Config::save(const char * configFilePath)
51 int Config::getNodeNumber()
53 config_setting_t *setting = config_lookup(&cfg, "node_number");
57 "%s! In file %s, '%s' was not found.\n",
59 config_error_file(&cfg),
66 return config_setting_get_int(setting);
68 void Config::setNodeNumber(int nodeNumber)
72 std::vector<std::string> Config::getHosts()
74 config_setting_t *setting = config_lookup(&cfg, "host");
75 std::vector<std::string> hosts;
79 "%s! In file %s, '%s' was not found.\n",
81 "configuration",//config_error_file(&cfg),
88 switch(config_setting_type(setting)) {
89 /* TODO: Deprecated. Made for back compatibility. */
90 case CONFIG_TYPE_STRING: {
91 std::string host(config_setting_get_string(setting));
92 hosts.push_back(host);
95 case CONFIG_TYPE_ARRAY: {
96 int size = config_setting_length(setting);
98 for (int i = 0; i < size; i++) {
99 host = config_setting_get_string_elem(setting, i);
100 hosts.push_back(host);
106 "%s! In file %s, bad entry type for %s will not be read.\n",
108 "configuration",//config_error_file(&cfg),
116 ConnectionType Config::getConnectionType()
118 config_setting_t *setting = config_lookup(&cfg, "type");
122 "%s! In file %s, '%s' was not found.\n",
124 "configuration",//config_error_file(&cfg),
131 /* same as strcmp(..) == 0 */
132 if (!strcmp(config_setting_get_string(setting), "explicit")) {
138 void Config::setConnectionType(ConnectionType type)
142 const char * Config::getProgramDir()
144 config_setting_t *setting = config_lookup(&cfg, "progdir");
148 "%s! In file %s, '%s' was not found.\n",
150 "configuration",//config_error_file(&cfg),
155 return config_setting_get_string(setting);
157 void Config::setProgramDir(const char * programDir)