2019-04-19 14:51:45 +02:00
|
|
|
/** Common entry point for all villas command line tools.
|
|
|
|
*
|
2022-12-14 17:39:07 +01:00
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:05:42 -04:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2022-05-19 17:40:10 +02:00
|
|
|
* @license Apache License 2.0
|
2019-04-19 14:51:45 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <villas/tool.hpp>
|
|
|
|
|
|
|
|
using namespace villas;
|
|
|
|
|
|
|
|
void Tool::staticHandler(int signal, siginfo_t *sinfo, void *ctx)
|
|
|
|
{
|
|
|
|
if (current_tool)
|
|
|
|
current_tool->handler(signal, sinfo, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tool::printCopyright()
|
|
|
|
{
|
|
|
|
std::cout << PROJECT_NAME " " << CLR_BLU(PROJECT_BUILD_ID)
|
|
|
|
<< " (built on " CLR_MAG(__DATE__) " " CLR_MAG(__TIME__) ")" << std::endl
|
2021-06-21 16:09:11 -04:00
|
|
|
<< " Copyright 2014-2021, Institute for Automation of Complex Power Systems, EONERC" << std::endl
|
2022-12-14 17:39:07 +01:00
|
|
|
<< " Steffen Vogel <post@steffenvogel.de>" << std::endl;
|
2019-04-19 14:51:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Tool::printVersion()
|
|
|
|
{
|
|
|
|
std::cout << PROJECT_BUILD_ID << std::endl;
|
|
|
|
}
|
|
|
|
|
2019-06-30 14:34:01 +02:00
|
|
|
Tool::Tool(int ac, char *av[], const std::string &nme, const std::list<int> &sigs) :
|
2019-04-19 14:51:45 +02:00
|
|
|
argc(ac),
|
|
|
|
argv(av),
|
2019-06-30 14:34:01 +02:00
|
|
|
name(nme),
|
|
|
|
handlerSignals(sigs)
|
2019-04-19 14:51:45 +02:00
|
|
|
{
|
|
|
|
current_tool = this;
|
|
|
|
|
|
|
|
logger = logging.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Tool::run()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
logger->info("This is VILLASnode {} (built on {}, {})",
|
|
|
|
CLR_BLD(CLR_YEL(PROJECT_BUILD_ID)),
|
|
|
|
CLR_BLD(CLR_MAG(__DATE__)), CLR_BLD(CLR_MAG(__TIME__)));
|
|
|
|
|
2021-09-19 19:05:53 +02:00
|
|
|
ret = utils::signalsInit(staticHandler, handlerSignals);
|
2019-04-19 14:51:45 +02:00
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to initialize signal subsystem");
|
|
|
|
|
2022-12-02 17:16:44 +01:00
|
|
|
// Parse command line arguments
|
2019-04-19 14:51:45 +02:00
|
|
|
parse();
|
|
|
|
|
2022-12-02 17:16:44 +01:00
|
|
|
// Run tool
|
2019-04-19 14:51:45 +02:00
|
|
|
ret = main();
|
|
|
|
|
|
|
|
logger->info(CLR_GRN("Goodbye!"));
|
|
|
|
|
|
|
|
return ret;
|
2020-07-27 16:40:48 +02:00
|
|
|
} catch (const std::runtime_error &e) {
|
2019-04-19 14:51:45 +02:00
|
|
|
logger->error("{}", e.what());
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tool *Tool::current_tool = nullptr;
|