1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/common/lib/tool.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.7 KiB
C++
Raw Normal View History

/** Common entry point for all villas command line tools.
*
* @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
*********************************************************************************/
#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
<< " Steffen Vogel <post@steffenvogel.de>" << std::endl;
}
void Tool::printVersion()
{
std::cout << PROJECT_BUILD_ID << std::endl;
}
Tool::Tool(int ac, char *av[], const std::string &nme, const std::list<int> &sigs) :
argc(ac),
argv(av),
name(nme),
handlerSignals(sigs)
{
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);
if (ret)
throw RuntimeError("Failed to initialize signal subsystem");
// Parse command line arguments
parse();
// Run tool
ret = main();
logger->info(CLR_GRN("Goodbye!"));
return ret;
2020-07-27 16:40:48 +02:00
} catch (const std::runtime_error &e) {
logger->error("{}", e.what());
return -1;
}
}
Tool *Tool::current_tool = nullptr;