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

180 lines
5.1 KiB
C
Raw Permalink Normal View History

/** Message paths
*
* @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/>.
*********************************************************************************/
2015-09-19 18:48:00 +02:00
/** A path connects one input node to multiple output nodes (1-to-n).
*
* @addtogroup path Path
* @{
*/
2017-02-16 09:04:12 -03:00
#pragma once
#include <pthread.h>
#include <jansson.h>
#include <villas/list.h>
#include <villas/queue.h>
#include <villas/pool.h>
#include <villas/bitset.h>
#include <villas/common.h>
#include <villas/hook.h>
#include <villas/mapping.h>
#include <villas/task.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Forward declarations */
struct stats;
struct node;
struct super_node;
2017-08-28 14:38:30 +02:00
struct path_source {
2016-11-07 22:17:45 -05:00
struct node *node;
2017-09-02 14:20:38 +02:00
2017-10-18 09:31:31 +02:00
bool masked;
2016-11-07 22:17:45 -05:00
struct pool pool;
2018-06-29 08:37:14 +02:00
struct list mappings; /**< List of mappings (struct mapping_entry). */
2016-11-07 22:17:45 -05:00
};
2017-08-28 14:38:30 +02:00
struct path_destination {
2016-11-07 22:17:45 -05:00
struct node *node;
2017-08-30 23:53:35 +02:00
struct queue queue;
2016-11-07 22:17:45 -05:00
};
2017-10-16 23:07:42 +02:00
/** The register mode determines under which condition the path is triggered. */
enum path_mode {
2018-06-29 08:37:14 +02:00
PATH_MODE_ANY, /**< The path is triggered whenever one of the sources receives samples. */
PATH_MODE_ALL /**< The path is triggered only after all sources have received at least 1 sample. */
2017-10-16 23:07:42 +02:00
};
2016-11-07 22:17:45 -05:00
/** The datastructure for a path. */
2017-08-28 14:38:30 +02:00
struct path {
2018-06-29 08:37:14 +02:00
enum state state; /**< Path state. */
2017-10-16 23:07:42 +02:00
2018-06-29 08:37:14 +02:00
enum path_mode mode; /**< Determines when this path is triggered. */
2017-09-02 14:20:38 +02:00
2017-08-30 23:53:35 +02:00
struct {
int nfds;
struct pollfd *pfds;
} reader;
2017-09-02 14:20:38 +02:00
2017-08-30 23:53:35 +02:00
struct pool pool;
struct sample *last_sample;
2017-10-16 23:07:42 +02:00
int last_sequence;
2018-06-29 08:37:14 +02:00
struct list sources; /**< List of all incoming nodes (struct path_source). */
struct list destinations; /**< List of all outgoing nodes (struct path_destination). */
struct list hooks; /**< List of processing hooks (struct hook). */
2017-10-16 23:07:42 +02:00
struct task timeout;
2018-06-29 08:37:14 +02:00
double rate; /**< A timeout for */
int enabled; /**< Is this path enabled. */
int poll; /**< Weather or not to use poll(2). */
int reverse; /**< This path as a matching reverse path. */
int builtin; /**< This path should use built-in hooks by default. */
int queuelen; /**< The queue length for each path_destination::queue */
int samplelen; /**< Will be calculated based on path::sources.mappings */
2018-06-29 08:37:14 +02:00
char *_name; /**< Singleton: A string which is used to print this path to screen. */
2018-06-29 08:37:14 +02:00
struct bitset mask; /**< A mask of path_sources which are enabled for poll(). */
struct bitset received; /**< A mask of path_sources for which we already received samples. */
2017-10-16 23:07:42 +02:00
2018-06-29 08:37:14 +02:00
pthread_t tid; /**< The thread id for this path. */
json_t *cfg; /**< A JSON object containing the configuration of the path. */
};
2016-10-20 21:16:01 -04:00
/** Initialize internal data structures. */
int path_init(struct path *p);
int path_init2(struct path *p);
/** Check if path configuration is proper. */
int path_check(struct path *p);
/** Start a path.
*
* Start a new pthread for receiving/sending messages over this path.
*
2015-03-21 15:31:42 +01:00
* @param p A pointer to the path structure.
2014-12-05 12:26:47 +01:00
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int path_start(struct path *p);
/** Stop a path.
*
2015-03-21 15:31:42 +01:00
* @param p A pointer to the path structure.
2014-12-05 12:26:47 +01:00
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int path_stop(struct path *p);
/** Destroy path by freeing dynamically allocated memory.
*
* @param i A pointer to the path structure.
*/
int path_destroy(struct path *p);
/** Show some basic statistics for a path.
*
2015-03-21 15:31:42 +01:00
* @param p A pointer to the path structure.
*/
2015-03-21 15:31:42 +01:00
void path_print_stats(struct path *p);
2015-03-21 15:31:42 +01:00
/** Fills the provided buffer with a string representation of the path.
*
* Format: source => [ dest1 dest2 dest3 ]
*
* @param p A pointer to the path structure.
* @return A pointer to a string containing a textual representation of the path.
2015-03-21 15:31:42 +01:00
*/
2018-06-29 08:37:14 +02:00
const char * path_name(struct path *p);
2016-11-07 22:17:45 -05:00
/** Reverse a path */
int path_reverse(struct path *p, struct path *r);
/** Check if node is used as source or destination of a path. */
int path_uses_node(struct path *p, struct node *n);
/** Parse a single path and add it to the global configuration.
*
* @param cfg A JSON object containing the configuration of the path.
* @param p Pointer to the allocated memory for this path
* @param nodes A linked list of all existing nodes
* @retval 0 Success. Everything went well.
* @retval <0 Error. Something went wrong.
*/
int path_parse(struct path *p, json_t *cfg, struct list *nodes);
2018-06-29 08:37:14 +02:00
/** @} */
#ifdef __cplusplus
}
#endif