2016-06-20 08:38:12 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// system includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QUdpSocket>
|
|
|
|
#include <QSet>
|
2016-06-27 09:27:11 +02:00
|
|
|
#include <QHostAddress>
|
2016-06-20 08:38:12 +02:00
|
|
|
|
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/Hyperion.h>
|
2016-06-25 15:15:23 +02:00
|
|
|
#include <utils/Logger.h>
|
2016-06-20 08:38:12 +02:00
|
|
|
|
|
|
|
class UDPClientConnection;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// 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
|
|
|
|
///
|
2016-06-26 20:08:03 +02:00
|
|
|
UDPListener(const int priority, const int timeout, const std::string& address, quint16 listenPort, bool shared);
|
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;
|
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();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// close server
|
|
|
|
///
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void statusChanged(bool isActive);
|
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();
|
|
|
|
void processTheDatagram(const QByteArray * _datagram);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Hyperion instance
|
|
|
|
Hyperion * _hyperion;
|
|
|
|
|
|
|
|
/// The UDP server object
|
|
|
|
QUdpSocket * _server;
|
|
|
|
|
|
|
|
/// List with open connections
|
|
|
|
QSet<UDPClientConnection *> _openConnections;
|
|
|
|
|
|
|
|
/// hyperion priority
|
|
|
|
int _priority;
|
|
|
|
|
|
|
|
/// hyperion priority
|
|
|
|
int _timeout;
|
|
|
|
|
2016-06-25 15:15:23 +02:00
|
|
|
/// Logger instance
|
|
|
|
Logger * _log;
|
2016-06-27 09:27:11 +02:00
|
|
|
|
|
|
|
/// state of connection
|
|
|
|
bool _isActive;
|
|
|
|
|
|
|
|
/// address to bind
|
|
|
|
QHostAddress _listenAddress;
|
|
|
|
quint16 _listenPort;
|
|
|
|
QAbstractSocket::BindFlag _bondage;
|
2016-06-20 08:38:12 +02:00
|
|
|
};
|