1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

minor bugfixes and improvements

This commit is contained in:
Steffen Vogel 2017-03-13 23:51:38 -03:00
parent 4554a689ee
commit 607be1dd99
10 changed files with 50 additions and 49 deletions

View file

@ -10,11 +10,9 @@
#include <stdio.h>
#include <stdint.h>
#include "config.h"
#include <jansson.h>
#ifdef WITH_JANSSON
#include <jansson.h>
#endif
#include "config.h"
#define HIST_HEIGHT (LOG_WIDTH - 55)
#define HIST_SEQ 17

View file

@ -72,7 +72,8 @@ struct log {
int level;
/** Debug facilities used by the debug() macro. */
int facilities;
long facilities;
};
/** Initialize log object */

View file

@ -54,19 +54,19 @@ struct path
struct path_source *source; /**< Pointer to the incoming node */
struct list destinations; /**< List of all outgoing nodes (struct path_destination). */
struct list hooks; /**< List of function pointers to hooks */
struct list hooks; /**< List of function pointers to hooks. */
int enabled; /**< Is this path enabled */
int reverse; /**< This path as a matching reverse path */
int enabled; /**< Is this path enabled. */
int reverse; /**< This path as a matching reverse path. */
pthread_t tid; /**< The thread id for this path */
pthread_t tid; /**< The thread id for this path. */
char *_name; /**< Singleton: A string which is used to print this path to screen. */
struct stats *stats; /**< Statistic counters. This is a pointer to the statistic hooks private data. */
struct super_node *super_node; /**< The super node this path belongs to. */
config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path */
config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path. */
};
/** Initialize internal data structures. */

View file

@ -62,7 +62,7 @@ struct plugin {
#define plugin_name(vt) plugin(vt)->name
#define plugin_description(vt) plugin(vt)->description
int plugin_init(struct plugin *p, char *name, char *path);
int plugin_init(struct plugin *p);
int plugin_destroy(struct plugin *p);

View file

@ -81,10 +81,11 @@ int node_start(struct node *n)
info("Starting node %s", node_name_long(n));
{ INDENT
ret = n->_vt->start ? n->_vt->start(n) : -1;
if (ret)
return ret;
}
if (ret == 0)
n->state = STATE_STARTED;
n->state = STATE_STARTED;
n->sequence = 0;

View file

@ -46,9 +46,6 @@ int socket_init(int argc, char *argv[], config_setting_t *cfg)
/* Gather list of used network interfaces */
list_foreach(struct node *n, &p.node.instances) {
if (n->state != STATE_INITIALIZED)
continue;
struct socket *s = n->_vd;
struct rtnl_link *link;

View file

@ -221,12 +221,12 @@ int path_parse(struct path *p, config_setting_t *cfg, struct list *nodes)
if (n->_vt->write == NULL)
cerror(cfg_out, "Output node '%s' is not supported as a destination.", node_name(n));
struct path_destination *pd = alloc(sizeof(struct path_destination));
struct path_destination pd;
pd->node = n;
pd->queuelen = queuelen;
pd.node = n;
pd.queuelen = queuelen;
list_push(&p->destinations, pd);
list_push(&p->destinations, memdup(&pd, sizeof(pd)));
}
list_destroy(&destinations, NULL, false);
@ -236,7 +236,9 @@ int path_parse(struct path *p, config_setting_t *cfg, struct list *nodes)
int path_check(struct path *p)
{
list_foreach (struct node *n, &p->destinations) {
assert(p->state != STATE_DESTROYED);
list_foreach(struct node *n, &p->destinations) {
if (!n->_vt->write)
error("Destiation node '%s' is not supported as a sink for path '%s'", node_name(n), path_name(p));
}
@ -296,13 +298,13 @@ int path_start(struct path *p)
assert(p->state == STATE_CHECKED);
info("Starting path: %s (#hooks=%zu)",
path_name(p), list_length(&p->hooks));
info("Starting path: %s (#hooks=%zu)", path_name(p), list_length(&p->hooks));
ret = hook_run(p, NULL, 0, HOOK_PATH_START);
if (ret)
return ret;
/* Start one thread per path for sending to destinations */
ret = pthread_create(&p->tid, NULL, &path_run, p);
if (ret)
return ret;

View file

@ -11,16 +11,26 @@
/** Global list of all known plugins */
struct list plugins = LIST_INIT();
int plugin_init(struct plugin *p, char *name, char *path)
int plugin_init(struct plugin *p)
{
p->name = strdup(name);
p->path = strdup(path);
assert(p->state == STATE_DESTROYED);
p->state = STATE_INITIALIZED;
return 0;
}
int plugin_parse(struct plugin *p, config_setting_t *cfg)
{
const char *path;
path = config_setting_get_string(cfg);
if (!path)
cerror(cfg, "Setting 'plugin' must be a string.");
return 0;
}
int plugin_load(struct plugin *p)
{
p->handle = dlopen(p->path, RTLD_NOW);
@ -57,17 +67,6 @@ int plugin_destroy(struct plugin *p)
return 0;
}
int plugin_parse(struct plugin *p, config_setting_t *cfg)
{
const char *path;
path = config_setting_get_string(cfg);
if (!path)
cerror(cfg, "Setting 'plugin' must be a string.");
return 0;
}
struct plugin * plugin_lookup(enum plugin_type type, const char *name)
{
list_foreach(struct plugin *l, &plugins) {

View file

@ -182,7 +182,11 @@ int super_node_parse(struct super_node *sn, config_setting_t *cfg)
for (int i = 0; i < config_setting_length(cfg_plugins); i++) {
struct config_setting_t *cfg_plugin = config_setting_get_elem(cfg_plugins, i);
struct plugin plugin;
struct plugin plugin = { .state = STATE_DESTROYED };
ret = plugin_init(&plugin);
if (ret)
cerror(cfg_plugin, "Failed to initialize plugin");
ret = plugin_parse(&plugin, cfg_plugin);
if (ret)
@ -207,23 +211,24 @@ int super_node_parse(struct super_node *sn, config_setting_t *cfg)
/* Required settings */
if (!config_setting_lookup_string(cfg_node, "type", &type))
cerror(cfg_node, "Missing node type");
p = plugin_lookup(PLUGIN_TYPE_NODE, type);
if (!p)
cerror(cfg_node, "Invalid node type: %s", type);
struct node n = { .state = STATE_DESTROYED };
struct node *n = alloc(sizeof(struct node));
ret = node_init(&n, &p->node);
n->state = STATE_DESTROYED;
ret = node_init(n, &p->node);
if (ret)
cerror(cfg_node, "Failed to initialize node");
ret = node_parse(&n, cfg_node);
ret = node_parse(n, cfg_node);
if (ret)
cerror(cfg_node, "Failed to parse node");
list_push(&sn->nodes, memdup(&n, sizeof(n)));
list_push(&sn->nodes, n);
}
}

View file

@ -124,8 +124,6 @@ static void logger(int level, const char *msg) {
int web_init(struct web *w, struct api *a)
{
info("Initialize web sub-system");
lws_set_log_level((1 << LLL_COUNT) - 1, logger);
w->api = a;