1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/nodes/websocket.h

109 lines
2.9 KiB
C
Raw Permalink Normal View History

/** 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>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @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.
*
2017-04-27 12:56:43 +02:00
* 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.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
/**
* @addtogroup websockets WebSockets node type
* @ingroup node
* @{
*/
2017-02-16 09:04:12 -03:00
#pragma once
#include <libwebsockets.h>
#include "node.h"
#include "pool.h"
2017-04-07 12:25:17 +02:00
#include "queue_signalled.h"
#include "common.h"
#include "config.h"
#define DEFAULT_WEBSOCKET_QUEUELEN (DEFAULT_QUEUELEN * 64)
#define DEFAULT_WEBSOCKET_SAMPLELEN DEFAULT_SAMPLELEN
/* Forward declaration */
struct lws;
/** Internal data per websocket node */
struct websocket {
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). */
struct pool pool;
2017-04-18 17:58:23 +02:00
struct queue_signalled queue; /**< For samples which are received from WebSockets */
};
/* Internal datastructures */
struct websocket_connection {
struct node *node;
struct lws *wsi;
struct queue queue; /**< For samples which are sent to the WebSocket */
struct {
char name[64];
char ip[64];
} peer;
enum {
WEBSOCKET_MODE_CLIENT,
WEBSOCKET_MODE_SERVER,
} mode;
enum state state;
char *_name;
};
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);
/** @see node_vtable::init */
int websocket_init(struct super_node *sn);
2017-04-18 17:58:23 +02:00
/** @see node_type::deinit */
int websocket_deinit();
2017-04-18 17:58:23 +02:00
/** @see node_type::open */
int websocket_start(struct node *n);
2017-04-18 17:58:23 +02:00
/** @see node_type::close */
int websocket_stop(struct node *n);
2017-04-18 17:58:23 +02:00
/** @see node_type::close */
int websocket_destroy(struct node *n);
2017-04-18 17:58:23 +02:00
/** @see node_type::read */
int websocket_read(struct node *n, struct sample *smps[], unsigned cnt);
2017-04-18 17:58:23 +02:00
/** @see node_type::write */
int websocket_write(struct node *n, struct sample *smps[], unsigned cnt);
2017-04-07 12:25:17 +02:00
/** @} */