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>
|
2016-08-11 07:13:55 +02:00
|
|
|
#include <utils/Components.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; };
|
2016-08-11 07:13:55 +02:00
|
|
|
bool componentState() { return active(); };
|
|
|
|
|
2016-06-27 22:43:43 +02:00
|
|
|
public slots:
|
|
|
|
///
|
|
|
|
/// bind server to network
|
|
|
|
///
|
|
|
|
void start();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// close server
|
|
|
|
///
|
|
|
|
void stop();
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
void componentStateChanged(const hyperion::Components component, bool enable);
|
|
|
|
|
2016-06-27 22:43:43 +02:00
|
|
|
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
|
|
|
};
|