Abort start in case configuration has errors

feature/AudioLoginLogoff
Geoffrey Merck 6 years ago
parent 784b0f1f7c
commit a1cb902da0

@ -42,7 +42,7 @@ int main(int argc, char *argv[])
if ('-' == argv[1][0]) {
printf("\nSmart Group Server Version %s (GitID #%.7s) Copyright (C) %s\n", VERSION.c_str(), gitversion, VENDOR_NAME.c_str());
printf("Smart Group Server comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("Smart Group Server XL comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
return 0;
}
@ -83,10 +83,15 @@ void CSGSXLApp::run()
bool CSGSXLApp::createThread()
{
printf("\nSmart Group Server Version %s (GitID #%.7s) Copyright (C) %s\n", VERSION.c_str(), gitversion, VENDOR_NAME.c_str());
printf("Smart Group Server comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("Smart Group Server XL comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
CSGSXLConfig config(m_configFile);
if(config.hasErrors()) {
printf("Configuration has one or more errors. Aborting.\n");
return false;
}
m_thread = new CSGSXLThread(config.getLinkCount("XRF"), config.getLinkCount("DCS"));
std::string CallSign, address;

@ -27,8 +27,10 @@
CSGSXLConfig::CSGSXLConfig(const std::string &pathname)
{
m_hasErrors = false;
if (pathname.size() < 1) {
printf("Configuration filename too short!\n");
m_hasErrors = true;
return;
}
@ -38,17 +40,21 @@ CSGSXLConfig::CSGSXLConfig(const std::string &pathname)
}
catch(const FileIOException &fioex) {
printf("Can't read %s\n", pathname.c_str());
m_hasErrors = true;
return;
}
catch(const ParseException &pex) {
printf("Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError());
m_hasErrors = true;
return;
}
if (! get_value(cfg, "gateway.callsign", m_callsign, 3, 8, ""))
return;
if (0 == m_callsign.size())
if (! get_value(cfg, "gateway.callsign", m_callsign, 3, 8, "")
|| 0 == m_callsign.size()) {
m_hasErrors = true;
printf("No Gateway callsign specified");
return;
}
CUtils::ToUpper(m_callsign);
get_value(cfg, "gateway.address", m_address, 0, 20, "");
printf("GATEWAY: callsign='%s' address='%s'\n", m_callsign.c_str(), m_address.c_str());
@ -220,9 +226,9 @@ CSGSXLConfig::CSGSXLConfig(const std::string &pathname)
get_value(cfg, "audio.directory", m_audioDirectory, 0, 2000, "");
m_audioDirectory = std::string(DATA_DIR) + "/" + m_audioDirectory;
if(m_audioEnabled) {
printf("Audio enabled, auudio directory : %s", m_audioDirectory.c_str());
printf("Audio enabled, auudio directory : %s\n", m_audioDirectory.c_str());
} else {
printf("Audio disabled");
printf("Audio disabled\n");
}
}
@ -258,6 +264,11 @@ unsigned int CSGSXLConfig::getLinkCount(const char *type)
return count;
}
bool CSGSXLConfig::hasErrors()
{
return m_hasErrors;
}
bool CSGSXLConfig::get_value(const Config &cfg, const std::string &path, int &value, int min, int max, int default_value)
{
if (cfg.lookupValue(path, value)) {

@ -62,6 +62,8 @@ public:
unsigned int getLinkCount(const char *type);
unsigned int getIrcDDBCount();
bool hasErrors();
private:
bool get_value(const Config &cfg, const std::string &path, int &value, int min, int max, int default_value);
bool get_value(const Config &cfg, const std::string &path, bool &value, bool default_value);
@ -79,4 +81,6 @@ private:
bool m_audioEnabled;
std::string m_audioDirectory;
bool m_hasErrors;
};

Loading…
Cancel
Save

Powered by TurnKey Linux.