54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QHttpServer>
|
|
|
|
#include <unordered_map>
|
|
#include <set>
|
|
#include <memory>
|
|
|
|
#ifdef FEATURE_REDIS
|
|
#include <hiredis/async.h>
|
|
#endif
|
|
|
|
class QWebSocket;
|
|
class Client;
|
|
|
|
class WebServer : public QObject
|
|
{
|
|
Q_OBJECT
|
|
friend class Client;
|
|
|
|
public:
|
|
explicit WebServer(const QString &identity,
|
|
#ifdef FEATURE_REDIS
|
|
redisAsyncContext *redis,
|
|
#endif
|
|
QObject *parent = nullptr);
|
|
~WebServer() override;
|
|
|
|
bool bind(QTcpServer *server);
|
|
|
|
private slots:
|
|
void newWebSocketConnection();
|
|
|
|
private:
|
|
#ifdef FEATURE_REDIS
|
|
void createTraefikRoute(const QString &serial);
|
|
void destroyTraefikRoute(const QString &serial);
|
|
#endif
|
|
|
|
QHttpServerWebSocketUpgradeResponse verifySocketUpgrade(const QHttpServerRequest &request);
|
|
void newWebSocketConnection(std::unique_ptr<QWebSocket> &&socket);
|
|
|
|
QHttpServer m_server;
|
|
|
|
QString m_identity;
|
|
|
|
std::unordered_map<QString, std::set<std::unique_ptr<Client>>> m_clients;
|
|
|
|
#ifdef FEATURE_REDIS
|
|
redisAsyncContext *m_redis;
|
|
#endif
|
|
};
|