From 14434d093f2880e4d3bf801e339fc3ea72e3502f Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 23 Apr 2019 13:14:47 +0200 Subject: [PATCH] remove old super_node C wrapper code --- include/villas/node_type.h | 6 +-- include/villas/nodes/iec61850.hpp | 2 +- include/villas/nodes/mqtt.hpp | 2 +- include/villas/nodes/ngsi.hpp | 2 +- include/villas/nodes/opal.hpp | 2 +- include/villas/nodes/socket.hpp | 2 +- include/villas/nodes/stats.hpp | 8 +--- include/villas/nodes/websocket.hpp | 2 +- include/villas/nodes/zeromq.hpp | 2 +- include/villas/super_node.h | 60 ---------------------------- include/villas/super_node.hpp | 3 ++ lib/node_type.cpp | 2 +- lib/nodes/iec61850.cpp | 2 +- lib/nodes/mqtt.cpp | 2 +- lib/nodes/ngsi.cpp | 2 +- lib/nodes/opal.cpp | 2 +- lib/nodes/rtp.cpp | 6 +-- lib/nodes/socket.cpp | 8 ++-- lib/nodes/stats.cpp | 8 ++-- lib/nodes/uldaq.cpp | 4 +- lib/nodes/websocket.cpp | 16 ++++---- lib/nodes/zeromq.cpp | 4 +- lib/super_node.cpp | 63 +----------------------------- src/villas-pipe.cpp | 2 +- src/villas-test-rtt.cpp | 2 +- 25 files changed, 48 insertions(+), 166 deletions(-) delete mode 100644 include/villas/super_node.h diff --git a/include/villas/node_type.h b/include/villas/node_type.h index c311d2139..eabd76865 100644 --- a/include/villas/node_type.h +++ b/include/villas/node_type.h @@ -28,12 +28,12 @@ #include +#include #include #include #include /* Forward declarations */ -struct super_node; struct node; struct sample; @@ -62,7 +62,7 @@ struct node_type { * @retval 0 Success. Everything went well. * @retval <0 Error. Something went wrong. */ - int (*start)(struct super_node *sn); + int (*start)(villas::node::SuperNode *sn); /** Global de-initialization per node type. * @@ -228,7 +228,7 @@ struct node_type { * * @see node_type::init */ -int node_type_start(struct node_type *vt, struct super_node *sn); +int node_type_start(struct node_type *vt, villas::node::SuperNode *sn); /** De-initialize node type subsystems. * diff --git a/include/villas/nodes/iec61850.hpp b/include/villas/nodes/iec61850.hpp index 6c6259065..c029ad377 100644 --- a/include/villas/nodes/iec61850.hpp +++ b/include/villas/nodes/iec61850.hpp @@ -97,7 +97,7 @@ struct iec61850_receiver { }; /** @see node_type::type_start */ -int iec61850_type_start(struct super_node *sn); +int iec61850_type_start(villas::node::SuperNode *sn); /** @see node_type::type_stop */ int iec61850_type_stop(); diff --git a/include/villas/nodes/mqtt.hpp b/include/villas/nodes/mqtt.hpp index 6114a9f2d..1a5feeb36 100644 --- a/include/villas/nodes/mqtt.hpp +++ b/include/villas/nodes/mqtt.hpp @@ -85,7 +85,7 @@ int mqtt_destroy(struct node *n); int mqtt_stop(struct node *n); /** @see node_type::type_start */ -int mqtt_type_start(struct super_node *sn); +int mqtt_type_start(villas::node::SuperNode *sn); /** @see node_type::type_stop */ int mqtt_type_stop(); diff --git a/include/villas/nodes/ngsi.hpp b/include/villas/nodes/ngsi.hpp index 885932e1f..88ecf0421 100644 --- a/include/villas/nodes/ngsi.hpp +++ b/include/villas/nodes/ngsi.hpp @@ -68,7 +68,7 @@ struct ngsi { * * @see node_type::type_start */ -int ngsi_type_start(struct super_node *sn); +int ngsi_type_start(villas::node::SuperNode *sn); /** Free global NGSI settings and unmaps shared memory regions. * diff --git a/include/villas/nodes/opal.hpp b/include/villas/nodes/opal.hpp index 8744eafdf..884a5c8f1 100644 --- a/include/villas/nodes/opal.hpp +++ b/include/villas/nodes/opal.hpp @@ -56,7 +56,7 @@ struct opal { * * @see node_type::type_start */ -int opal_type_start(struct super_node *sn); +int opal_type_start(villas::node::SuperNode *sn); /** Free global OPAL settings and unmaps shared memory regions. * diff --git a/include/villas/nodes/socket.hpp b/include/villas/nodes/socket.hpp index 207098d45..b72d93cc0 100644 --- a/include/villas/nodes/socket.hpp +++ b/include/villas/nodes/socket.hpp @@ -66,7 +66,7 @@ struct socket { /** @see node_vtable::type_start */ -int socket_type_start(struct super_node *sn); +int socket_type_start(villas::node::SuperNode *sn); /** @see node_type::type_stop */ int socket_type_stop(); diff --git a/include/villas/nodes/stats.hpp b/include/villas/nodes/stats.hpp index e15dba9c8..612c1ae03 100644 --- a/include/villas/nodes/stats.hpp +++ b/include/villas/nodes/stats.hpp @@ -31,15 +31,11 @@ #include +#include #include #include #include -/* Forward declarations */ -struct node; -struct sample; -struct super_node; - struct stats_node_signal { struct node *node; char *node_str; @@ -57,7 +53,7 @@ struct stats_node { }; /** @see node_type::print */ -int stats_node_type_start(struct super_node *sn); +int stats_node_type_start(villas::node::SuperNode *sn); /** @see node_type::print */ char *stats_node_print(struct node *n); diff --git a/include/villas/nodes/websocket.hpp b/include/villas/nodes/websocket.hpp index b31f6b73f..35eae229f 100644 --- a/include/villas/nodes/websocket.hpp +++ b/include/villas/nodes/websocket.hpp @@ -92,7 +92,7 @@ struct websocket_destination { int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len); /** @see node_type::type_start */ -int websocket_type_start(struct super_node *sn); +int websocket_type_start(villas::node::SuperNode *sn); /** @see node_type::type_stop */ int websocket_type_stop(); diff --git a/include/villas/nodes/zeromq.hpp b/include/villas/nodes/zeromq.hpp index 973e6e6f5..0178225ca 100644 --- a/include/villas/nodes/zeromq.hpp +++ b/include/villas/nodes/zeromq.hpp @@ -87,7 +87,7 @@ char * zeromq_print(struct node *n); int zeromq_parse(struct node *n, json_t *cfg); /** @see node_type::type_start */ -int zeromq_type_start(struct super_node *sn); +int zeromq_type_start(villas::node::SuperNode *sn); /** @see node_type::type_stop */ int zeromq_type_stop(); diff --git a/include/villas/super_node.h b/include/villas/super_node.h deleted file mode 100644 index 41fc05a35..000000000 --- a/include/villas/super_node.h +++ /dev/null @@ -1,60 +0,0 @@ -/** The super node object holding the state of the application (C-compatability header). - * - * @file - * @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 . - *********************************************************************************/ - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Forward declarations */ -struct vlist; -struct web; -struct super_node; -struct lws; - -struct vlist * super_node_get_nodes(struct super_node *sn); - -struct vlist * super_node_get_paths(struct super_node *sn); - -struct vlist * super_node_get_interfaces(struct super_node *sn); - -int super_node_get_cli_argc(struct super_node *sn); - -struct web * super_node_get_web(struct super_node *sn); - -struct lws_context * web_get_context(struct web *w); - -struct lws_vhost * web_get_vhost(struct web *w); - -enum state web_get_state(struct web *w); - -#ifdef WITH_WEB -int web_callback_on_writable(struct web *w, struct lws *wsi); -#endif - -#ifdef __cplusplus -} -#endif diff --git a/include/villas/super_node.hpp b/include/villas/super_node.hpp index 671361ce7..d72d2d940 100644 --- a/include/villas/super_node.hpp +++ b/include/villas/super_node.hpp @@ -32,6 +32,9 @@ #include #include +/* Forward declarations */ +struct node; + namespace villas { namespace node { diff --git a/lib/node_type.cpp b/lib/node_type.cpp index c10cefca9..6de9800cc 100644 --- a/lib/node_type.cpp +++ b/lib/node_type.cpp @@ -29,7 +29,7 @@ #include #include -int node_type_start(struct node_type *vt, struct super_node *sn) +int node_type_start(struct node_type *vt, villas::node::SuperNode *sn) { int ret; diff --git a/lib/nodes/iec61850.cpp b/lib/nodes/iec61850.cpp index b5d8be4ff..3ba2115ac 100644 --- a/lib/nodes/iec61850.cpp +++ b/lib/nodes/iec61850.cpp @@ -172,7 +172,7 @@ int iec61850_parse_signals(json_t *json_signals, struct vlist *signals, struct v return total_size; } -int iec61850_type_start(struct super_node *sn) +int iec61850_type_start(villas::node::SuperNode *sn) { int ret; diff --git a/lib/nodes/mqtt.cpp b/lib/nodes/mqtt.cpp index 1ca39d196..a1d394747 100644 --- a/lib/nodes/mqtt.cpp +++ b/lib/nodes/mqtt.cpp @@ -366,7 +366,7 @@ mosquitto_error: return ret; } -int mqtt_type_start(struct super_node *sn) +int mqtt_type_start(villas::node::SuperNode *sn) { int ret; diff --git a/lib/nodes/ngsi.cpp b/lib/nodes/ngsi.cpp index 1f8e46ab5..a5814921f 100644 --- a/lib/nodes/ngsi.cpp +++ b/lib/nodes/ngsi.cpp @@ -393,7 +393,7 @@ out: json_decref(request); return ret; } -int ngsi_type_start(struct super_node *sn) +int ngsi_type_start(villas::node::SuperNode *sn) { return curl_global_init(CURL_GLOBAL_ALL); } diff --git a/lib/nodes/opal.cpp b/lib/nodes/opal.cpp index afd69a412..c75924cf7 100644 --- a/lib/nodes/opal.cpp +++ b/lib/nodes/opal.cpp @@ -48,7 +48,7 @@ int opal_register_region(int argc, char *argv[]) print_shmem_name = argv[3]; } -int opal_type_start(struct super_node *sn) +int opal_type_start(villas::node::SuperNode *sn) { int err; diff --git a/lib/nodes/rtp.cpp b/lib/nodes/rtp.cpp index c456f50e8..28ed3bf54 100644 --- a/lib/nodes/rtp.cpp +++ b/lib/nodes/rtp.cpp @@ -45,7 +45,7 @@ extern "C" { #include #include #include -#include +#include #ifdef WITH_NETEM #include @@ -457,7 +457,7 @@ static void stop_handler(int sig, siginfo_t *si, void *ctx) typedef void *(*pthread_start_routine)(void *); -int rtp_type_start(struct super_node *sn) +int rtp_type_start(villas::node::SuperNode *sn) { int ret; @@ -484,7 +484,7 @@ int rtp_type_start(struct super_node *sn) return ret; #ifdef WITH_NETEM - struct vlist *interfaces = super_node_get_interfaces(sn); + struct vlist *interfaces = sn->getInterfaces(); /* Gather list of used network interfaces */ for (size_t i = 0; i < vlist_length(&p.node.instances); i++) { diff --git a/lib/nodes/socket.cpp b/lib/nodes/socket.cpp index 34020aeff..4b965bfd1 100644 --- a/lib/nodes/socket.cpp +++ b/lib/nodes/socket.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #ifdef WITH_SOCKET_LAYER_ETH #include @@ -47,10 +47,12 @@ /* Forward declartions */ static struct plugin p; -int socket_type_start(struct super_node *sn) +using namespace villas::node; + +int socket_type_start(villas::node::SuperNode *sn) { #ifdef WITH_NETEM - struct vlist *interfaces = super_node_get_interfaces(sn); + struct vlist *interfaces = sn->getInterfaces(); /* Gather list of used network interfaces */ for (size_t i = 0; i < vlist_length(&p.node.instances); i++) { diff --git a/lib/nodes/stats.cpp b/lib/nodes/stats.cpp index 3e5b6ef34..8bf7db4ba 100644 --- a/lib/nodes/stats.cpp +++ b/lib/nodes/stats.cpp @@ -26,12 +26,14 @@ #include #include #include -#include +#include #include #include #define STATS_METRICS 6 +using namespace villas::node; + static struct vlist *nodes; /** The global list of nodes */ int stats_node_signal_destroy(struct stats_node_signal *s) @@ -87,9 +89,9 @@ invalid_format: return -1; } -int stats_node_type_start(struct super_node *sn) +int stats_node_type_start(villas::node::SuperNode *sn) { - nodes = super_node_get_nodes(sn); + nodes = sn->getNodes(); return 0; } diff --git a/lib/nodes/uldaq.cpp b/lib/nodes/uldaq.cpp index 273aedfe5..0be8ae906 100644 --- a/lib/nodes/uldaq.cpp +++ b/lib/nodes/uldaq.cpp @@ -211,7 +211,7 @@ static int uldaq_connect(struct node *n) return 0; } -int uldaq_type_start(struct super_node *sn) +int uldaq_type_start(villas::node::SuperNode *sn) { UlError err; @@ -665,4 +665,4 @@ __attribute__((destructor(110))) static void deregister_plugin() { if (plugins.state != STATE_DESTROYED) vlist_remove_all(&plugins, &p); -} \ No newline at end of file +} diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index 0a7bb7b24..a813333c4 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -35,14 +35,14 @@ #include #include #include -#include +#include #define DEFAULT_WEBSOCKET_BUFFER_SIZE (1 << 12) /* Private static storage */ static struct vlist connections = { .state = STATE_DESTROYED }; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */ -static struct web *web; +static villas::node::Web *web; /* Forward declarations */ static struct plugin p; @@ -165,7 +165,7 @@ static int websocket_connection_write(struct websocket_connection *c, struct sam /* Client connections which are currently conecting don't have an associate c->wsi yet */ if (c->wsi) - web_callback_on_writable(web, c->wsi); + web->callbackOnWritable(c->wsi); return 0; } @@ -373,12 +373,12 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi return 0; } -int websocket_type_start(struct super_node *sn) +int websocket_type_start(villas::node::SuperNode *sn) { vlist_init(&connections); - web = super_node_get_web(sn); - if (web_get_state(web) != STATE_STARTED) + web = sn->getWeb(); + if (web->getState() != STATE_STARTED) return -1; return 0; @@ -417,8 +417,8 @@ int websocket_start(struct node *n) c->node = n; c->destination = d; - d->info.context = web_get_context(web); - d->info.vhost = web_get_vhost(web); + d->info.context = web->getContext(); + d->info.vhost = web->getVHost(); d->info.userdata = c; lws_client_connect_via_info(&d->info); diff --git a/lib/nodes/zeromq.cpp b/lib/nodes/zeromq.cpp index 529a489ef..2aa65ee43 100644 --- a/lib/nodes/zeromq.cpp +++ b/lib/nodes/zeromq.cpp @@ -245,7 +245,7 @@ char * zeromq_print(struct node *n) return buf; } -int zeromq_type_start(struct super_node *sn) +int zeromq_type_start(villas::node::SuperNode *sn) { context = zmq_ctx_new(); @@ -598,4 +598,4 @@ __attribute__((destructor(110))) static void deregister_plugin() { if (plugins.state != STATE_DESTROYED) vlist_remove_all(&plugins, &p); -} \ No newline at end of file +} diff --git a/lib/super_node.cpp b/lib/super_node.cpp index fe620bf09..857439b1a 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -249,7 +249,7 @@ void SuperNode::startNodeTypes() for (size_t i = 0; i < vlist_length(&nodes); i++) { auto *n = (struct node *) vlist_at(&nodes, i); - ret = node_type_start(n->_vt, reinterpret_cast(this)); + ret = node_type_start(n->_vt, this); if (ret) throw RuntimeError("Failed to start node-type: {}", node_type_name(n->_vt)); } @@ -523,64 +523,3 @@ int SuperNode::periodic() return 0; } - - -/* C-compatability */ -extern "C" { - struct vlist * super_node_get_nodes(struct super_node *sn) - { - SuperNode *ssn = reinterpret_cast(sn); - - return ssn->getNodes(); - } - - struct vlist * super_node_get_paths(struct super_node *sn) - { - SuperNode *ssn = reinterpret_cast(sn); - - return ssn->getPaths(); - } - - struct vlist * super_node_get_interfaces(struct super_node *sn) - { - SuperNode *ssn = reinterpret_cast(sn); - - return ssn->getInterfaces(); - } -#ifdef WITH_WEB - struct web * super_node_get_web(struct super_node *sn) - { - SuperNode *ssn = reinterpret_cast(sn); - Web *w = ssn->getWeb(); - - return reinterpret_cast(w); - } -#endif - struct lws_context * web_get_context(struct web *w) - { - Web *ws = reinterpret_cast(w); - - return ws->getContext(); - } - - struct lws_vhost * web_get_vhost(struct web *w) - { - Web *ws = reinterpret_cast(w); - - return ws->getVHost(); - } - - enum state web_get_state(struct web *w) - { - Web *ws = reinterpret_cast(w); - - return ws->getState(); - } - -#ifdef WITH_WEB - int web_callback_on_writable(struct web *w, struct lws *wsi) - { - return lws_callback_on_writable(wsi); - } -#endif -} diff --git a/src/villas-pipe.cpp b/src/villas-pipe.cpp index dbf3f9ecd..ec29c7917 100644 --- a/src/villas-pipe.cpp +++ b/src/villas-pipe.cpp @@ -388,7 +388,7 @@ check: if (optarg == endptr) if (reverse) node_reverse(node); - ret = node_type_start(node_type(node), reinterpret_cast(&sn)); + ret = node_type_start(node_type(node), &sn); if (ret) throw RuntimeError("Failed to intialize node type {}: reason={}", node_type_name(node_type(node)), ret); diff --git a/src/villas-test-rtt.cpp b/src/villas-test-rtt.cpp index 1fc060205..be033d822 100644 --- a/src/villas-test-rtt.cpp +++ b/src/villas-test-rtt.cpp @@ -162,7 +162,7 @@ check: if (optarg == endptr) if (!node) throw RuntimeError("There's no node with the name '{}'", nodestr); - ret = node_type_start(node->_vt, reinterpret_cast(&sn)); + ret = node_type_start(node->_vt, &sn); if (ret) throw RuntimeError("Failed to start node-type {}: reason={}", node_type_name(node->_vt), ret);