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

websocket: add workaround for C++ port

This commit is contained in:
Steffen Vogel 2019-01-12 19:05:09 +01:00
parent 918c99881c
commit 8052b15377
3 changed files with 42 additions and 27 deletions

View file

@ -22,16 +22,22 @@
*********************************************************************************/
struct vlist;
struct web;
struct super_node;
struct lws;
struct vlist * super_node_get_nodes(struct super_node *sn);
struct vlist * 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);
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);
int web_callback_on_writable(struct web *w, struct lws *wsi);

View file

@ -42,9 +42,7 @@
/* Private static storage */
static struct vlist connections = { .state = STATE_DESTROYED }; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */
// @todo: port to C++
//static struct web *web;
static struct super_node *sn;
static struct web *web;
/* Forward declarations */
static struct plugin p;
@ -166,9 +164,8 @@ 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 */
// @todo: port to C++
//if (c->wsi)
// web_callback_on_writable(c->wsi);
if (c->wsi)
web_callback_on_writable(web, c->wsi);
return 0;
}
@ -373,16 +370,15 @@ int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
return 0;
}
int websocket_type_start(struct super_node *ssn)
int websocket_type_start(struct super_node *sn)
{
vlist_init(&connections);
//web = NULL; /// @todo: Port to C++ &sn->web;
sn = ssn;
web = super_node_get_web(sn);
info("web state: %d", super_node_get_web_state(sn));
info("web state: %d", web_get_state(web));
if (super_node_get_web_state(sn) != STATE_STARTED)
if (web_get_state(web) != STATE_STARTED)
return -1;
return 0;
@ -419,8 +415,8 @@ int websocket_start(struct node *n)
c->node = n;
c->destination = d;
d->info.context = super_node_get_web_context(sn);
d->info.vhost = super_node_get_web_vhost(sn);
d->info.context = web_get_context(web);
d->info.vhost = web_get_vhost(web);
d->info.userdata = c;
lws_client_connect_via_info(&d->info);

View file

@ -530,24 +530,37 @@ extern "C" {
return ssn->getNodes();
}
struct lws_context * super_node_get_web_context(struct super_node *sn)
struct web * super_node_get_web(struct super_node *sn)
{
SuperNode *ssn = reinterpret_cast<SuperNode *>(sn);
Web *w = ssn->getWeb();
return ssn->getWeb()->getContext();
return reinterpret_cast<web *>(w);
}
struct lws_vhost * super_node_get_web_vhost(struct super_node *sn)
struct lws_context * web_get_context(struct web *w)
{
SuperNode *ssn = reinterpret_cast<SuperNode *>(sn);
Web *ws = reinterpret_cast<Web *>(w);
return ssn->getWeb()->getVHost();
return ws->getContext();
}
enum state super_node_get_web_state(struct super_node *sn)
struct lws_vhost * web_get_vhost(struct web *w)
{
SuperNode *ssn = reinterpret_cast<SuperNode *>(sn);
Web *ws = reinterpret_cast<Web *>(w);
return ssn->getWeb()->getState();
return ws->getVHost();
}
enum state web_get_state(struct web *w)
{
Web *ws = reinterpret_cast<Web *>(w);
return ws->getState();
}
int web_callback_on_writable(struct web *w, struct lws *wsi)
{
return lws_callback_on_writable(wsi);
}
}