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/node.h

172 lines
4.9 KiB
C
Raw Permalink Normal View History

/** Nodes
*
* @file
2015-06-02 21:53:04 +02:00
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-03-21 16:59:19 +01:00
*********************************************************************************/
/**
2015-09-19 18:48:00 +02:00
* @addtogroup node Node
* @{
2018-03-21 16:59:19 +01:00
*/
2017-02-16 09:04:12 -03:00
#pragma once
#include <sys/socket.h>
#include <netinet/in.h>
#include <jansson.h>
#include <villas/node_type.h>
#include <villas/sample.h>
#include <villas/list.h>
#include <villas/queue.h>
#include <villas/common.h>
#ifdef __cplusplus
extern "C"{
#endif
struct node_direction {
int enabled;
int builtin; /**< This node should use built-in hooks by default. */
int vectorize; /**< Number of messages to send / recv at once (scatter / gather) */
struct list hooks; /**< List of write hooks (struct hook). */
struct list signals; /**< List of signal meta data such as signal names */
json_t *cfg; /**< A JSON object containing the configuration of the node. */
};
2016-06-08 22:38:21 +02:00
/** The data structure for a node.
*
* Every entity which exchanges messages is represented by a node.
* Nodes can be remote machines and simulators or locally running processes.
*/
struct node
{
char *name; /**< A short identifier of the node, only used for configuration and logging */
2016-06-08 22:38:21 +02:00
char *_name; /**< Singleton: A string used to print to screen. */
char *_name_long; /**< Singleton: A string used to print to screen. */
int affinity; /**< CPU Affinity of this node */
2017-08-28 14:36:16 +02:00
int samplelen; /**< The maximum number of values this node can receive. */
unsigned sequence; /**< This is a counter of received samples, in case the node-type does not generate sequence numbers itself. */
struct stats *stats; /**< Statistic counters. This is a pointer to the statistic hooks private data. */
struct node_direction in, out;
enum state state;
2016-06-08 22:38:21 +02:00
struct node_type *_vt; /**< Virtual functions (C++ OOP style) */
void *_vd; /**< Virtual data (used by struct node::_vt functions) */
json_t *cfg; /**< A JSON object containing the configuration of the node. */
2016-06-08 22:38:21 +02:00
};
int node_init(struct node *n, struct node_type *vt);
/** Parse settings of a node.
*
* @param cfg A JSON object containing the configuration of the node.
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int node_parse(struct node *n, json_t *cfg, const char *name);
/** Parse settings of a node from cmdline. */
int node_parse_cli(struct node *n, int argc, char *argv[]);
2018-03-21 16:59:19 +01:00
/** Parse an array or single node and checks if they exist in the "nodes" section.
*
* Examples:
* out = [ "sintef", "scedu" ]
* out = "acs"
*
* @param cfg A JSON array or string. See examples above.
* @param nodes The nodes will be added to this list.
* @param all This list contains all valid nodes.
*/
int node_parse_list(struct list *list, json_t *cfg, struct list *all);
/** Parse the list of signal definitions. */
int node_parse_signals(struct list *list, json_t *cfg);
/** Validate node configuration. */
int node_check(struct node *n);
/** Start operation of a node.
*
* @see node_type::open
*/
2014-12-05 12:39:52 +01:00
int node_start(struct node *n);
/** Stops operation of a node.
*
* @see node_type::close
*/
int node_stop(struct node *n);
/** Destroy node by freeing dynamically allocated memory.
*
* @see node_type::destroy
*/
int node_destroy(struct node *n);
2015-12-13 00:46:22 +01:00
/** Return a pointer to a string which should be used to print this node.
*
* @see node::_name
* @param n A pointer to the node structure.
*/
const char * node_name_short(struct node *n);
/** Return a pointer to a string which should be used to print this node. */
char * node_name(struct node *n);
2015-12-13 00:46:22 +01:00
/** Return a pointer to a string which should be used to print this node.
*
* @see node::_name_short
* @see node_type::print
* @param n A pointer to the node structure.
*/
char * node_name_long(struct node *n);
2014-12-05 12:39:52 +01:00
/** Reverse local and remote socket address.
*
* @see node_type::reverse
*/
int node_reverse(struct node *n);
int node_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release);
2016-06-08 22:38:21 +02:00
int node_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release);
2016-06-08 22:38:21 +02:00
int node_fd(struct node *n);
struct node_type * node_type(struct node *n);
2018-07-02 14:17:50 +02:00
struct memory_type * node_memory_type(struct node *n, struct memory_type *parent);
#ifdef __cplusplus
}
#endif
/** @} */