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

workaround for C-compatability

This commit is contained in:
Steffen Vogel 2018-12-02 02:56:52 +01:00
parent 47023f0c3e
commit caf3e45960
25 changed files with 127 additions and 40 deletions

View file

@ -37,6 +37,7 @@ extern "C" {
#include <villas/memory.h>
/* Forward declarations */
struct super_node;
struct node;
struct sample;
@ -222,7 +223,7 @@ struct node_type {
*
* @see node_type::init
*/
int node_type_start(struct node_type *vt);
int node_type_start(struct node_type *vt, struct super_node *sn);
/** De-initialize node type subsystems.
*

View file

@ -101,7 +101,7 @@ struct iec61850_receiver {
};
/** @see node_type::type_start */
int iec61850_type_start();
int iec61850_type_start(struct super_node *sn);
/** @see node_type::type_stop */
int iec61850_type_stop();

View file

@ -89,7 +89,7 @@ int mqtt_destroy(struct node *n);
int mqtt_stop(struct node *n);
/** @see node_type::type_start */
int mqtt_type_start();
int mqtt_type_start(struct super_node *sn);
/** @see node_type::type_stop */
int mqtt_type_stop();

View file

@ -72,7 +72,7 @@ struct ngsi {
*
* @see node_type::type_start
*/
int ngsi_type_start();
int ngsi_type_start(struct super_node *sn);
/** Free global NGSI settings and unmaps shared memory regions.
*

View file

@ -60,7 +60,7 @@ struct opal {
*
* @see node_type::type_start
*/
int opal_type_start();
int opal_type_start(struct super_node *sn);
/** Free global OPAL settings and unmaps shared memory regions.
*

View file

@ -111,7 +111,7 @@ struct socket {
/** @see node_vtable::type_start */
int socket_type_start();
int socket_type_start(struct super_node *sn);
/** @see node_type::type_stop */
int socket_type_stop();

View file

@ -40,6 +40,7 @@ extern "C" {
/* Forward declarations */
struct node;
struct sample;
struct super_node;
struct stats_node {
double rate;
@ -51,7 +52,7 @@ struct stats_node {
};
/** @see node_type::print */
int stats_node_type_start();
int stats_node_type_start(struct super_node *sn);
/** @see node_type::print */
char *stats_node_print(struct node *n);

View file

@ -96,7 +96,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(); /// @todo: Port to C++
int websocket_type_start(struct super_node *sn);
/** @see node_type::type_stop */
int websocket_type_stop();

View file

@ -91,7 +91,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();
int zeromq_type_start(struct super_node *sn);
/** @see node_type::type_stop */
int zeromq_type_stop();

View file

@ -0,0 +1,37 @@
/** The super node object holding the state of the application (C-compatability header).
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017-2018, 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/>.
*********************************************************************************/
struct list;
struct super_node;
struct list * super_node_get_nodes(struct super_node *sn);
struct list * super_node_get_nodes(struct super_node *sn);
struct lws_context * super_node_get_web_context(struct super_node *sn);
struct lws_vhost * super_node_get_web_vhost(struct super_node *sn);
enum state super_node_get_web_state(struct super_node *sn);
int super_node_get_cli_argc(struct super_node *sn);

View file

@ -82,6 +82,22 @@ public:
return api;
}
/* for C-compatability */
lws_context * getContext()
{
return context;
}
lws_vhost * getVHost()
{
return vhost;
}
enum state getState() const
{
return state;
}
void callbackOnWritable(struct lws *wsi);
};

View file

@ -28,7 +28,7 @@
#include <villas/node/config.h>
#include <villas/plugin.h>
int node_type_start(struct node_type *vt)
int node_type_start(struct node_type *vt, struct super_node *sn)
{
int ret;
@ -37,7 +37,7 @@ int node_type_start(struct node_type *vt)
info("Initializing " CLR_YEL("%s") " node type which is used by %zu nodes", node_type_name(vt), list_length(&vt->instances));
ret = vt->type.start ? vt->type.start() : 0; // @todo: port to C++
ret = vt->type.start ? vt->type.start(sn) : 0;
if (ret == 0)
vt->state = STATE_STARTED;

View file

@ -22,8 +22,7 @@
set(NODE_SRC
influxdb.c
# @todo: Port to C++
# stats.c
stats.c
signal_generator.c
loopback.c
)

View file

@ -157,7 +157,7 @@ int iec61850_parse_signals(json_t *json_signals, struct list *signals, struct li
return total_size;
}
int iec61850_type_start()
int iec61850_type_start(struct super_node *sn)
{
int ret;

View file

@ -346,7 +346,7 @@ int mqtt_stop(struct node *n)
return 0;
}
int mqtt_type_start()
int mqtt_type_start(struct super_node *sn)
{
int ret;

View file

@ -389,7 +389,7 @@ out: json_decref(request);
return ret;
}
int ngsi_type_start()
int ngsi_type_start(struct super_node *sn)
{
return curl_global_init(CURL_GLOBAL_ALL);
}

View file

@ -48,7 +48,7 @@ int opal_register_region(int argc, char *argv[])
print_shmem_name = argv[3];
}
int opal_type_start() /// @todo: Port to C++
int opal_type_start(struct super_node *sn)
{
int err;

View file

@ -53,7 +53,7 @@ static struct plugin p;
/* Private static storage */
struct list interfaces = { .state = STATE_DESTROYED };
int socket_type_start()
int socket_type_start(struct super_node *sn)
{
#ifdef WITH_NETEM
int ret;
@ -454,7 +454,6 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *r
}
ret = io_sscan(&s->io, ptr, bytes, &rbytes, smps, cnt);
if (ret < 0 || bytes != rbytes)
warning("Received invalid packet from node: %s ret=%d, bytes=%zu, rbytes=%zu", node_name(n), ret, bytes, rbytes);

View file

@ -30,7 +30,7 @@
#include <villas/hook.h>
#include <villas/plugin.h>
#include <villas/stats.h>
#include <villas/super_node.hpp>
#include <villas/super_node.h>
#include <villas/sample.h>
#include <villas/node.h>
@ -89,11 +89,11 @@ static void stats_init_signals(struct node *n)
}
}
int stats_node_type_start() /// @todo: Port to C++
int stats_node_type_start(struct super_node *sn)
{
nodes = NULL;
nodes = super_node_get_nodes(sn);
return -1;
return 0;
}
int stats_node_start(struct node *n)

View file

@ -35,14 +35,16 @@
#include <villas/nodes/websocket.h>
#include <villas/format_type.h>
#include <villas/formats/msg_format.h>
#include <villas/super_node.h>
#define DEFAULT_WEBSOCKET_BUFFER_SIZE (1 << 12)
/* Private static storage */
static struct list connections = { .state = STATE_DESTROYED }; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */
// TODO: port to C++
// @todo: port to C++
//static struct web *web;
static struct super_node *sn;
/* Forward declarations */
static struct plugin p;
@ -164,8 +166,9 @@ static int websocket_connection_write(struct websocket_connection *c, struct sam
debug(LOG_WEBSOCKET | 10, "Enqueued %u samples to %s", pushed, websocket_connection_name(c));
/* Client connections which are currently conecting don't have an associate c->wsi yet */
if (c->wsi)
web_callback_on_writable(c->wsi);
// @todo: port to C++
//if (c->wsi)
// web_callback_on_writable(c->wsi);
return 0;
}
@ -370,17 +373,17 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
return 0;
}
int websocket_type_start() // @todo: Port to C++
int websocket_type_start(struct super_node *ssn)
{
list_init(&connections);
//web = NULL; /// @todo: Port to C++ &sn->web;
sn = ssn;
return -1;
info("web state: %d", super_node_get_web_state(sn));
// @todo: Port to C++
//if (web->state != STATE_STARTED)
// return -1;
if (super_node_get_web_state(sn) != STATE_STARTED)
return -1;
return 0;
}
@ -416,9 +419,8 @@ int websocket_start(struct node *n)
c->node = n;
c->destination = d;
// @todo: Port to C++
//d->info.context = web->context;
//d->info.vhost = web->vhost;
d->info.context = super_node_get_web_context(sn);
d->info.vhost = super_node_get_web_vhost(sn);
d->info.userdata = c;
lws_client_connect_via_info(&d->info);

View file

@ -240,7 +240,7 @@ char * zeromq_print(struct node *n)
return buf;
}
int zeromq_type_start() /// @todo: Port to C++
int zeromq_type_start(struct super_node *sn)
{
context = zmq_ctx_new();

View file

@ -338,7 +338,7 @@ int SuperNode::start()
for (size_t i = 0; i < list_length(&nodes); i++) {
auto *n = (struct node *) list_at(&nodes, i);
ret = node_type_start(n->_vt);//, this); // @todo: port to C++
ret = node_type_start(n->_vt, reinterpret_cast<super_node *>(this));
if (ret)
throw new RuntimeError("Failed to start node-type: {}", node_type_name(n->_vt));
}
@ -515,3 +515,35 @@ int SuperNode::periodic()
#endif
return 0;
}
/* C-compatability */
extern "C" {
struct list * super_node_get_nodes(struct super_node *sn)
{
SuperNode *ssn = reinterpret_cast<SuperNode *>(sn);
return ssn->getNodes();
}
struct lws_context * super_node_get_web_context(struct super_node *sn)
{
SuperNode *ssn = reinterpret_cast<SuperNode *>(sn);
return ssn->getWeb()->getContext();
}
struct lws_vhost * super_node_get_web_vhost(struct super_node *sn)
{
SuperNode *ssn = reinterpret_cast<SuperNode *>(sn);
return ssn->getWeb()->getVHost();
}
enum state super_node_get_web_state(struct super_node *sn)
{
SuperNode *ssn = reinterpret_cast<SuperNode *>(sn);
return ssn->getWeb()->getState();
}
}

