2013-11-08 22:18:10 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
#include <QLocale>
|
|
|
|
|
2018-12-28 18:12:45 +01:00
|
|
|
// utils includes
|
2016-06-27 22:43:43 +02:00
|
|
|
#include <utils/Logger.h>
|
2018-12-28 18:12:45 +01:00
|
|
|
#include <utils/ColorRgb.h>
|
|
|
|
|
|
|
|
class ImageProcessor;
|
|
|
|
class Hyperion;
|
2013-11-08 22:18:10 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// The Connection object created by \a BoblightServer when a new connection is establshed
|
|
|
|
///
|
|
|
|
class BoblightClientConnection : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// Constructor
|
|
|
|
/// @param socket The Socket object for this connection
|
|
|
|
/// @param hyperion The Hyperion server
|
|
|
|
///
|
2018-12-28 18:12:45 +01:00
|
|
|
BoblightClientConnection(Hyperion* hyperion, QTcpSocket * socket, const int priority);
|
2013-11-08 22:18:10 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Destructor
|
|
|
|
///
|
|
|
|
~BoblightClientConnection();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
///
|
|
|
|
/// Signal which is emitted when the connection is being closed
|
|
|
|
/// @param connection This connection object
|
|
|
|
///
|
|
|
|
void connectionClosed(BoblightClientConnection * connection);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// Slot called when new data has arrived
|
|
|
|
///
|
|
|
|
void readData();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Slot called when this connection is being closed
|
|
|
|
///
|
|
|
|
void socketClosed();
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
/// Handle an incoming boblight message
|
|
|
|
///
|
|
|
|
/// @param message the incoming message as string
|
|
|
|
///
|
|
|
|
void handleMessage(const QString &message);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Send a message to the connected client
|
|
|
|
///
|
|
|
|
/// @param message The boblight message to send
|
|
|
|
///
|
2019-08-01 19:10:15 +02:00
|
|
|
void sendMessage(const QByteArray &message) { _socket->write(message); };
|
2013-11-08 22:18:10 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Send a lights message the to connected client
|
|
|
|
///
|
|
|
|
void sendLightMessage();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Locale used for parsing floating point values
|
|
|
|
QLocale _locale;
|
|
|
|
|
|
|
|
/// The TCP-Socket that is connected tot the boblight-client
|
|
|
|
QTcpSocket * _socket;
|
|
|
|
|
2018-12-28 18:12:45 +01:00
|
|
|
/// The processor for translating images to led-values
|
|
|
|
ImageProcessor * _imageProcessor;
|
|
|
|
|
2013-11-08 22:18:10 +01:00
|
|
|
/// Link to Hyperion for writing led-values to a priority channel
|
|
|
|
Hyperion * _hyperion;
|
|
|
|
|
|
|
|
/// The buffer used for reading data from the socket
|
|
|
|
QByteArray _receiveBuffer;
|
|
|
|
|
|
|
|
/// The priority used by this connection
|
|
|
|
int _priority;
|
|
|
|
|
|
|
|
/// The latest led color data
|
2013-11-11 10:00:37 +01:00
|
|
|
std::vector<ColorRgb> _ledColors;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-06-27 22:43:43 +02:00
|
|
|
/// logger instance
|
|
|
|
Logger * _log;
|
2017-03-01 15:23:53 +01:00
|
|
|
|
|
|
|
/// address of client
|
|
|
|
QString _clientAddress;
|
2013-11-08 22:18:10 +01:00
|
|
|
};
|