2014-06-05 09:35:32 +00:00
|
|
|
/** Message paths
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
2014-06-28 06:40:52 +00:00
|
|
|
* @file
|
2015-06-02 21:53:04 +02:00
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @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-05-05 19:24:16 +00:00
|
|
|
*
|
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-05-05 19:24:16 +00:00
|
|
|
*
|
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/>.
|
2017-03-05 10:06:32 -04:00
|
|
|
*********************************************************************************/
|
|
|
|
|
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-03-05 10:06:32 -04:00
|
|
|
*/
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
#include <pthread.h>
|
2014-06-05 09:35:41 +00:00
|
|
|
#include <libconfig.h>
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2015-03-18 15:53:01 +01:00
|
|
|
#include "list.h"
|
2016-06-08 22:38:21 +02:00
|
|
|
#include "queue.h"
|
2016-01-14 22:59:57 +01:00
|
|
|
#include "pool.h"
|
2017-03-11 23:50:30 -03:00
|
|
|
#include "common.h"
|
2017-03-29 04:25:30 +02:00
|
|
|
#include "hook.h"
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2016-11-20 12:59:37 -05:00
|
|
|
/* Forward declarations */
|
2017-03-29 04:25:30 +02:00
|
|
|
struct stats;
|
|
|
|
struct node;
|
2017-03-12 17:01:24 -03:00
|
|
|
struct super_node;
|
2016-11-20 12:59:37 -05:00
|
|
|
|
2016-11-07 22:17:45 -05:00
|
|
|
struct path_source
|
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
struct pool pool;
|
|
|
|
int samplelen;
|
2017-05-05 19:24:16 +00:00
|
|
|
pthread_t tid;
|
2016-11-07 22:17:45 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct path_destination
|
|
|
|
{
|
|
|
|
struct node *node;
|
|
|
|
struct queue queue;
|
|
|
|
int queuelen;
|
|
|
|
pthread_t tid;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** The datastructure for a path. */
|
2014-06-05 09:34:29 +00:00
|
|
|
struct path
|
|
|
|
{
|
2017-03-11 23:50:30 -03:00
|
|
|
enum state state; /**< Path state. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2016-11-07 22:17:45 -05:00
|
|
|
/* Each path has a single source and multiple destinations */
|
|
|
|
struct path_source *source; /**< Pointer to the incoming node */
|
|
|
|
struct list destinations; /**< List of all outgoing nodes (struct path_destination). */
|
2016-06-08 22:38:21 +02:00
|
|
|
|
2017-03-13 23:51:38 -03:00
|
|
|
struct list hooks; /**< List of function pointers to hooks. */
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2017-03-13 23:51:38 -03:00
|
|
|
int enabled; /**< Is this path enabled. */
|
|
|
|
int reverse; /**< This path as a matching reverse path. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-29 04:25:30 +02:00
|
|
|
int samplelen;
|
|
|
|
int queuelen;
|
2014-06-25 17:50:30 +00:00
|
|
|
|
2017-03-13 23:51:38 -03:00
|
|
|
pthread_t tid; /**< The thread id for this path. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2015-11-29 22:45:46 +01:00
|
|
|
char *_name; /**< Singleton: A string which is used to print this path to screen. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2016-11-20 12:59:37 -05:00
|
|
|
struct stats *stats; /**< Statistic counters. This is a pointer to the statistic hooks private data. */
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-03-12 17:01:24 -03:00
|
|
|
struct super_node *super_node; /**< The super node this path belongs to. */
|
2017-03-13 23:51:38 -03:00
|
|
|
config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path. */
|
2014-06-05 09:34:29 +00:00
|
|
|
};
|
|
|
|
|
2016-10-20 21:16:01 -04:00
|
|
|
/** Initialize internal data structures. */
|
2017-03-12 17:01:24 -03:00
|
|
|
int path_init(struct path *p, struct super_node *sn);
|
|
|
|
|
|
|
|
int path_init2(struct path *p);
|
2017-03-05 10:06:32 -04:00
|
|
|
|
|
|
|
/** Check if path configuration is proper. */
|
|
|
|
int path_check(struct path *p);
|
2015-03-21 15:23:57 +01:00
|
|
|
|
2014-06-05 09:35:32 +00:00
|
|
|
/** Start a path.
|
|
|
|
*
|
|
|
|
* Start a new pthread for receiving/sending messages over this path.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
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.
|
2014-06-05 09:34:29 +00:00
|
|
|
*/
|
|
|
|
int path_start(struct path *p);
|
|
|
|
|
2014-06-05 09:35:32 +00:00
|
|
|
/** Stop a path.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
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.
|
2014-06-05 09:34:29 +00:00
|
|
|
*/
|
|
|
|
int path_stop(struct path *p);
|
|
|
|
|
2017-03-12 17:01:24 -03:00
|
|
|
/** Destroy path by freeing dynamically allocated memory.
|
|
|
|
*
|
|
|
|
* @param i A pointer to the path structure.
|
|
|
|
*/
|
|
|
|
int path_destroy(struct path *p);
|
|
|
|
|
2014-07-14 11:49:44 +00:00
|
|
|
/** Show some basic statistics for a path.
|
2014-07-04 09:47:28 +00:00
|
|
|
*
|
2015-03-21 15:31:42 +01:00
|
|
|
* @param p A pointer to the path structure.
|
2014-07-04 09:47:28 +00:00
|
|
|
*/
|
2015-03-21 15:31:42 +01:00
|
|
|
void path_print_stats(struct path *p);
|
2014-07-04 09:47:28 +00:00
|
|
|
|
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.
|
2015-09-22 12:58:37 +02:00
|
|
|
* @return A pointer to a string containing a textual representation of the path.
|
2015-03-21 15:31:42 +01:00
|
|
|
*/
|
2015-11-29 22:45:46 +01:00
|
|
|
const char * path_name(struct path *p);
|
2015-03-18 15:45:06 +01:00
|
|
|
|
2016-11-07 22:17:45 -05:00
|
|
|
/** Reverse a path */
|
|
|
|
int path_reverse(struct path *p, struct path *r);
|
|
|
|
|
2016-01-14 22:52:08 +01:00
|
|
|
/** Check if node is used as source or destination of a path. */
|
|
|
|
int path_uses_node(struct path *p, struct node *n);
|
|
|
|
|
2016-11-20 12:59:37 -05:00
|
|
|
/** Parse a single path and add it to the global configuration.
|
|
|
|
*
|
|
|
|
* @param cfg A libconfig object pointing to 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.
|
|
|
|
*/
|
2017-03-05 10:06:32 -04:00
|
|
|
int path_parse(struct path *p, config_setting_t *cfg, struct list *nodes);
|
2016-11-20 12:59:37 -05:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
/** @} */
|