From 720e5e688cac73605503f94728e37ba3ebccd2b8 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 21 Jan 2019 16:21:26 +0100 Subject: [PATCH] plugin: strip down old plugin system --- etc/example.conf | 1 - etc/plugins.conf | 36 ---------------------- include/villas/plugin.h | 16 ---------- include/villas/super_node.hpp | 1 - lib/plugin.c | 58 ----------------------------------- lib/super_node.cpp | 30 ++---------------- 6 files changed, 2 insertions(+), 140 deletions(-) delete mode 100644 etc/plugins.conf diff --git a/etc/example.conf b/etc/example.conf index cdbe05638..a70699bde 100644 --- a/etc/example.conf +++ b/etc/example.conf @@ -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 ############ diff --git a/etc/plugins.conf b/etc/plugins.conf deleted file mode 100644 index 66142606d..000000000 --- a/etc/plugins.conf +++ /dev/null @@ -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 - * @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 . - *********************************************************************************/ - -############ 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" -] diff --git a/include/villas/plugin.h b/include/villas/plugin.h index c0cc377b8..017b02189 100644 --- a/include/villas/plugin.h +++ b/include/villas/plugin.h @@ -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. */ diff --git a/include/villas/super_node.hpp b/include/villas/super_node.hpp index 21c0d2771..544268a19 100644 --- a/include/villas/super_node.hpp +++ b/include/villas/super_node.hpp @@ -50,7 +50,6 @@ protected: struct vlist nodes; struct vlist paths; struct vlist interfaces; - struct vlist plugins; #ifdef WITH_API Api api; diff --git a/lib/plugin.c b/lib/plugin.c index 518c0b9bc..2a3da5101 100644 --- a/lib/plugin.c +++ b/lib/plugin.c @@ -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++) { diff --git a/lib/super_node.cpp b/lib/super_node.cpp index 9e5abb208..38dde0438 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -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);