2018-12-28 17:55:49 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// util
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <utils/Image.h>
|
|
|
|
#include <utils/ColorRgb.h>
|
2022-01-09 17:23:50 +01:00
|
|
|
#include <utils/ColorRgba.h>
|
2018-12-28 17:55:49 +01:00
|
|
|
#include <utils/Components.h>
|
|
|
|
|
|
|
|
// flatbuffer FBS
|
|
|
|
#include "hyperion_reply_generated.h"
|
|
|
|
#include "hyperion_request_generated.h"
|
|
|
|
|
|
|
|
class QTcpSocket;
|
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
namespace flatbuf {
|
2019-08-02 21:12:13 +02:00
|
|
|
class HyperionRequest;
|
2018-12-28 17:55:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Socket (client) of FlatBufferServer
|
|
|
|
///
|
|
|
|
class FlatBufferClient : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// @brief Construct the client
|
|
|
|
/// @param socket The socket
|
|
|
|
/// @param timeout The timeout when a client is automatically disconnected and the priority unregistered
|
|
|
|
/// @param parent The parent
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
explicit FlatBufferClient(QTcpSocket* socket, int timeout, QObject *parent = nullptr);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
///
|
|
|
|
/// @brief forward register data to HyperionDaemon
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void registerGlobalInput(int priority, hyperion::Components component, const QString& origin = "FlatBuffer", const QString& owner = "", unsigned smooth_cfg = 0);
|
2019-07-29 19:09:26 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Forward clear command to HyperionDaemon
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void clearGlobalInput(int priority, bool forceClearAll=false);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief forward prepared image to HyperionDaemon
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
bool setGlobalInputImage(int priority, const Image<ColorRgb>& image, int timeout_ms, bool clearEffect = false);
|
2019-07-29 19:09:26 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Forward requested color
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void setGlobalInputColor(int priority, const std::vector<ColorRgb> &ledColor, int timeout_ms, const QString& origin = "FlatBuffer" ,bool clearEffects = true);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Emits whenever the client disconnected
|
|
|
|
///
|
|
|
|
void clientDisconnected();
|
|
|
|
|
|
|
|
public slots:
|
2019-07-29 19:09:26 +02:00
|
|
|
///
|
|
|
|
/// @brief Requests a registration from the client
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void registationRequired(int priority);
|
2019-07-29 19:09:26 +02:00
|
|
|
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
|
|
|
/// @brief close the socket and call disconnected()
|
|
|
|
///
|
|
|
|
void forceClose();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// @brief Is called whenever the socket got new data to read
|
|
|
|
///
|
2019-02-17 15:26:11 +01:00
|
|
|
void readyRead();
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Is called when the socket closed the connection, also requests thread exit
|
|
|
|
///
|
2019-02-17 15:26:11 +01:00
|
|
|
void disconnected();
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
/// @brief Handle the received message
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
void handleMessage(const hyperionnet::Request * req);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Register new priority
|
|
|
|
///
|
|
|
|
void handleRegisterCommand(const hyperionnet::Register *regReq);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Hande Color message
|
|
|
|
///
|
|
|
|
void handleColorCommand(const hyperionnet::Color *colorReq);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Handle an incoming Image message
|
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
/// @param image the incoming image
|
|
|
|
///
|
|
|
|
void handleImageCommand(const hyperionnet::Image *image);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Handle clear command
|
|
|
|
///
|
|
|
|
/// @param clear the incoming clear request
|
2018-12-28 17:55:49 +01:00
|
|
|
///
|
2018-12-30 22:07:53 +01:00
|
|
|
void handleClearCommand(const hyperionnet::Clear *clear);
|
2018-12-28 17:55:49 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Send handle not implemented
|
|
|
|
///
|
|
|
|
void handleNotImplemented();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Send a message to the connected client
|
|
|
|
///
|
|
|
|
void sendMessage();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Send a standard reply indicating success
|
|
|
|
///
|
|
|
|
void sendSuccessReply();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Send an error message back to the client
|
|
|
|
///
|
|
|
|
/// @param error String describing the error
|
|
|
|
///
|
|
|
|
void sendErrorReply(const std::string & error);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Logger *_log;
|
2018-12-30 22:07:53 +01:00
|
|
|
QTcpSocket *_socket;
|
2018-12-28 17:55:49 +01:00
|
|
|
const QString _clientAddress;
|
|
|
|
QTimer *_timeoutTimer;
|
|
|
|
int _timeout;
|
|
|
|
int _priority;
|
|
|
|
|
|
|
|
QByteArray _receiveBuffer;
|
|
|
|
|
|
|
|
// Flatbuffers builder
|
|
|
|
flatbuffers::FlatBufferBuilder _builder;
|
|
|
|
};
|