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

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

158 lines
3.3 KiB
C++
Raw Permalink Normal View History

/* The super node object holding the state of the application.
*
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
2015-06-02 21:53:04 +02:00
*/
2017-02-16 09:04:12 -03:00
#pragma once
#include <villas/node/config.hpp>
#ifdef WITH_GRAPHVIZ
2020-03-04 13:59:46 +01:00
extern "C" {
#include <graphviz/gvc.h>
2020-03-04 13:59:46 +01:00
}
#endif
#include <fstream>
2018-10-20 14:20:06 +02:00
#include <villas/api.hpp>
#include <villas/common.hpp>
#include <villas/config_class.hpp>
#include <villas/kernel/if.hpp>
#include <villas/log.hpp>
#include <villas/node.hpp>
#include <villas/node_list.hpp>
#include <villas/path_list.hpp>
2020-03-04 13:07:20 +01:00
#include <villas/task.hpp>
#include <villas/web.hpp>
2017-02-18 10:31:42 -05:00
2018-07-03 21:51:48 +02:00
namespace villas {
namespace node {
// Forward declarations
class Node;
2017-02-18 10:31:42 -05:00
// Global configuration
2018-07-03 21:51:48 +02:00
class SuperNode {
protected:
enum State state;
int idleStop;
2019-02-12 15:07:50 +01:00
Logger logger;
2018-10-20 14:20:06 +02:00
NodeList nodes;
PathList paths;
std::list<kernel::Interface *> interfaces;
2017-02-18 10:31:42 -05:00
2018-10-20 14:20:06 +02:00
#ifdef WITH_API
Api api;
2018-10-20 14:20:06 +02:00
#endif
#ifdef WITH_WEB
Web web;
2018-10-20 14:20:06 +02:00
#endif
int priority; // Process priority (lower is better)
int affinity; // Process affinity of the server and all created threads
int hugepages; // Number of hugepages to reserve.
double statsRate; // Rate at which we display the periodic stats.
struct Task task; // Task for periodic stats output
2017-08-05 21:02:09 +02:00
uuid_t uuid; // A globally unique identifier of the instance
2020-10-15 14:47:43 +02:00
struct timespec started; // The time at which the instance has been started.
2020-10-15 14:47:43 +02:00
std::string uri; // URI of configuration
2017-02-18 10:31:42 -05:00
Config config; // The configuration file.
2018-07-03 21:51:48 +02:00
public:
// Inititalize configuration object before parsing the configuration.
SuperNode();
2016-02-04 16:27:14 +01:00
int init();
// Wrapper for parse() which loads the config first.
void parse(const std::string &name);
2017-02-18 10:31:42 -05:00
/* Parse super-node configuration.
2018-07-03 21:51:48 +02:00
*
2021-02-16 14:15:14 +01:00
* @param json A libjansson object which contains the configuration.
2018-07-03 21:51:48 +02:00
*/
void parse(json_t *json);
// Check validity of super node configuration.
void check();
2017-03-06 08:59:28 -04:00
// Initialize after parsing the configuration file.
void prepare();
void start();
void stop();
void run();
void preparePaths();
void prepareNodes();
void prepareNodeTypes();
2019-02-24 11:13:28 +01:00
void startPaths();
void startNodes();
void startInterfaces();
void stopPaths();
void stopNodes();
void stopNodeTypes();
void stopInterfaces();
#ifdef WITH_GRAPHVIZ
graph_t *getGraph();
#endif
// Run periodic hooks of this super node.
int periodic();
void setState(enum State st) { state = st; }
Node *getNode(const std::string &name) { return nodes.lookup(name); }
NodeList &getNodes() { return nodes; }
PathList &getPaths() { return paths; }
std::list<kernel::Interface *> &getInterfaces() { return interfaces; }
enum State getState() const { return state; }
const uuid_t &getUuid() const { return uuid; }
struct timespec getStartTime() const { return started; }
2020-10-15 14:47:43 +02:00
2018-10-20 14:20:06 +02:00
#ifdef WITH_API
Api *getApi() { return &api; }
2018-10-20 14:20:06 +02:00
#endif
#ifdef WITH_WEB
Web *getWeb() { return &web; }
2018-10-20 14:20:06 +02:00
#endif
json_t *getConfig() { return config.root; }
2018-10-20 14:20:06 +02:00
std::filesystem::path &getConfigPath() { return config.getConfigPath(); }
std::string getConfigUri() const { return uri; }
2018-10-20 14:20:06 +02:00
int getAffinity() const { return affinity; }
Logger getLogger() { return logger; }
2021-02-16 14:15:14 +01:00
// Destroy configuration object.
~SuperNode();
2018-07-03 21:51:48 +02:00
};
} // namespace node
} // namespace villas