2018-12-28 17:55:49 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// util
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <utils/settings.h>
|
|
|
|
|
|
|
|
// qt
|
|
|
|
#include <QVector>
|
|
|
|
|
2020-09-07 21:34:14 +02:00
|
|
|
class BonjourServiceRegister;
|
2018-12-28 17:55:49 +01:00
|
|
|
class QTcpServer;
|
|
|
|
class FlatBufferClient;
|
2019-07-12 16:54:26 +02:00
|
|
|
class NetOrigin;
|
|
|
|
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief A TcpServer to receive images of different formats with Google Flatbuffer
|
|
|
|
/// Images will be forwarded to all Hyperion instances
|
|
|
|
///
|
|
|
|
class FlatBufferServer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
FlatBufferServer(const QJsonDocument& config, QObject* parent = nullptr);
|
2020-08-08 23:12:43 +02:00
|
|
|
~FlatBufferServer() override;
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
///
|
|
|
|
/// @brief Handle settings update
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @param type The type from enum
|
|
|
|
/// @param config The configuration
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
void initServer();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// @brief Is called whenever a new socket wants to connect
|
|
|
|
///
|
|
|
|
void newConnection();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief is called whenever a client disconnected
|
|
|
|
///
|
|
|
|
void clientDisconnected();
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
/// @brief Start the server with current _port
|
|
|
|
///
|
|
|
|
void startServer();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Stop server
|
|
|
|
///
|
|
|
|
void stopServer();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
QTcpServer* _server;
|
2019-07-12 16:54:26 +02:00
|
|
|
NetOrigin* _netOrigin;
|
2018-12-28 17:55:49 +01:00
|
|
|
Logger* _log;
|
|
|
|
int _timeout;
|
|
|
|
quint16 _port;
|
|
|
|
const QJsonDocument _config;
|
2020-09-07 21:34:14 +02:00
|
|
|
BonjourServiceRegister * _serviceRegister = nullptr;
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
QVector<FlatBufferClient*> _openConnections;
|
|
|
|
};
|