2013-10-11 10:06:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// system includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QSet>
|
2016-02-15 18:25:18 +01:00
|
|
|
#include <QList>
|
2016-02-08 16:56:23 +01:00
|
|
|
#include <QStringList>
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <QJsonDocument>
|
2013-10-11 10:06:24 +02:00
|
|
|
|
2016-02-16 15:41:40 +01:00
|
|
|
// hyperion includes
|
|
|
|
#include <utils/Image.h>
|
|
|
|
#include <utils/ColorRgb.h>
|
2016-06-07 23:12:18 +02:00
|
|
|
#include <utils/VideoMode.h>
|
2016-07-11 17:08:22 +02:00
|
|
|
#include <utils/Logger.h>
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <utils/Components.h>
|
|
|
|
|
|
|
|
// settings
|
|
|
|
#include <utils/settings.h>
|
2016-02-16 15:41:40 +01:00
|
|
|
|
2016-02-15 18:25:18 +01:00
|
|
|
// forward decl
|
2013-10-11 10:06:24 +02:00
|
|
|
class ProtoClientConnection;
|
2016-02-15 18:25:18 +01:00
|
|
|
class ProtoConnection;
|
2018-12-27 23:11:32 +01:00
|
|
|
class QTcpServer;
|
|
|
|
class Hyperion;
|
|
|
|
class BonjourServiceRegister;
|
|
|
|
class ComponentRegister;
|
|
|
|
class NetOrigin;
|
2016-02-15 18:25:18 +01:00
|
|
|
|
|
|
|
namespace proto {
|
|
|
|
class HyperionRequest;
|
|
|
|
}
|
2013-10-11 10:06:24 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// This class creates a TCP server which accepts connections wich can then send
|
|
|
|
/// in Protocol Buffer encoded commands. This interface to Hyperion is used by
|
|
|
|
/// hyperion-remote to control the leds
|
|
|
|
///
|
|
|
|
class ProtoServer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// ProtoServer constructor
|
2018-12-27 23:11:32 +01:00
|
|
|
/// @param config the configuration
|
2013-10-11 10:06:24 +02:00
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
ProtoServer(const QJsonDocument& config);
|
2013-10-11 10:06:24 +02:00
|
|
|
~ProtoServer();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @return the port number on which this TCP listens for incoming connections
|
|
|
|
///
|
|
|
|
uint16_t getPort() const;
|
|
|
|
|
2016-02-16 15:41:40 +01:00
|
|
|
public slots:
|
|
|
|
void sendImageToProtoSlaves(int priority, const Image<ColorRgb> & image, int duration_ms);
|
2016-08-11 07:13:55 +02:00
|
|
|
void componentStateChanged(const hyperion::Components component, bool enable);
|
2016-02-16 15:41:40 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Handle settings update from Hyperion Settingsmanager emit or this constructor
|
|
|
|
/// @param type settingyType from enum
|
|
|
|
/// @param config configuration object
|
|
|
|
///
|
|
|
|
void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
|
|
|
|
|
2016-06-07 23:12:18 +02:00
|
|
|
signals:
|
|
|
|
///
|
2017-11-22 00:52:55 +01:00
|
|
|
/// Forwarding videoMode
|
2016-06-07 23:12:18 +02:00
|
|
|
///
|
|
|
|
void videoMode(const VideoMode VideoMode);
|
|
|
|
|
2013-10-11 10:06:24 +02:00
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// Slot which is called when a client tries to create a new connection
|
|
|
|
///
|
|
|
|
void newConnection();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Slot which is called when a client closes a connection
|
|
|
|
/// @param connection The Connection object which is being closed
|
|
|
|
///
|
|
|
|
void closedConnection(ProtoClientConnection * connection);
|
|
|
|
|
2016-02-15 18:25:18 +01:00
|
|
|
void newMessage(const proto::HyperionRequest * message);
|
|
|
|
|
2013-10-11 10:06:24 +02:00
|
|
|
private:
|
|
|
|
/// Hyperion instance
|
|
|
|
Hyperion * _hyperion;
|
|
|
|
|
|
|
|
/// The TCP server object
|
2018-12-27 23:11:32 +01:00
|
|
|
QTcpServer * _server;
|
2013-10-11 10:06:24 +02:00
|
|
|
|
|
|
|
/// List with open connections
|
|
|
|
QSet<ProtoClientConnection *> _openConnections;
|
2016-02-08 16:56:23 +01:00
|
|
|
QStringList _forwardClients;
|
2016-02-15 18:25:18 +01:00
|
|
|
|
|
|
|
/// Hyperion proto connection object for forwarding
|
|
|
|
QList<ProtoConnection*> _proxy_connections;
|
2016-08-11 07:13:55 +02:00
|
|
|
|
|
|
|
/// Logger instance
|
2016-07-11 17:08:22 +02:00
|
|
|
Logger * _log;
|
2017-11-22 00:52:55 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Component Register
|
|
|
|
ComponentRegister* _componentRegister;
|
|
|
|
|
|
|
|
/// Network Origin Check
|
|
|
|
NetOrigin* _netOrigin;
|
|
|
|
|
|
|
|
/// Service register
|
|
|
|
BonjourServiceRegister * _serviceRegister = nullptr;
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
/// flag if forwarder is enabled
|
|
|
|
bool _forwarder_enabled;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
uint16_t _port = 0;
|
|
|
|
|
|
|
|
/// Start server
|
|
|
|
void start();
|
|
|
|
/// Stop server
|
|
|
|
void stop();
|
2013-10-11 10:06:24 +02:00
|
|
|
};
|