2015-12-02 13:55:58 +01:00
|
|
|
/** Node type: WebSockets
|
|
|
|
*
|
|
|
|
* This file implements the websocket type for nodes.
|
|
|
|
* It's based on the libwebsockets library.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
|
|
|
*********************************************************************************/
|
|
|
|
|
2015-12-02 13:55:58 +01:00
|
|
|
/**
|
|
|
|
* @addtogroup websockets WebSockets node type
|
|
|
|
* @ingroup node
|
|
|
|
* @{
|
2017-03-03 20:20:13 -04:00
|
|
|
*/
|
2015-12-02 13:55:58 +01:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2015-12-02 13:55:58 +01:00
|
|
|
|
2016-11-08 00:24:57 -05:00
|
|
|
#include <libwebsockets.h>
|
|
|
|
|
2015-12-04 01:47:49 +01:00
|
|
|
#include "node.h"
|
2016-07-11 18:18:20 +02:00
|
|
|
#include "pool.h"
|
|
|
|
#include "queue.h"
|
2017-04-02 13:02:07 +02:00
|
|
|
#include "common.h"
|
2016-07-11 18:18:20 +02:00
|
|
|
|
|
|
|
/* Forward declaration */
|
|
|
|
struct lws;
|
2015-12-04 01:47:49 +01:00
|
|
|
|
2016-06-08 22:39:17 +02:00
|
|
|
/** Internal data per websocket node */
|
|
|
|
struct websocket {
|
2016-11-08 00:24:57 -05:00
|
|
|
struct list connections; /**< List of active libwebsocket connections in server mode (struct websocket_connection). */
|
|
|
|
struct list destinations; /**< List of websocket servers connect to in client mode (struct websocket_destination). */
|
2016-07-11 18:18:20 +02:00
|
|
|
|
|
|
|
struct pool pool;
|
2016-11-07 22:19:30 -05:00
|
|
|
struct queue queue; /**< For samples which are received from WebSockets a */
|
2015-12-02 13:55:58 +01:00
|
|
|
|
2016-06-08 22:39:17 +02:00
|
|
|
};
|
|
|
|
|
2017-03-29 06:01:50 +02:00
|
|
|
/* Internal datastructures */
|
2016-06-08 22:39:17 +02:00
|
|
|
struct websocket_connection {
|
|
|
|
struct node *node;
|
2016-07-11 18:18:20 +02:00
|
|
|
struct lws *wsi;
|
|
|
|
|
2017-03-29 06:01:50 +02:00
|
|
|
struct queue queue; /**< For samples which are sent to the WebSocket */
|
|
|
|
|
2016-07-11 18:18:20 +02:00
|
|
|
struct {
|
|
|
|
char name[64];
|
|
|
|
char ip[64];
|
|
|
|
} peer;
|
2017-03-05 10:06:32 -04:00
|
|
|
|
2017-04-02 13:02:07 +02:00
|
|
|
enum state state;
|
|
|
|
|
2017-03-05 10:06:32 -04:00
|
|
|
char *_name;
|
2015-12-02 13:55:58 +01:00
|
|
|
};
|
|
|
|
|
2017-03-29 06:01:50 +02:00
|
|
|
/* Internal datastructures */
|
|
|
|
struct websocket_destination {
|
|
|
|
char *uri;
|
|
|
|
struct lws_client_connect_info info;
|
|
|
|
};
|
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
|
|
|
|
|
2015-12-02 13:55:58 +01:00
|
|
|
/** @see node_vtable::init */
|
2017-03-13 00:04:56 -03:00
|
|
|
int websocket_init(int argc, char *argv[], config_setting_t *cfg);
|
2015-12-02 13:55:58 +01:00
|
|
|
|
|
|
|
/** @see node_vtable::deinit */
|
|
|
|
int websocket_deinit();
|
|
|
|
|
|
|
|
/** @see node_vtable::open */
|
2017-03-11 23:30:24 -03:00
|
|
|
int websocket_start(struct node *n);
|
2015-12-02 13:55:58 +01:00
|
|
|
|
|
|
|
/** @see node_vtable::close */
|
2017-03-11 23:30:24 -03:00
|
|
|
int websocket_stop(struct node *n);
|
2015-12-02 13:55:58 +01:00
|
|
|
|
2016-02-04 17:13:28 +01:00
|
|
|
/** @see node_vtable::close */
|
|
|
|
int websocket_destroy(struct node *n);
|
|
|
|
|
2015-12-02 13:55:58 +01:00
|
|
|
/** @see node_vtable::read */
|
2016-06-08 22:39:17 +02:00
|
|
|
int websocket_read(struct node *n, struct sample *smps[], unsigned cnt);
|
2015-12-02 13:55:58 +01:00
|
|
|
|
|
|
|
/** @see node_vtable::write */
|
2016-06-08 22:39:17 +02:00
|
|
|
int websocket_write(struct node *n, struct sample *smps[], unsigned cnt);
|
2015-12-02 13:55:58 +01:00
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
/** @} */
|