50 lines
1.2 KiB
C++
Executable File
50 lines
1.2 KiB
C++
Executable File
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QtWebSockets/QWebSocketServer>
|
|
#include "building_control_handler.h"
|
|
#include "logger.h"
|
|
|
|
|
|
|
|
namespace Buildings
|
|
{
|
|
|
|
class WebSocketHandler final: public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit WebSocketHandler(const std::shared_ptr<BuildingControlHandler> &buildingControlHandler, QObject *parent = nullptr);
|
|
~WebSocketHandler();
|
|
|
|
bool init(quint16 listenPort = 0);
|
|
bool init(const QPair<quint16, quint16> &portRange);
|
|
bool isConnected() const { return !m_webSockets.isEmpty(); }
|
|
quint16 listenPort() const { return m_webSocketServer->serverPort(); }
|
|
bool sendPosition();
|
|
|
|
private:
|
|
NGL::INGLLogger &m_logger;
|
|
bool sendTelegramInternal() const;
|
|
bool sendbuildingInfos() const;
|
|
QJsonObject ObjectFromString(const QString& in);
|
|
void triggerFlashlight(const QString &message);
|
|
|
|
private Q_SLOTS:
|
|
void onNewMessage(const QString &message);
|
|
void onNewConnection();
|
|
void onWebSocketDisconnected();
|
|
|
|
private:
|
|
NGL::INGLLogger &m_logger;
|
|
std::shared_ptr<BuildingControlHandler> m_buildingControlHandler;
|
|
QWebSocketServer* m_webSocketServer = nullptr;
|
|
QVector<QWebSocket*> m_webSockets;
|
|
};
|
|
|
|
}
|