View file

@ -373,7 +373,7 @@ check: if (optarg == endptr)
if (reverse)
node_reverse(node);
ret = node_type_start(node->_vt);//, &sn); // @todo: port to C++
ret = node_type_start(node->_vt, reinterpret_cast<super_node *>(&sn));
if (ret)
throw new RuntimeError("Failed to intialize node type {}: reason={}", node_type_name(node->_vt), ret);
@ -419,7 +419,7 @@ check: if (optarg == endptr)
if (ret)
throw new RuntimeError("Failed to stop node {}: reason={}", node_name(node), ret);
ret = node_type_stop(node->_vt);//, &sn); // @todo: port to C++
ret = node_type_stop(node->_vt);
if (ret)
throw new RuntimeError("Failed to stop node type {}: reason={}", node_type_name(node->_vt), ret);

View file

@ -209,7 +209,7 @@ int main(int argc, char *argv[])
}
// nt == n._vt
ret = node_type_start(nt); /// @todo: Port to C++
ret = node_type_start(nt, nullptr);
if (ret)
throw new RuntimeError("Failed to initialize node type: {}", node_type_name(nt));

View file

@ -162,7 +162,7 @@ check: if (optarg == endptr)
if (!node)
throw new RuntimeError("There's no node with the name '{}'", nodestr);
ret = node_type_start(node->_vt);//, &sn); // @todo: port to C++
ret = node_type_start(node->_vt, reinterpret_cast<super_node *>(&sn));
if (ret)
throw new RuntimeError("Failed to start node-type {}: reason={}", node_type_name(node->_vt), ret);