1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

super_node: use exceptions for error handling

This commit is contained in:
Steffen Vogel 2019-03-22 13:44:42 +01:00
parent e9c3e61084
commit cd3200e42a
5 changed files with 15 additions and 35 deletions

View file

@ -73,19 +73,17 @@ public:
int init();
/** Wrapper for super_node_parse() */
int parseUri(const std::string &name);
/** Wrapper for parse() */
void parseUri(const std::string &name);
/** Parse super-node configuration.
*
* @param cfg A libjansson object which contains the configuration.
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int parseJson(json_t *cfg);
void parseJson(json_t *cfg);
/** Check validity of super node configuration. */
int check();
void check();
/** Initialize after parsing the configuration file. */
void prepare();

View file

@ -81,7 +81,7 @@ SuperNode::SuperNode() :
logger = logging.get("super_node");
}
int SuperNode::parseUri(const std::string &u)
void SuperNode::parseUri(const std::string &u)
{
json_error_t err;
@ -160,12 +160,10 @@ int SuperNode::parseUri(const std::string &u)
uri = u;
return parseJson(json);
return 0;
parseJson(json);
}
int SuperNode::parseJson(json_t *j)
void SuperNode::parseJson(json_t *j)
{
int ret;
const char *nme = nullptr;
@ -290,11 +288,9 @@ parse: path *p = (path *) alloc(sizeof(path));
json = j;
state = STATE_PARSED;
return 0;
}
int SuperNode::check()
void SuperNode::check()
{
int ret;
@ -317,8 +313,6 @@ int SuperNode::check()
}
state = STATE_CHECKED;
return 0;
}
void SuperNode::startNodeTypes()

View file

@ -171,18 +171,12 @@ int main(int argc, char *argv[])
if (ret)
throw RuntimeError("Failed to initialize signal subsystem");
if (uri) {
ret = sn.parseUri(uri);
if (ret)
throw RuntimeError("Failed to parse command line arguments");
}
if (uri)
sn.parseUri(uri);
else
logger->warn("No configuration file specified. Starting unconfigured. Use the API to configure this instance.");
ret = sn.check();
if (ret)
throw RuntimeError("Failed to verify configuration");
sn.check();
sn.prepare();
sn.start();
sn.run();

View file

@ -349,11 +349,8 @@ check: if (optarg == endptr)
if (ret)
throw RuntimeError("Failed to initialize signals");
if (uri) {
ret = sn.parseUri(uri);
if (ret)
throw RuntimeError("Failed to parse configuration");
}
if (uri)
sn.parseUri(uri);
else
logger->warn("No configuration file specified. Starting unconfigured. Use the API to configure this instance.");

View file

@ -151,11 +151,8 @@ check: if (optarg == endptr)
if (ret)
throw RuntimeError("Failed to initialize signals subsystem");
if (uri) {
ret = sn.parseUri(uri);
if (ret)
throw RuntimeError("Failed to parse configuration");
}
if (uri)
sn.parseUri(uri);
else
logger->warn("No configuration file specified. Starting unconfigured. Use the API to configure this instance.");