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

111 lines
2.3 KiB
C++
Raw Normal View History

/** API session.
*
* @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
2020-08-17 17:03:54 +02:00
#include <atomic>
#include <jansson.h>
2017-12-09 02:19:28 +08:00
#include <villas/queue.h>
2018-10-20 14:20:06 +02:00
#include <villas/json_buffer.hpp>
#include <villas/api.hpp>
2018-10-20 14:20:06 +02:00
namespace villas {
namespace node {
2018-10-20 14:20:06 +02:00
/* Forward declarations */
class SuperNode;
class Api;
2020-08-17 17:03:54 +02:00
class Web;
2018-10-20 14:20:06 +02:00
namespace api {
2020-08-17 17:03:54 +02:00
/* Forward declarations */
class Request;
class Response;
/** A connection via HTTP REST or WebSockets to issue API requests. */
2018-10-20 14:20:06 +02:00
class Session {
public:
enum State {
ESTABLISHED,
SHUTDOWN
};
enum Version {
2020-08-17 17:03:54 +02:00
UNKNOWN_VERSION = 0,
VERSION_1 = 1,
VERSION_2 = 2
2018-10-20 14:20:06 +02:00
};
protected:
enum State state;
enum Version version;
2020-08-17 17:03:54 +02:00
lws *wsi;
2020-08-17 17:03:54 +02:00
Web *web;
2018-10-20 14:20:06 +02:00
Api *api;
2017-12-09 02:19:28 +08:00
2020-08-17 17:03:54 +02:00
Logger logger;
2018-10-20 14:20:06 +02:00
2020-08-17 17:03:54 +02:00
JsonBuffer requestBuffer;
JsonBuffer responseBuffer;
2020-08-17 17:03:54 +02:00
std::atomic<Request *> request;
std::atomic<Response *> response;
2020-08-17 17:03:54 +02:00
bool headersSent;
2020-08-17 17:03:54 +02:00
public:
Session(struct lws *w);
~Session();
std::string getName() const;
2020-08-17 17:03:54 +02:00
SuperNode * getSuperNode() const
2018-10-20 14:20:06 +02:00
{
return api->getSuperNode();
}
2020-08-17 17:03:54 +02:00
void open(void *in, size_t len);
int writeable();
void body(void *in, size_t len);
void bodyComplete();
void execute();
void shutdown();
static int protocolCallback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
int getRequestMethod(struct lws *wsi);
static std::string methodToString(int meth);
2018-10-20 14:20:06 +02:00
};
2020-07-08 13:43:15 +02:00
} /* namespace api */
} /* namespace node */
} /* namespace villas */