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

173 lines
5.4 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>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, 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
2019-04-23 13:03:58 +02:00
#include <bitset>
2020-08-17 17:01:36 +02:00
#include <uuid/uuid.h>
#include <pthread.h>
#include <jansson.h>
#include <villas/list.h>
#include <villas/queue.h>
#include <villas/pool.h>
2020-03-04 12:41:55 +01:00
#include <villas/common.hpp>
#include <villas/mapping.h>
2020-03-04 13:06:28 +01:00
#include <villas/task.hpp>
2019-04-23 13:03:58 +02:00
#include <villas/log.hpp>
/* Forward declarations */
2020-08-25 21:00:52 +02:00
struct vnode;
2017-10-16 23:07:42 +02:00
/** The register mode determines under which condition the path is triggered. */
2019-06-23 16:13:23 +02:00
enum class PathMode {
ANY, /**< The path is triggered whenever one of the sources receives samples. */
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. */
2020-06-08 02:25:07 +02:00
struct vpath {
2019-06-23 16:13:23 +02:00
enum State state; /**< Path state. */
2017-10-16 23:07:42 +02:00
2019-06-23 16:13:23 +02:00
enum PathMode mode; /**< Determines when this path is triggered. */
2017-09-02 14:20:38 +02:00
2020-08-17 17:01:36 +02:00
uuid_t uuid;
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;
2020-06-08 02:25:07 +02:00
struct vlist sources; /**< List of all incoming nodes (struct vpath_source). */
struct vlist destinations; /**< List of all outgoing nodes (struct vpath_destination). */
2019-06-11 18:34:23 +02:00
struct vlist mappings; /**< List of all input mappings (struct mapping_entry). */
2019-01-07 10:28:55 +01:00
struct vlist hooks; /**< List of processing hooks (struct hook). */
struct vlist signals; /**< List of signals which this path creates (struct signal). */
2020-03-04 13:06:28 +01:00
struct Task timeout;
2017-10-16 23:07:42 +02:00
2018-06-29 08:37:14 +02:00
double rate; /**< A timeout for */
int enabled; /**< Is this path enabled. */
int affinity; /**< Thread affinity. */
2018-06-29 08:37:14 +02:00
int poll; /**< Weather or not to use poll(2). */
2020-08-17 17:01:36 +02:00
int reverse; /**< This path has a matching reverse path. */
2018-06-29 08:37:14 +02:00
int builtin; /**< This path should use built-in hooks by default. */
2020-08-17 17:01:36 +02:00
int original_sequence_no; /**< Use original source sequence number when multiplexing */
unsigned queuelen; /**< The queue length for each path_destination::queue */
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
pthread_t tid; /**< The thread id for this path. */
json_t *cfg; /**< A JSON object containing the configuration of the path. */
2019-04-07 15:44:00 +02:00
2019-04-07 16:16:58 +02:00
villas::Logger logger;
std::list<struct vnode *> mask_list;
std::bitset<MAX_SAMPLE_LENGTH> mask; /**< A mask of path_sources which are enabled for poll(). */
2020-08-17 17:01:36 +02:00
std::bitset<MAX_SAMPLE_LENGTH> received; /**< A mask of path_sources for which we already received samples. */
};
2016-10-20 21:16:01 -04:00
/** Initialize internal data structures. */
int path_init(struct vpath *p) __attribute__ ((warn_unused_result));
int path_prepare(struct vpath *p, struct vlist *nodes);
/** Check if path configuration is proper. */
void path_check(struct vpath *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.
*/
2020-06-08 02:25:07 +02:00
int path_start(struct vpath *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.
*/
2020-06-08 02:25:07 +02:00
int path_stop(struct vpath *p);
/** Destroy path by freeing dynamically allocated memory.
*
* @param i A pointer to the path structure.
*/
int path_destroy(struct vpath *p) __attribute__ ((warn_unused_result));
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
*/
2020-06-08 02:25:07 +02:00
const char * path_name(struct vpath *p);
2020-07-01 17:02:22 +02:00
/** Get a list of signals which is emitted by the path. */
struct vlist * path_output_signals(struct vpath *n);
2020-10-21 20:56:51 +02:00
struct vlist * path_signals(struct vpath *p);
2016-11-07 22:17:45 -05:00
/** Reverse a path */
2020-06-08 02:25:07 +02:00
int path_reverse(struct vpath *p, struct vpath *r);
2016-11-07 22:17:45 -05:00
/** 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 vpath *p, json_t *cfg, struct vlist *nodes, const uuid_t sn_uuid);
void path_parse_mask(struct vpath *p, json_t *json_mask, struct vlist *nodes);
2020-06-08 02:25:07 +02:00
bool path_is_simple(const struct vpath *p);
2020-06-08 02:25:07 +02:00
bool path_is_enabled(const struct vpath *p);
2020-06-08 02:25:07 +02:00
bool path_is_reversed(const struct vpath *p);
2020-08-25 20:24:18 +02:00
json_t * path_to_json(struct vpath *p);
2018-06-29 08:37:14 +02:00
/** @} */