2016-06-20 08:38:12 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// system includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QSet>
|
2016-06-27 09:27:11 +02:00
|
|
|
#include <QHostAddress>
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <QJsonDocument>
|
2016-06-20 08:38:12 +02:00
|
|
|
|
|
|
|
// Hyperion includes
|
2016-06-25 15:15:23 +02:00
|
|
|
#include <utils/Logger.h>
|
2016-08-11 07:13:55 +02:00
|
|
|
#include <utils/Components.h>
|
2018-12-28 18:12:45 +01:00
|
|
|
#include <utils/ColorRgb.h>
|
2016-06-20 08:38:12 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// settings
|
|
|
|
#include <utils/settings.h>
|
|
|
|
|
|
|
|
class BonjourServiceRegister;
|
|
|
|
class QUdpSocket;
|
2016-06-20 08:38:12 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// This class creates a UDP server which accepts connections from boblight clients.
|
|
|
|
///
|
|
|
|
class UDPListener : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// UDPListener constructor
|
|
|
|
/// @param hyperion Hyperion instance
|
|
|
|
/// @param port port number on which to start listening for connections
|
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
UDPListener(const QJsonDocument& config);
|
2016-06-20 08:38:12 +02:00
|
|
|
~UDPListener();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @return the port number on which this UDP listens for incoming connections
|
|
|
|
///
|
|
|
|
uint16_t getPort() const;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-06-27 09:27:11 +02:00
|
|
|
///
|
|
|
|
/// @return true if server is active (bind to a port)
|
|
|
|
///
|
|
|
|
bool active() { return _isActive; };
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
///
|
|
|
|
/// bind server to network
|
|
|
|
///
|
|
|
|
void start();
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-06-27 09:27:11 +02:00
|
|
|
///
|
|
|
|
/// close server
|
|
|
|
///
|
|
|
|
void stop();
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
void componentStateChanged(const hyperion::Components component, bool enable);
|
|
|
|
|
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-20 08:38:12 +02:00
|
|
|
|
2018-12-28 18:12:45 +01:00
|
|
|
signals:
|
|
|
|
///
|
|
|
|
/// @brief forward register data to HyperionDaemon
|
|
|
|
///
|
|
|
|
void registerGlobalInput(const int priority, const hyperion::Components& component, const QString& origin = "System", const QString& owner = "", unsigned smooth_cfg = 0);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief forward led data to HyperionDaemon
|
|
|
|
///
|
|
|
|
const bool setGlobalInput(const int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms = -1, const bool& clearEffect = true);
|
|
|
|
|
2016-06-20 08:38:12 +02:00
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// Slot which is called when a client tries to create a new connection
|
|
|
|
///
|
|
|
|
void readPendingDatagrams();
|
2017-03-01 15:23:53 +01:00
|
|
|
void processTheDatagram(const QByteArray * datagram, const QHostAddress * sender);
|
2016-06-20 08:38:12 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// The UDP server object
|
|
|
|
QUdpSocket * _server;
|
|
|
|
|
|
|
|
/// hyperion priority
|
|
|
|
int _priority;
|
|
|
|
|
2017-03-01 15:23:53 +01:00
|
|
|
/// hyperion timeout
|
2016-06-20 08:38:12 +02:00
|
|
|
int _timeout;
|
|
|
|
|
2016-06-25 15:15:23 +02:00
|
|
|
/// Logger instance
|
|
|
|
Logger * _log;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
/// Bonjour Service Register
|
2018-12-28 18:12:45 +01:00
|
|
|
BonjourServiceRegister* _serviceRegister = nullptr;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-06-27 09:27:11 +02:00
|
|
|
/// state of connection
|
|
|
|
bool _isActive;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-06-27 09:27:11 +02:00
|
|
|
/// address to bind
|
2017-03-01 15:23:53 +01:00
|
|
|
QHostAddress _listenAddress;
|
2018-12-27 23:11:32 +01:00
|
|
|
uint16_t _listenPort;
|
2016-06-27 09:27:11 +02:00
|
|
|
QAbstractSocket::BindFlag _bondage;
|
2016-06-20 08:38:12 +02:00
|
|
|
};
|