mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added new signal metadata class
This commit is contained in:
parent
46cbb689fc
commit
5d7999b3f5
5 changed files with 151 additions and 18 deletions
|
@ -19,10 +19,12 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*********************************************************************************/
|
||||
|
||||
/**
|
||||
* @addtogroup node Node
|
||||
* @{
|
||||
*********************************************************************************/
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -59,6 +61,7 @@ struct node
|
|||
struct stats *stats; /**< Statistic counters. This is a pointer to the statistic hooks private data. */
|
||||
|
||||
struct list hooks; /**< List of write hooks (struct hook). */
|
||||
struct list signals; /**< List of signal meta data such as signal names */
|
||||
|
||||
enum state state;
|
||||
|
||||
|
@ -83,6 +86,21 @@ 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[]);
|
||||
|
||||
/** 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);
|
||||
|
||||
|
@ -134,16 +152,4 @@ int node_write(struct node *n, struct sample *smps[], unsigned cnt);
|
|||
|
||||
int node_fd(struct node *n);
|
||||
|
||||
/** 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);
|
||||
|
||||
/** @} */
|
||||
|
|
43
include/villas/signal.h
Normal file
43
include/villas/signal.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/** Signal meta data.
|
||||
*
|
||||
* @file
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2018, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
/* Forward declarations */
|
||||
struct list;
|
||||
|
||||
struct signal {
|
||||
char *name; /**< The name of the signal. */
|
||||
enum {
|
||||
SIGNAL_FORMAT_INTEGER,
|
||||
SIGNAL_FORMAT_REAL
|
||||
} format;
|
||||
};
|
||||
|
||||
int signal_destroy(struct signal *s);
|
||||
|
||||
int signal_parse(struct signal *s, json_t *cfg);
|
||||
|
||||
int signal_parse_list(struct list *list, json_t *cfg);
|
|
@ -30,7 +30,7 @@ LIB_SRCS += $(addprefix lib/kernel/, kernel.c rt.c) \
|
|||
utils.c super_node.c hist.c timing.c pool.c list.c queue.c \
|
||||
queue_signalled.c memory.c advio.c plugin.c node_type.c stats.c \
|
||||
mapping.c shmem.c config_helper.c crypt.c compat.c \
|
||||
log_helper.c task.c buffer.c table.c bitset.c \
|
||||
log_helper.c task.c buffer.c table.c bitset.c signal.c \
|
||||
)
|
||||
|
||||
LIB_LDFLAGS += -shared
|
||||
|
|
16
lib/node.c
16
lib/node.c
|
@ -26,11 +26,11 @@
|
|||
#include <villas/sample.h>
|
||||
#include <villas/node.h>
|
||||
#include <villas/utils.h>
|
||||
#include <villas/config.h>
|
||||
#include <villas/plugin.h>
|
||||
#include <villas/config_helper.h>
|
||||
#include <villas/mapping.h>
|
||||
#include <villas/timing.h>
|
||||
#include <villas/signal.h>
|
||||
|
||||
int node_init(struct node *n, struct node_type *vt)
|
||||
{
|
||||
|
@ -104,17 +104,19 @@ int node_parse(struct node *n, json_t *cfg, const char *name)
|
|||
|
||||
json_error_t err;
|
||||
json_t *json_hooks = NULL;
|
||||
json_t *json_signals = NULL;
|
||||
|
||||
const char *type;
|
||||
|
||||
n->name = strdup(name);
|
||||
|
||||
ret = json_unpack_ex(cfg, &err, 0, "{ s: s, s?: i, s?: i, s?: o, s?: b }",
|
||||
ret = json_unpack_ex(cfg, &err, 0, "{ s: s, s?: i, s?: i, s?: o, s?: b, s?: o }",
|
||||
"type", &type,
|
||||
"vectorize", &n->vectorize,
|
||||
"samplelen", &n->samplelen,
|
||||
"hooks", &json_hooks,
|
||||
"no_builtin", &n->no_builtin
|
||||
"no_builtin", &n->no_builtin,
|
||||
"signals", &json_signals
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse node '%s'", node_name(n));
|
||||
|
@ -130,6 +132,12 @@ int node_parse(struct node *n, json_t *cfg, const char *name)
|
|||
}
|
||||
#endif /* WITH_HOOKS */
|
||||
|
||||
if (json_signals) {
|
||||
ret = signal_parse_list(&n->signals, json_signals);
|
||||
if (ret)
|
||||
error("Failed to parse signal definition of node '%s'", node_name(n));
|
||||
}
|
||||
|
||||
ret = n->_vt->parse ? n->_vt->parse(n, cfg) : 0;
|
||||
if (ret)
|
||||
error("Failed to parse node '%s'", node_name(n));
|
||||
|
@ -253,6 +261,8 @@ int node_destroy(struct node *n)
|
|||
|
||||
list_remove(&n->_vt->instances, n);
|
||||
|
||||
list_destroy(&n->signals, (dtor_cb_t) signal_destroy, true);
|
||||
|
||||
if (n->_vd)
|
||||
free(n->_vd);
|
||||
|
||||
|
|
74
lib/signal.c
Normal file
74
lib/signal.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/** Signal meta data.
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "villas/signal.h"
|
||||
#include "villas/list.h"
|
||||
#include "villas/utils.h"
|
||||
|
||||
int signal_destroy(struct signal *s)
|
||||
{
|
||||
if (s->name)
|
||||
free(s->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int signal_parse(struct signal *s, json_t *cfg)
|
||||
{
|
||||
int ret;
|
||||
json_error_t err;
|
||||
const char *name;
|
||||
|
||||
ret = json_unpack_ex(cfg, &err, 0, "s: s",
|
||||
"name", &name
|
||||
);
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
s->name = strdup(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int signal_parse_list(struct list *list, json_t *cfg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!json_is_array(cfg))
|
||||
return -1;
|
||||
|
||||
size_t index;
|
||||
json_t *json_signal;
|
||||
json_array_foreach(cfg, index, json_signal) {
|
||||
struct signal *s = alloc(sizeof(struct signal));
|
||||
|
||||
ret = signal_parse(s, json_signal);
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
list_push(list, s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue