2013-11-08 22:18:10 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// system includes
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QSet>
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <QJsonDocument>
|
2013-11-08 22:18:10 +01:00
|
|
|
|
|
|
|
// Hyperion includes
|
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
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// settings
|
|
|
|
#include <utils/settings.h>
|
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
class BoblightClientConnection;
|
2018-12-27 23:11:32 +01:00
|
|
|
class Hyperion;
|
|
|
|
class QTcpServer;
|
2013-11-08 22:18:10 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// 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
|
|
|
|
///
|
2018-12-28 18:12:45 +01:00
|
|
|
BoblightServer(Hyperion* hyperion, const QJsonDocument& config);
|
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;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-06-27 22:43:43 +02:00
|
|
|
/// @return true if server is active (bind to a port)
|
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
bool active();
|
2016-08-11 07:13:55 +02:00
|
|
|
|
2016-06-27 22:43:43 +02:00
|
|
|
public slots:
|
|
|
|
///
|
|
|
|
/// bind server to network
|
|
|
|
///
|
|
|
|
void start();
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-06-27 22:43:43 +02:00
|
|
|
///
|
|
|
|
/// close server
|
|
|
|
///
|
|
|
|
void stop();
|
|
|
|
|
2020-02-26 18:54:56 +01:00
|
|
|
void compStateChangeRequest(const hyperion::Components component, bool enable);
|
2016-08-11 07:13:55 +02: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);
|
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
|
2018-12-27 23:11:32 +01:00
|
|
|
QTcpServer * _server;
|
2013-11-08 22:18:10 +01:00
|
|
|
|
|
|
|
/// List with open connections
|
|
|
|
QSet<BoblightClientConnection *> _openConnections;
|
2016-03-08 17:31:56 +01:00
|
|
|
|
|
|
|
/// hyperion priority
|
2018-12-27 23:11:32 +01:00
|
|
|
int _priority;
|
2016-06-27 22:43:43 +02:00
|
|
|
|
|
|
|
/// Logger instance
|
|
|
|
Logger * _log;
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// current port
|
2017-03-01 15:23:53 +01:00
|
|
|
uint16_t _port;
|
2013-11-08 22:18:10 +01:00
|
|
|
};
|