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

106 lines
2.5 KiB
C++
Raw Permalink Normal View History

/** LWS-releated functions.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, 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/>.
*********************************************************************************/
#pragma once
2018-10-20 14:20:06 +02:00
#include <atomic>
#include <thread>
2017-04-07 17:39:37 +02:00
2018-07-03 21:51:48 +02:00
#include <jansson.h>
2018-10-20 14:20:06 +02:00
#include <villas/log.hpp>
2020-03-04 12:41:55 +01:00
#include <villas/common.hpp>
2018-10-20 14:20:06 +02:00
#include <villas/queue.hpp>
2018-10-20 14:20:06 +02:00
namespace villas {
namespace node {
/* Forward declarations */
2018-10-20 14:20:06 +02:00
class Api;
2018-10-20 14:20:06 +02:00
class Web {
2018-10-20 14:20:06 +02:00
protected:
2019-06-23 16:13:23 +02:00
enum State state;
2019-01-17 20:28:20 +01:00
Logger logger;
2018-10-20 14:20:06 +02:00
lws_context *context; /**< The libwebsockets server context. */
lws_vhost *vhost; /**< The libwebsockets vhost. */
Queue<lws *> writables; /**< Queue of WSIs for which we will call lws_callback_on_writable() */
2018-06-29 08:37:14 +02:00
int port; /**< Port of the build in HTTP / WebSocket server. */
2018-10-20 14:20:06 +02:00
std::string htdocs; /**< The root directory for files served via HTTP. */
std::string ssl_cert; /**< Path to the SSL certitifcate for HTTPS / WSS. */
std::string ssl_private_key; /**< Path to the SSL private key for HTTPS / WSS. */
2018-10-20 14:20:06 +02:00
std::thread thread;
std::atomic<bool> running; /**< Atomic flag for signalizing thread termination. */
2018-10-20 14:20:06 +02:00
Api *api;
2018-10-20 14:20:06 +02:00
void worker();
static void lwsLogger(int level, const char *msg);
2018-10-20 14:20:06 +02:00
public:
2018-10-20 14:20:06 +02:00
/** Initialize the web interface.
*
* The web interface is based on the libwebsockets library.
*/
Web(Api *a = nullptr);
2018-10-20 14:20:06 +02:00
void start();
void stop();
2018-10-20 14:20:06 +02:00
/** Parse HTTPd and WebSocket related options */
int parse(json_t *cfg);
Api * getApi()
{
return api;
}
2018-12-02 02:56:52 +01:00
/* for C-compatability */
lws_context * getContext()
{
return context;
}
lws_vhost * getVHost()
{
return vhost;
}
2019-06-23 16:13:23 +02:00
enum State getState() const
2018-12-02 02:56:52 +01:00
{
return state;
}
2018-10-20 14:20:06 +02:00
void callbackOnWritable(struct lws *wsi);
};
2020-06-15 22:16:38 +02:00
} /* namespace node */
} /* namespace villas */