mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added support for dynamically loaded plugins
This commit is contained in:
parent
238c732feb
commit
d811128459
3 changed files with 26 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -29,7 +29,7 @@ V ?= 2
|
|||
GIT_REV=$(shell git rev-parse --short HEAD)
|
||||
|
||||
# Compiler and linker flags
|
||||
LDLIBS = -pthread -lrt -lm -lconfig -lvillas
|
||||
LDLIBS = -pthread -lrt -lm -lconfig -lvillas -ldl
|
||||
|
||||
LIB_LDFLAGS = -shared
|
||||
|
||||
|
|
|
@ -95,6 +95,10 @@ fpga = {
|
|||
)
|
||||
}
|
||||
|
||||
plugins = [
|
||||
"./lib/cbmodels/simple_circuit.so"
|
||||
]
|
||||
|
||||
nodes = {
|
||||
dma = {
|
||||
datamover = "dma_0";
|
||||
|
|
21
lib/cfg.c
21
lib/cfg.c
|
@ -9,6 +9,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "list.h"
|
||||
|
@ -83,6 +84,26 @@ int config_parse_global(config_setting_t *cfg, struct settings *set)
|
|||
config_setting_lookup_int(cfg, "priority", &set->priority);
|
||||
config_setting_lookup_int(cfg, "debug", &set->debug);
|
||||
config_setting_lookup_float(cfg, "stats", &set->stats);
|
||||
|
||||
/* Load plugins */
|
||||
cfg_plugins = config_setting_get_member(cfg, "plugins");
|
||||
if (cfg) {
|
||||
if (!config_setting_is_array(cfg_plugins))
|
||||
cerror(cfg_plugins, "Setting 'plugings' must be a list of strings");
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg_plugins); i++) {
|
||||
void *handle;
|
||||
const char *path;
|
||||
|
||||
path = config_setting_get_string_elem(cfg_plugins, i);
|
||||
if (!path)
|
||||
cerror(cfg_plugins, "Setting 'plugings' must be a list of strings");
|
||||
|
||||
handle = dlopen(path, RTLD_NOW);
|
||||
if (!handle)
|
||||
error("Failed to load plugin %s", dlerror());
|
||||
}
|
||||
}
|
||||
|
||||
log_setlevel(set->debug, -1);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue