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>
|
2016-02-09 05:33:19 +01:00
|
|
|
* @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC
|
2016-06-08 23:21:42 +02:00
|
|
|
* This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential.
|
2015-12-02 13:55:58 +01:00
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @addtogroup websockets WebSockets node type
|
|
|
|
* @ingroup node
|
|
|
|
* @{
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WEBSOCKET_H_
|
|
|
|
#define _WEBSOCKET_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"
|
|
|
|
|
|
|
|
/* 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-07-11 18:18:20 +02:00
|
|
|
struct list connections; /**< List of active libwebsocket connections in server mode (struct websocket_connection) */
|
2016-11-07 22:19:30 -05:00
|
|
|
|
2016-07-11 18:18:20 +02:00
|
|
|
struct list destinations; /**< List of struct lws_client_connect_info to connect to in client mode. */
|
|
|
|
|
|
|
|
struct pool pool;
|
2015-12-02 13:55:58 +01:00
|
|
|
|
2016-11-07 22:19:30 -05:00
|
|
|
struct queue queue; /**< For samples which are received from WebSockets a */
|
|
|
|
|
|
|
|
int id; /**< The index of this node */
|
2016-06-08 22:39:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct websocket_connection {
|
2016-07-11 18:18:20 +02:00
|
|
|
enum {
|
|
|
|
WEBSOCKET_ESTABLISHED,
|
|
|
|
WEBSOCKET_ACTIVE,
|
2016-11-07 22:19:30 -05:00
|
|
|
WEBSOCKET_SHUTDOWN,
|
2016-07-11 18:18:20 +02:00
|
|
|
WEBSOCKET_CLOSED
|
|
|
|
} state;
|
|
|
|
|
2016-06-08 22:39:17 +02:00
|
|
|
struct node *node;
|
|
|
|
struct path *path;
|
|
|
|
|
2016-11-07 22:19:30 -05:00
|
|
|
struct queue queue; /**< For samples which are sent to the WebSocket */
|
|
|
|
|
2016-07-11 18:18:20 +02:00
|
|
|
struct lws *wsi;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char name[64];
|
|
|
|
char ip[64];
|
|
|
|
} peer;
|
2015-12-02 13:55:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @see node_vtable::init */
|
2015-12-11 12:35:32 +01: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 */
|
|
|
|
int websocket_open(struct node *n);
|
|
|
|
|
|
|
|
/** @see node_vtable::close */
|
|
|
|
int websocket_close(struct node *n);
|
|
|
|
|
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
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
#endif /** _WEBSOCKET_H_ @} */
|