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

refactor: use libconfig instance only within _parse() functions

This commit is contained in:
Steffen Vogel 2017-08-01 11:56:47 +02:00
parent bc83463831
commit a71053f718
12 changed files with 49 additions and 34 deletions

View file

@ -64,8 +64,6 @@ struct fpga_card {
struct fpga_ip *intc;
struct fpga_ip *reset;
struct fpga_ip *sw;
config_setting_t *cfg;
};
/** Initialize FPGA card and its IP components. */

View file

@ -87,8 +87,6 @@ struct fpga_ip {
int irq; /**< The interrupt number of the FPGA IP component. */
struct fpga_card *card; /**< The FPGA to which this IP instance belongs to. */
config_setting_t *cfg;
};
/** Initialize IP core. */

View file

@ -43,8 +43,7 @@
*/
struct node
{
const char *name; /**< A short identifier of the node, only used for configuration and logging */
char *name; /**< A short identifier of the node, only used for configuration and logging */
char *_name; /**< Singleton: A string used to print to screen. */
char *_name_long; /**< Singleton: A string used to print to screen. */
@ -59,8 +58,6 @@ struct node
struct node_type *_vt; /**< Virtual functions (C++ OOP style) */
void *_vd; /**< Virtual data (used by struct node::_vt functions) */
config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this node */
};
int node_init(struct node *n, struct node_type *vt);

View file

@ -83,7 +83,6 @@ struct path
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. */
};
/** Initialize internal data structures. */

View file

@ -40,9 +40,9 @@ struct web {
struct lws_vhost *vhost; /**< The libwebsockets vhost. */
int port; /**< Port of the build in HTTP / WebSocket server. */
const char *htdocs; /**< The root directory for files served via HTTP. */
const char *ssl_cert; /**< Path to the SSL certitifcate for HTTPS / WSS. */
const char *ssl_private_key; /**< Path to the SSL private key for HTTPS / WSS. */
char *htdocs; /**< The root directory for files served via HTTP. */
char *ssl_cert; /**< Path to the SSL certitifcate for HTTPS / WSS. */
char *ssl_private_key; /**< Path to the SSL private key for HTTPS / WSS. */
pthread_t thread;
};

View file

@ -96,8 +96,7 @@ int hook_parse_cli(struct hook *h, int argc, char *argv[])
ret = hook_parse(h, cfg_root);
out:
config_destroy(&cfg);
out: config_destroy(&cfg);
}
return ret;

View file

