2013-11-08 22:18:10 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// system includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QSet>
|
|
|
|
|
|
|
|
// Hyperion includes
|
|
|
|
#include <hyperion/Hyperion.h>
|
2016-06-27 22:43:43 +02:00
|
|
|
#include <utils/Logger.h>
|
2013-11-08 22:18:10 +01:00
|
|
|
|
|
|
|
class BoblightClientConnection;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// This class creates a TCP server which accepts connections from boblight clients.
|
|
|
|
///
|
|
|
|
class BoblightServer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// BoblightServer constructor
|
|
|
|
/// @param hyperion Hyperion instance
|
|
|
|
/// @param port port number on which to start listening for connections
|
|
|
|
///
|
2016-06-20 23:41:07 +02:00
|
|
|
BoblightServer(const int priority, uint16_t port = 19333);
|
2013-11-08 22:18:10 +01:00
|
|
|
~BoblightServer();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @return the port number on which this TCP listens for incoming connections
|
|
|
|
///
|
|
|
|
uint16_t getPort() const;
|
2016-06-27 22:43:43 +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);
|
2013-11-08 22:18:10 +01: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(BoblightClientConnection * connection);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Hyperion instance
|
|
|
|
Hyperion * _hyperion;
|
|
|
|
|
|
|
|
/// The TCP server object
|
|
|
|
QTcpServer _server;
|
|
|
|
|
|
|
|
/// List with open connections
|
|
|
|
QSet<BoblightClientConnection *> _openConnections;
|
2016-03-08 17:31:56 +01:00
|
|
|
|
|
|
|
/// hyperion priority
|
|
|
|
const int _priority;
|
2016-06-27 22:43:43 +02:00
|
|
|
|
|
|
|
/// Logger instance
|
|
|
|
Logger * _log;
|
|
|
|
|
|
|
|
/// state of connection
|
|
|
|
bool _isActive;
|
|
|
|
|
|
|
|
uint16_t _port;
|
2013-11-08 22:18:10 +01:00
|
|
|
};
|