-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathvillas-graph.cpp
More file actions
128 lines (94 loc) · 2.59 KB
/
Copy pathvillas-graph.cpp
File metadata and controls
128 lines (94 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* Create a graph representation of the VILLASnode configuration file.
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#include <iostream>
// clang-format off
#include <graphviz/types.h>
#include <graphviz/gvcommon.h>
// clang-format on
#include <villas/super_node.hpp>
#include <villas/tool.hpp>
#include <villas/utils.hpp>
using namespace villas;
struct GVC_s {
GVCOMMON_t common;
char *config_path;
bool config_found;
char **input_filenames; // gvParseArgs
};
namespace villas {
namespace node {
namespace tools {
class Graph : public Tool {
public:
Graph(int argc, char *argv[])
: Tool(argc, argv, "graph", {SIGUSR1, SIGINT}), gvc(nullptr),
graph(nullptr) {
int ret;
ret = memory::init(DEFAULT_NR_HUGEPAGES);
if (ret)
throw RuntimeError("Failed to initialize memory");
this->argv[0] = (char *)"neato"; // Default layout engine
gvc = gvContext();
}
~Graph() { gvFreeContext(gvc); }
protected:
GVC_t *gvc;
graph_t *graph;
std::string configFilename;
void usage() override {
std::cout << "Usage: villas-graph [OPTIONS]" << std::endl
<< "For OPTIONS see dot(1).";
printCopyright();
}
void parse() override {
gvParseArgs(gvc, argc, argv);
std::list<std::string> filenames;
int i;
for (i = 0; gvc->input_filenames[i]; i++)
filenames.emplace_back(gvc->input_filenames[i]);
if (i == 0)
throw RuntimeError("No configuration file given!");
configFilename = filenames.front();
}
void handler(int signal, siginfo_t *siginfp, void *) override {
#ifndef _WIN32
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: {
}
}
#endif // _WIN32
}
int main() override {
int ret;
villas::node::SuperNode sn;
sn.parse(configFilename);
sn.check();
sn.prepare();
graph = sn.getGraph();
ret = gvLayoutJobs(gvc, graph); // Take layout engine from command line
if (ret)
return ret;
return gvRenderJobs(gvc, graph);
}
};
} // namespace tools
} // namespace node
} // namespace villas
int main(int argc, char *argv[]) {
node::tools::Graph t(argc, argv);
return t.run();
}