diff --git a/include/villas/super_node.h b/include/villas/super_node.h index f6c89536e..1e49004f0 100644 --- a/include/villas/super_node.h +++ b/include/villas/super_node.h @@ -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); diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index 6e1853c7c..997477ebe 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -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); diff --git a/lib/super_node.cpp b/lib/super_node.cpp index 9be8b9cdb..424be11b1 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -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(sn); + Web *w = ssn->getWeb(); - return ssn->getWeb()->getContext(); + return reinterpret_cast(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(sn); + Web *ws = reinterpret_cast(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(sn); + Web *ws = reinterpret_cast(w); - return ssn->getWeb()->getState(); + return ws->getVHost(); + } + + enum state web_get_state(struct web *w) + { + Web *ws = reinterpret_cast(w); + + return ws->getState(); + } + + int web_callback_on_writable(struct web *w, struct lws *wsi) + { + return lws_callback_on_writable(wsi); } }