@ -40,7 +40,7 @@ struct stats_collect {
int buckets;
AFILE *output;
const char *uri;
char *uri;
};
static int stats_collect_init(struct hook *h)
@ -67,6 +67,9 @@ static int stats_collect_destroy(struct hook *h)
{
struct stats_collect *p = h->_vd;
if (p->uri)
free(p->uri);
return stats_destroy(&p->stats);
}
@ -117,7 +120,7 @@ static int stats_collect_parse(struct hook *h, config_setting_t *cfg)
{
struct stats_collect *p = h->_vd;
const char *format;
const char *format, *uri;
if (config_setting_lookup_string(cfg, "format", &format)) {
int fmt;
@ -131,7 +134,9 @@ static int stats_collect_parse(struct hook *h, config_setting_t *cfg)
config_setting_lookup_bool(cfg, "verbose", &p->verbose);
config_setting_lookup_int(cfg, "warmup", &p->warmup);
config_setting_lookup_int(cfg, "buckets", &p->buckets);
config_setting_lookup_string(cfg, "output", &p->uri);
if (config_setting_lookup_string(cfg, "output", &uri))
p->uri = strdup(uri);
return 0;
}

View file

@ -39,6 +39,7 @@ int node_init(struct node *n, struct node_type *vt)
n->_vt = vt;
n->_vd = alloc(vt->size);
n->name = NULL;
n->id = max_id++;
/* Default values */
@ -67,8 +68,7 @@ int node_parse(struct node *n, config_setting_t *cfg)
config_setting_lookup_int(cfg, "vectorize", &n->vectorize);
n->name = name;
n->cfg = cfg;
n->name = strdup(name);
ret = n->_vt->parse ? n->_vt->parse(n, cfg) : 0;
if (ret)
@ -188,6 +188,9 @@ int node_destroy(struct node *n)
if (n->_name_long)
free(n->_name_long);
if (n->name)
free(n->name);
n->state = STATE_DESTROYED;
return 0;

View file

@ -392,9 +392,8 @@ int ngsi_init(struct super_node *sn)
cfg = config_root_setting(&sn->cfg);
const char *tname;
if (config_setting_lookup_string(cfg, "name", &tname)) {
if (config_setting_lookup_string(cfg, "name", &tname))
name = strdup(tname);
}
else {
name = alloc(128); /** @todo missing free */
gethostname((char *) name, 128);
@ -602,4 +601,3 @@ static struct plugin p = {
REGISTER_PLUGIN(&p)
LIST_INIT_STATIC(&p.node.instances)

View file

@ -225,8 +225,6 @@ int path_parse(struct path *p, config_setting_t *cfg, struct list *nodes)
warn("Queue length should always be a power of 2. Adjusting to %d", p->queuelen);
}
p->cfg = cfg;
p->source = alloc(sizeof(struct path_source));
p->source->node = source;
p->source->samplelen = p->samplelen;
@ -437,7 +435,6 @@ int path_reverse(struct path *p, struct path *r)
/* General */
r->enabled = p->enabled;
r->cfg = p->cfg;
struct path_destination *pd = alloc(sizeof(struct path_destination));

View file

@ -65,8 +65,6 @@ int super_node_init(struct super_node *sn)
{
assert(sn->state == STATE_DESTROYED);
config_init(&sn->cfg);
log_init(&sn->log, V, LOG_ALL);
#ifdef WITH_API
api_init(&sn->api, sn);
@ -131,6 +129,7 @@ int super_node_parse_uri(struct super_node *sn, const char *uri)
if (!f)
error("Failed to open configuration");
config_init(&sn->cfg);
config_set_destructor(&sn->cfg, config_dtor);
config_set_auto_convert(&sn->cfg, 1);
@ -177,7 +176,11 @@ int super_node_parse_uri(struct super_node *sn, const char *uri)
else if (f != stdin)
fclose(f);
return super_node_parse(sn, cfg_root);
ret = super_node_parse(sn, cfg_root);
config_destroy(&sn->cfg);
return ret;
}
else { INDENT
warn("No configuration file specified. Starting unconfigured. Use the API to configure this instance.");
@ -458,8 +461,6 @@ int super_node_destroy(struct super_node *sn)
#endif
log_destroy(&sn->log);
config_destroy(&sn->cfg);
sn->state = STATE_DESTROYED;
return 0;

View file

@ -161,7 +161,7 @@ int web_init(struct web *w, struct api *a)
/* Default values */
w->port = getuid() > 0 ? 8080 : 80; /**< @todo Use libcap to check if user can bind to ports < 1024 */
w->htdocs = WEB_PATH;
w->htdocs = strdup(WEB_PATH);
w->state = STATE_INITIALIZED;
@ -171,14 +171,25 @@ int web_init(struct web *w, struct api *a)
int web_parse(struct web *w, config_setting_t *cfg)
{
int enabled = true;
const char *ssl_cert, *ssl_private_key, *htdocs;
if (!config_setting_is_group(cfg))
cerror(cfg, "Setting 'http' must be a group.");
config_setting_lookup_string(cfg, "ssl_cert", &w->ssl_cert);
config_setting_lookup_string(cfg, "ssl_private_key", &w->ssl_private_key);
if (config_setting_lookup_string(cfg, "ssl_cert", &ssl_cert))
w->ssl_cert = strdup(ssl_cert);
if (config_setting_lookup_string(cfg, "ssl_private_key", &ssl_private_key))
w->ssl_private_key = strdup(ssl_private_key);
if (config_setting_lookup_string(cfg, "htdocs", &htdocs)) {
if (w->htdocs)
free(w->htdocs);
w->htdocs = strdup(htdocs);
}
config_setting_lookup_int(cfg, "port", &w->port);
config_setting_lookup_string(cfg, "htdocs", &w->htdocs);
config_setting_lookup_bool(cfg, "enabled", &enabled);
if (!enabled)
@ -264,6 +275,15 @@ int web_destroy(struct web *w)
lws_context_destroy(w->context);
}
if (w->ssl_cert)
free(w->ssl_cert);
if (w->ssl_private_key)
free(w->ssl_private_key);
if (w->htdocs)
free(w->htdocs);
w->state = STATE_DESTROYED;
return 0;