hyperion.ng/libsrc/boblightserver/BoblightClientConnection.h

141 lines
3.3 KiB
C
Raw Normal View History

#pragma once
// Qt includes
#include <QByteArray>
#include <QTcpSocket>
#include <QLocale>
#include <QString>
// utils includes
#include <utils/Logger.h>
#include <utils/ColorRgb.h>
/// Whether to parse floats with an eye on performance
#define FAST_FLOAT_PARSE
class ImageProcessor;
class Hyperion;
///
Various Cleanups (#1075) * LedDevice - Address clang findings * Fix Windows Warnings * Ensure newInput is initialised * Clean-up unused elements for Plaform Capture * Fix initialization problem and spellings * Address clang findings and spelling corrections * LedDevice clean-ups * Cleanups * Align that getLedCount is int * Have "display" as default for Grabbers * Fix config during start-up for missing elements * Framegrabber Clean-up - Remove non supported grabbers from selection, filter valid options * Typo * Framegrabber.json - Fix property numbering * Preselect active Grabbertype * Sort Grabbernames * Align options with selected element * Fix deletion of pointer to incomplete type 'BonjourBrowserWrapper' * Address macOS compile warnings * Have default layout = 1 LED only to avoid errors as in #673 * Address lgtm findings * Address finding that params passed to LedDevice discovery were not considered * Cleanups after merging with latest master * Update Changelog * Address lgtm findings * Fix comment * Test Fix * Fix Python Warning * Handle Dummy Device assignment correctly * Address delete called on non-final 'commandline::Option' that has virtual functions but non-virtual destructor * Correct that QTimer.start accepts only int * Have Release Python GIL & reset threat state chnage downward compatible * Correct format specifier * LedDevice - add assertions * Readonly DB - Fix merge issue * Smoothing - Fix wrong defaults * LedDevice - correct assertion * Show smoothing config set# in debug and related values. * Suppress error on windows, if default file is "/dev/null" * CMAKE - Allow to define QT_BASE_DIR dynamically via environment-variable * Ignore Visual Studio specific files Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2020-11-14 17:58:56 +01:00
/// The Connection object created by \a BoblightServer when a new connection is established
///
class BoblightClientConnection : public QObject
{
Q_OBJECT
public:
///
/// Constructor
/// @param socket The Socket object for this connection
/// @param hyperion The Hyperion server
///
2020-08-08 13:09:15 +02:00
BoblightClientConnection(Hyperion* hyperion, QTcpSocket * socket, int priority);
///
/// Destructor
///
~BoblightClientConnection() override;
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
///
void sendMessage(const QByteArray &message) { _socket->write(message); };
///
/// Send a lights message the to connected client
///
void sendLightMessage();
///
/// Interpret the float value "0.0" to "1.0" of the QString byte values 0 .. 255
///
/// @param s the string to parse
/// @param ok whether the result is ok
/// @return the parsed byte value in range 0 to 255, or 0
///
uint8_t parseByte(const QStringRef& s, bool *ok = nullptr) const;
///
/// Parse the given QString as unsigned int value.
///
/// @param s the string to parse
/// @param ok whether the result is ok
/// @return the parsed unsigned int value
///
unsigned parseUInt(const QStringRef& s, bool *ok = nullptr) const;
///
/// Parse the given QString as float value, e.g. the 16-bit (wide char) QString "1" shall represent 1, "0.5" is 0.5 and so on.
///
/// @param s the string to parse
/// @param ok whether the result is ok
/// @return the parsed float value, or 0
///
float parseFloat(const QStringRef& s, bool *ok = nullptr) const;
///
/// Read an incoming boblight message as QString
///
/// @param data the char data buffer of the incoming message
/// @param size the length of the buffer buffer
/// @returns the incoming boblight message as QString
///
QString readMessage(const char *data, const size_t size) const;
private:
/// Locale used for parsing floating point values
QLocale _locale;
/// The TCP-Socket that is connected tot the boblight-client
QTcpSocket * _socket;
/// The processor for translating images to led-values
ImageProcessor * _imageProcessor;
/// 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
std::vector<ColorRgb> _ledColors;
2018-12-27 23:11:32 +01:00
/// logger instance
Logger * _log;
/// address of client
QString _clientAddress;
};