2023-09-04 12:21:37 +02:00
|
|
|
/* Create a graph representation of the VILLASnode configuration file.
|
2019-06-30 14:46:55 +02:00
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2019-06-30 14:46:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <graphviz/types.h>
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 14:21:24 +02:00
|
|
|
#include <graphviz/gvcommon.h>
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/super_node.hpp>
|
2019-06-30 14:46:55 +02:00
|
|
|
#include <villas/tool.hpp>
|
|
|
|
#include <villas/utils.hpp>
|
|
|
|
|
|
|
|
using namespace villas;
|
|
|
|
|
|
|
|
struct GVC_s {
|
2023-09-07 11:46:39 +02:00
|
|
|
GVCOMMON_t common;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
char *config_path;
|
|
|
|
bool config_found;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
char **input_filenames; // gvParseArgs
|
2019-06-30 14:46:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
namespace tools {
|
|
|
|
|
|
|
|
class Graph : public Tool {
|
|
|
|
|
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
Graph(int argc, char *argv[])
|
|
|
|
: Tool(argc, argv, "graph", {SIGUSR1, SIGINT}), gvc(nullptr),
|
|
|
|
graph(nullptr) {
|
|
|
|
int ret;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = memory::init(DEFAULT_NR_HUGEPAGES);
|
|
|
|
if (ret)
|
|
|
|
throw RuntimeError("Failed to initialize memory");
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
this->argv[0] = (char *)"neato"; // Default layout engine
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
gvc = gvContext();
|
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
~Graph() { gvFreeContext(gvc); }
|
2019-06-30 14:46:55 +02:00
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
GVC_t *gvc;
|
|
|
|
graph_t *graph;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::string configFilename;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void usage() {
|
|
|
|
std::cout << "Usage: villas-graph [OPTIONS]" << std::endl
|
|
|
|
<< "For OPTIONS see dot(1).";
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
printCopyright();
|
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void parse() {
|
|
|
|
gvParseArgs(gvc, argc, argv);
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::list<std::string> filenames;
|
|
|
|
int i;
|
|
|
|
for (i = 0; gvc->input_filenames[i]; i++)
|
|
|
|
filenames.emplace_back(gvc->input_filenames[i]);
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
if (i == 0)
|
|
|
|
throw RuntimeError("No configuration file given!");
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
configFilename = filenames.front();
|
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
virtual void handler(int signal, siginfo_t *siginfp, void *) {
|
2019-06-30 14:46:55 +02:00
|
|
|
#ifndef _WIN32
|
2023-09-07 11:46:39 +02:00
|
|
|
switch (signal) {
|
|
|
|
case SIGINT:
|
|
|
|
// If interrupted we try to produce a partial rendering before exiting
|
|
|
|
if (graph)
|
|
|
|
gvRenderJobs(gvc, graph);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGUSR1:
|
|
|
|
// Note that we don't call gvFinalize() so that we don't start event-driven
|
|
|
|
// devices like -Tgtk or -Txlib */
|
|
|
|
exit(gvFreeContext(gvc));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
}
|
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
#endif // _WIN32
|
2023-09-07 11:46:39 +02:00
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int main() {
|
|
|
|
int ret;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
villas::node::SuperNode sn;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
sn.parse(configFilename);
|
|
|
|
sn.check();
|
|
|
|
sn.prepare();
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
graph = sn.getGraph();
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
ret = gvLayoutJobs(gvc, graph); // Take layout engine from command line
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
return gvRenderJobs(gvc, graph);
|
|
|
|
}
|
2019-06-30 14:46:55 +02:00
|
|
|
};
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace tools
|
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
node::tools::Graph t(argc, argv);
|
2019-06-30 14:46:55 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
return t.run();
|
2019-06-30 14:46:55 +02:00
|
|
|
}
|