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

plugin: strip down old plugin system

This commit is contained in:
Steffen Vogel 2019-01-21 16:21:26 +01:00
parent c5ec56908a
commit 720e5e688c
6 changed files with 2 additions and 140 deletions

View file

@ -31,7 +31,6 @@
# Some global settings are used by multiple configuration files
# and therefore defined in separate files
@include "global.conf"
@include "plugins.conf"
############ Dictionary of nodes ############

View file

@ -1,36 +0,0 @@
/** Example plugins configuration file for VILLASnode.
*
* The syntax of this file is similar to JSON.
* A detailed description of the format can be found here:
* http://www.hyperrealm.com/libconfig/libconfig_manual.html#Configuration-Files
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014-2019, 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/>.
*********************************************************************************/
############ List of plugins ############
#
# Additional node-types, hooks or formats
# can be loaded by compiling them into a shared library and
# adding them to this list
plugins = [
"simple_circuit.so",
"example_hook.so"
]

View file

@ -69,14 +69,8 @@ enum plugin_type {
struct plugin {
const char *name;
const char *description;
void *handle;
char *path;
enum plugin_type type;
enum state state;
int (*load)(struct plugin *p);
int (*unload)(struct plugin *p);
union {
struct format_type format;
@ -92,16 +86,6 @@ struct plugin {
#define plugin_name(vt) plugin(vt)->name
#define plugin_description(vt) plugin(vt)->description
int plugin_init(struct plugin *p);
int plugin_destroy(struct plugin *p);
int plugin_parse(struct plugin *p, json_t *cfg);
int plugin_load(struct plugin *p);
int plugin_unload(struct plugin *p);
void plugin_dump(enum plugin_type type);
/** Find registered and loaded plugin with given name and type. */

View file

@ -50,7 +50,6 @@ protected:
struct vlist nodes;
struct vlist paths;
struct vlist interfaces;
struct vlist plugins;
#ifdef WITH_API
Api api;

View file

@ -30,64 +30,6 @@ struct vlist plugins = { .state = STATE_DESTROYED };
LIST_INIT_STATIC(&plugins)
int plugin_init(struct plugin *p)
{
assert(p->state == STATE_DESTROYED);
p->state = STATE_INITIALIZED;
return 0;
}
int plugin_parse(struct plugin *p, json_t *cfg)
{
const char *path;
path = json_string_value(cfg);
if (!path)
return -1;
p->path = strdup(path);
return 0;
}
int plugin_load(struct plugin *p)
{
p->handle = dlopen(p->path, RTLD_NOW);
if (!p->path)
return -1;
p->state = STATE_LOADED;
return 0;
}
int plugin_unload(struct plugin *p)
{
int ret;
assert(p->state == STATE_LOADED);
ret = dlclose(p->handle);
if (ret)
return -1;
p->state = STATE_UNLOADED;
return 0;
}
int plugin_destroy(struct plugin *p)
{
assert(p->state != STATE_DESTROYED && p->state != STATE_LOADED);
if (p->path)
free(p->path);
return 0;
}
struct plugin * plugin_lookup(enum plugin_type type, const char *name)
{
for (size_t i = 0; i < vlist_length(&plugins); i++) {

View file

@ -55,12 +55,11 @@ SuperNode::SuperNode() :
{
nodes.state = STATE_DESTROYED;
paths.state = STATE_DESTROYED;
plugins.state = STATE_DESTROYED;
interfaces.state = STATE_DESTROYED;
vlist_init(&nodes);
vlist_init(&paths);
vlist_init(&interfaces);
vlist_init(&plugins);
#ifdef WITH_NETEM
nl_init(); /* Fill link cache */
@ -170,16 +169,14 @@ int SuperNode::parseJson(json_t *j)
json_t *json_nodes = nullptr;
json_t *json_paths = nullptr;
json_t *json_plugins = nullptr;
json_t *json_logging = nullptr;
json_t *json_web = nullptr;
json_error_t err;
ret = json_unpack_ex(j, &err, 0, "{ s?: o, s?: o, s?: o, s?: o, s?: o, s?: i, s?: i, s?: i, s?: F, s?: s }",
ret = json_unpack_ex(j, &err, 0, "{ s?: o, s?: o, s?: o, s?: o, s?: i, s?: i, s?: i, s?: F, s?: s }",
"http", &json_web,
"logging", &json_logging,
"plugins", &json_plugins,
"nodes", &json_nodes,
"paths", &json_paths,
"hugepages", &hugepages,
@ -202,28 +199,6 @@ int SuperNode::parseJson(json_t *j)
if (json_logging)
logging.parse(json_logging);
/* Parse plugins */
if (json_plugins) {
if (!json_is_array(json_plugins))
throw ConfigError(json_plugins, "node-config-plugins", "Setting 'plugins' must be a list of strings");
size_t i;
json_t *json_plugin;
json_array_foreach(json_plugins, i, json_plugin) {
auto *p = (plugin *) alloc(sizeof(plugin));
ret = plugin_init(p);
if (ret)
throw RuntimeError("Failed to initialize plugin");
ret = plugin_parse(p, json_plugin);
if (ret)
throw RuntimeError("Failed to parse plugin");
vlist_push(&plugins, p);
}
}
/* Parse nodes */
if (json_nodes) {
if (!json_is_object(json_nodes))
@ -496,7 +471,6 @@ SuperNode::~SuperNode()
{
assert(state != STATE_STARTED);
vlist_destroy(&plugins, (dtor_cb_t) plugin_destroy, false);
vlist_destroy(&paths, (dtor_cb_t) path_destroy, true);
vlist_destroy(&nodes, (dtor_cb_t) node_destroy, true);
vlist_destroy(&interfaces, (dtor_cb_t) if_destroy, true);