mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
cleaning function namespaces: config_ => cfg
This commit is contained in:
parent
cbe29caf98
commit
812eb31c95
7 changed files with 62 additions and 47 deletions
3
Makefile
3
Makefile
|
@ -23,10 +23,11 @@ V ?= 2
|
|||
GIT_REV = $(shell git rev-parse --short HEAD)
|
||||
|
||||
# Compiler and linker flags
|
||||
LDLIBS = -pthread -lrt -lm -lconfig -lvillas -ldl
|
||||
LDLIBS = -pthread -lm -lvillas
|
||||
|
||||
LIB_CFLAGS = -fPIC
|
||||
LIB_LDFLAGS = -shared
|
||||
LIB_LDLIBS = -ldl -lrt
|
||||
|
||||
CFLAGS += -std=c11 -Iinclude -Iinclude/villas -I. -MMD -mcx16
|
||||
CFLAGS += -Wall -fdiagnostics-color=auto
|
||||
|
|
|
@ -25,6 +25,16 @@ struct settings;
|
|||
#define config_setting_lookup config_lookup_from
|
||||
#endif
|
||||
|
||||
/** Simple wrapper around libconfig's config_init()
|
||||
*
|
||||
* This allows us to avoid an additional library dependency to libconfig
|
||||
* for the excuctables. They only have to depend on libvillas.
|
||||
*/
|
||||
void cfg_init(config_t *cfg);
|
||||
|
||||
/** Simple wrapper around libconfig's config_init() */
|
||||
void cfg_destroy(config_t *cfg);
|
||||
|
||||
/** Parse config file and store settings in supplied struct settings.
|
||||
*
|
||||
* @param filename The path to the configration file (relative or absolute)
|
||||
|
@ -35,7 +45,7 @@ struct settings;
|
|||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
||||
int cfg_parse(const char *filename, config_t *cfg, struct settings *set,
|
||||
struct list *nodes, struct list *paths);
|
||||
|
||||
/** Parse the global section of a configuration file.
|
||||
|
@ -45,7 +55,7 @@ int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
|||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int config_parse_global(config_setting_t *cfg, struct settings *set);
|
||||
int cfg_parse_global(config_setting_t *cfg, struct settings *set);
|
||||
|
||||
/** Parse a single path and add it to the global configuration.
|
||||
*
|
||||
|
@ -56,7 +66,7 @@ int config_parse_global(config_setting_t *cfg, struct settings *set);
|
|||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int config_parse_path(config_setting_t *cfg,
|
||||
int cfg_parse_path(config_setting_t *cfg,
|
||||
struct list *paths, struct list *nodes, struct settings *set);
|
||||
|
||||
/** Parse an array or single node and checks if they exist in the "nodes" section.
|
||||
|
@ -69,7 +79,7 @@ int config_parse_path(config_setting_t *cfg,
|
|||
* @param nodes The nodes will be added to this list.
|
||||
* @param all This list contains all valid nodes.
|
||||
*/
|
||||
int config_parse_nodelist(config_setting_t *cfg, struct list *nodes, struct list *all);
|
||||
int cfg_parse_nodelist(config_setting_t *cfg, struct list *nodes, struct list *all);
|
||||
|
||||
/** Parse an array or single hook function.
|
||||
*
|
||||
|
@ -77,7 +87,7 @@ int config_parse_nodelist(config_setting_t *cfg, struct list *nodes, struct list
|
|||
* hooks = [ "print", "fir" ]
|
||||
* hooks = "log"
|
||||
**/
|
||||
int config_parse_hooklist(config_setting_t *cfg, struct list *hooks);
|
||||
int cfg_parse_hooklist(config_setting_t *cfg, struct list *hooks);
|
||||
|
||||
/** Parse a single hook and append it to the list.
|
||||
* A hook definition is composed of the hook name and optional parameters
|
||||
|
@ -86,7 +96,7 @@ int config_parse_hooklist(config_setting_t *cfg, struct list *hooks);
|
|||
* Examples:
|
||||
* "print:stdout"
|
||||
*/
|
||||
int config_parse_hook(config_setting_t *cfg, struct list *list);
|
||||
int cfg_parse_hook(config_setting_t *cfg, struct list *list);
|
||||
|
||||
/** Parse a single node and add it to the global configuration.
|
||||
*
|
||||
|
@ -96,6 +106,6 @@ int config_parse_hook(config_setting_t *cfg, struct list *list);
|
|||
* @retval 0 Success. Everything went well.
|
||||
* @retval <0 Error. Something went wrong.
|
||||
*/
|
||||
int config_parse_node(config_setting_t *cfg, struct list *nodes, struct settings *set);
|
||||
int cfg_parse_node(config_setting_t *cfg, struct list *nodes, struct settings *set);
|
||||
|
||||
#endif /* _CFG_H_ */
|
||||
|
|
46
lib/cfg.c
46
lib/cfg.c
|
@ -19,12 +19,24 @@
|
|||
#include "path.h"
|
||||
#include "hooks.h"
|
||||
|
||||
int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
||||
void cfg_init(config_t *cfg)
|
||||
{
|
||||
config_init(cfg);
|
||||
}
|
||||
|
||||
void cfg_destroy(config_t *cfg)
|
||||
{
|
||||
config_destroy(cfg);
|
||||
}
|
||||
|
||||
int cfg_parse(const char *filename, config_t *cfg, struct settings *set,
|
||||
struct list *nodes, struct list *paths)
|
||||
{
|
||||
int ret;
|
||||
char *filename_cpy, *include_dir;
|
||||
|
||||
config_init(cfg);
|
||||
|
||||
filename_cpy = strdup(filename);
|
||||
include_dir = dirname(filename_cpy);
|
||||
|
||||
|
@ -56,7 +68,7 @@ int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
|||
if (!cfg_root || !config_setting_is_group(cfg_root))
|
||||
error("Missing global section in config file: %s", filename);
|
||||
|
||||
config_parse_global(cfg_root, set);
|
||||
cfg_parse_global(cfg_root, set);
|
||||
}
|
||||
|
||||
/* Parse nodes */
|
||||
|
@ -67,7 +79,7 @@ int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
|||
|
||||
for (int i = 0; i < config_setting_length(cfg_nodes); i++) {
|
||||
config_setting_t *cfg_node = config_setting_get_elem(cfg_nodes, i);
|
||||
config_parse_node(cfg_node, nodes, set);
|
||||
cfg_parse_node(cfg_node, nodes, set);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,14 +91,14 @@ int config_parse(const char *filename, config_t *cfg, struct settings *set,
|
|||
|
||||
for (int i = 0; i < config_setting_length(cfg_paths); i++) {
|
||||
config_setting_t *cfg_path = config_setting_get_elem(cfg_paths, i);
|
||||
config_parse_path(cfg_path, paths, nodes, set);
|
||||
cfg_parse_path(cfg_path, paths, nodes, set);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_plugins(config_setting_t *cfg)
|
||||
int cfg_parse_plugins(config_setting_t *cfg)
|
||||
{
|
||||
if (!config_setting_is_array(cfg))
|
||||
cerror(cfg, "Setting 'plugins' must be a list of strings");
|
||||
|
@ -107,7 +119,7 @@ int config_parse_plugins(config_setting_t *cfg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_global(config_setting_t *cfg, struct settings *set)
|
||||
int cfg_parse_global(config_setting_t *cfg, struct settings *set)
|
||||
{
|
||||
config_setting_t *cfg_plugins;
|
||||
|
||||
|
@ -125,14 +137,14 @@ int config_parse_global(config_setting_t *cfg, struct settings *set)
|
|||
|
||||
cfg_plugins = config_setting_get_member(cfg, "plugins");
|
||||
if (cfg_plugins)
|
||||
config_parse_plugins(cfg_plugins);
|
||||
cfg_parse_plugins(cfg_plugins);
|
||||
|
||||
log_setlevel(set->debug, -1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_path(config_setting_t *cfg,
|
||||
int cfg_parse_path(config_setting_t *cfg,
|
||||
struct list *paths, struct list *nodes, struct settings *set)
|
||||
{
|
||||
config_setting_t *cfg_out, *cfg_hook;
|
||||
|
@ -163,7 +175,7 @@ int config_parse_path(config_setting_t *cfg,
|
|||
!(cfg_out = config_setting_get_member(cfg, "sink")))
|
||||
cerror(cfg, "Missing output nodes for path");
|
||||
|
||||
ret = config_parse_nodelist(cfg_out, &p->destinations, nodes);
|
||||
ret = cfg_parse_nodelist(cfg_out, &p->destinations, nodes);
|
||||
if (ret <= 0)
|
||||
cerror(cfg_out, "Invalid output nodes");
|
||||
|
||||
|
@ -179,7 +191,7 @@ int config_parse_path(config_setting_t *cfg,
|
|||
/* Optional settings */
|
||||
cfg_hook = config_setting_get_member(cfg, "hook");
|
||||
if (cfg_hook)
|
||||
config_parse_hooklist(cfg_hook, &p->hooks);
|
||||
cfg_parse_hooklist(cfg_hook, &p->hooks);
|
||||
|
||||
if (!config_setting_lookup_int(cfg, "values", &p->samplelen))
|
||||
p->samplelen = DEFAULT_VALUES;
|
||||
|
@ -208,7 +220,7 @@ int config_parse_path(config_setting_t *cfg,
|
|||
list_push(&r->destinations, p->in);
|
||||
|
||||
if (cfg_hook)
|
||||
config_parse_hooklist(cfg_hook, &r->hooks);
|
||||
cfg_parse_hooklist(cfg_hook, &r->hooks);
|
||||
|
||||
list_push(paths, r);
|
||||
}
|
||||
|
@ -216,7 +228,7 @@ int config_parse_path(config_setting_t *cfg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_nodelist(config_setting_t *cfg, struct list *list, struct list *all) {
|
||||
int cfg_parse_nodelist(config_setting_t *cfg, struct list *list, struct list *all) {
|
||||
const char *str;
|
||||
struct node *node;
|
||||
|
||||
|
@ -260,7 +272,7 @@ int config_parse_nodelist(config_setting_t *cfg, struct list *list, struct list
|
|||
return list_length(list);
|
||||
}
|
||||
|
||||
int config_parse_node(config_setting_t *cfg, struct list *nodes, struct settings *set)
|
||||
int cfg_parse_node(config_setting_t *cfg, struct list *nodes, struct settings *set)
|
||||
{
|
||||
const char *type, *name;
|
||||
int ret;
|
||||
|
@ -307,15 +319,15 @@ int config_parse_node(config_setting_t *cfg, struct list *nodes, struct settings
|
|||
return ret;
|
||||
}
|
||||
|
||||
int config_parse_hooklist(config_setting_t *cfg, struct list *list) {
|
||||
int cfg_parse_hooklist(config_setting_t *cfg, struct list *list) {
|
||||
switch (config_setting_type(cfg)) {
|
||||
case CONFIG_TYPE_STRING:
|
||||
config_parse_hook(cfg, list);
|
||||
cfg_parse_hook(cfg, list);
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_ARRAY:
|
||||
for (int i = 0; i < config_setting_length(cfg); i++)
|
||||
config_parse_hook(config_setting_get_elem(cfg, i), list);
|
||||
cfg_parse_hook(config_setting_get_elem(cfg, i), list);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -325,7 +337,7 @@ int config_parse_hooklist(config_setting_t *cfg, struct list *list) {
|
|||
return list_length(list);
|
||||
}
|
||||
|
||||
int config_parse_hook(config_setting_t *cfg, struct list *list)
|
||||
int cfg_parse_hook(config_setting_t *cfg, struct list *list)
|
||||
{
|
||||
struct hook *hook, *copy;
|
||||
const char *name = config_setting_get_string(cfg);
|
||||
|
|
|
@ -81,10 +81,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
info("Parsing configuration");
|
||||
{ INDENT
|
||||
config_init(&config);
|
||||
config_parse(argv[1], &config, &settings, NULL, NULL);
|
||||
}
|
||||
cfg_parse(argv[1], &config, &settings, NULL, NULL);
|
||||
|
||||
info("Initialize real-time system");
|
||||
rt_init(settings.affinity, settings.priority);
|
||||
|
@ -108,6 +105,8 @@ int main(int argc, char *argv[])
|
|||
ret = fpga_deinit(&fpga);
|
||||
if (ret)
|
||||
error("Failed to de-initialize fpga card");
|
||||
|
||||
cfg_destroy(&config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ static void quit()
|
|||
/* Freeing dynamically allocated memory */
|
||||
list_destroy(&paths, (dtor_cb_t) path_destroy, false);
|
||||
list_destroy(&nodes, (dtor_cb_t) node_destroy, false);
|
||||
config_destroy(&config);
|
||||
cfg_destroy(&config);
|
||||
|
||||
info(GRN("Goodbye!"));
|
||||
|
||||
|
@ -120,11 +120,8 @@ int main(int argc, char *argv[])
|
|||
list_init(&nodes);
|
||||
|
||||
info("Parsing configuration");
|
||||
{ INDENT
|
||||
config_init(&config);
|
||||
config_parse(configfile, &config, &settings, &nodes, &paths);
|
||||
}
|
||||
|
||||
cfg_parse(configfile, &config, &settings, &nodes, &paths);
|
||||
|
||||
info("Initialize real-time system");
|
||||
rt_init(settings.affinity, settings.priority);
|
||||
|
||||
|
|
15
src/pipe.c
15
src/pipe.c
|
@ -27,8 +27,9 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
struct list nodes; /**< List of all nodes */
|
||||
struct settings settings; /**< The global configuration */
|
||||
static struct list nodes; /**< List of all nodes */
|
||||
static struct settings settings; /**< The global configuration */
|
||||
static config_t config;
|
||||
|
||||
struct dir {
|
||||
struct pool pool;
|
||||
|
@ -62,6 +63,7 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx)
|
|||
node_deinit(node->_vt);
|
||||
|
||||
list_destroy(&nodes, (dtor_cb_t) node_destroy, false);
|
||||
cfg_destroy(&config);
|
||||
|
||||
info(GRN("Goodbye!"));
|
||||
exit(EXIT_SUCCESS);
|
||||
|
@ -169,8 +171,6 @@ int main(int argc, char *argv[])
|
|||
int ret;
|
||||
char c;
|
||||
|
||||
config_t config;
|
||||
|
||||
ptid = pthread_self();
|
||||
log_init();
|
||||
|
||||
|
@ -216,11 +216,8 @@ int main(int argc, char *argv[])
|
|||
list_init(&nodes);
|
||||
|
||||
info("Parsing configuration");
|
||||
{ INDENT
|
||||
config_init(&config);
|
||||
config_parse(argv[1], &config, &settings, &nodes, NULL);
|
||||
}
|
||||
|
||||
cfg_parse(argv[1], &config, &settings, &nodes, NULL);
|
||||
|
||||
info("Initialize real-time system");
|
||||
rt_init(settings.affinity, settings.priority);
|
||||
|
||||
|
|
|
@ -85,8 +85,7 @@ int main(int argc, char *argv[])
|
|||
list_init(&nodes);
|
||||
|
||||
log_init();
|
||||
config_init(&config);
|
||||
config_parse(argv[1], &config, &settings, &nodes, NULL);
|
||||
cfg_parse(argv[1], &config, &settings, &nodes, NULL);
|
||||
|
||||
node = list_lookup(&nodes, argv[3]);
|
||||
if (!node)
|
||||
|
@ -141,7 +140,7 @@ check: if (optarg == endptr)
|
|||
node_deinit(node->_vt);
|
||||
|
||||
list_destroy(&nodes, (dtor_cb_t) node_destroy, false);
|
||||
config_destroy(&config);
|
||||
cfg_destroy(&config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue