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/api/session.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
1.8 KiB
C++
Raw Permalink Normal View History

/* API session.
*
* Author: Steffen Vogel <post@steffenvogel.de>
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <jansson.h>
2018-10-20 14:20:06 +02:00
#include <villas/api.hpp>
#include <villas/buffer.hpp>
#include <villas/queue.h>
2018-10-20 14:20:06 +02:00
namespace villas {
namespace node {
// Forward declarations
2018-10-20 14:20:06 +02:00
class SuperNode;
class Api;
2020-08-17 17:03:54 +02:00
class Web;
2018-10-20 14:20:06 +02:00
namespace api {
// Forward declarations
2020-08-17 17:03:54 +02:00
class Request;
class Response;
2020-10-16 11:43:24 +02:00
class StatusRequest;
2021-02-16 14:15:14 +01:00
class RequestFactory;
2020-08-17 17:03:54 +02:00
// A connection via HTTP REST or WebSockets to issue API requests.
2018-10-20 14:20:06 +02:00
class Session {
public:
friend Request; // Requires access to wsi for getting URL args and headers
friend StatusRequest; // Requires access to wsi for context status
friend RequestFactory;
enum State { ESTABLISHED, SHUTDOWN };
enum Version { UNKNOWN_VERSION = 0, VERSION_1 = 1, VERSION_2 = 2 };
enum Method { UNKNOWN, GET, POST, DELETE, OPTIONS, PUT, PATCH };
2018-10-20 14:20:06 +02:00
protected:
enum State state;
enum Version version;
lws *wsi;
Web *web;
Api *api;
2017-12-09 02:19:28 +08:00
Logger logger;
2018-10-20 14:20:06 +02:00
std::unique_ptr<Request> request;
std::unique_ptr<Response> response;
bool headersSent;
2020-08-17 17:03:54 +02:00
public:
Session(struct lws *w);
~Session();
2020-08-17 17:03:54 +02:00
std::string getName() const;
SuperNode *getSuperNode() const { return api->getSuperNode(); }
2018-10-20 14:20:06 +02:00
void open(void *in, size_t len);
int writeable();
void body(void *in, size_t len);
void bodyComplete();
void execute();
void shutdown();
2020-08-17 17:03:54 +02:00
static int protocolCallback(struct lws *wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len);
2020-08-17 17:03:54 +02:00
Method getRequestMethod() const;
2020-08-17 17:03:54 +02:00
static std::string methodToString(Method meth);
2018-10-20 14:20:06 +02:00
};
} // namespace api
} // namespace node
} // namespace villas