mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
ProtoBuffer, UDPListener ...
Protocol Buffer reimplemented to receive image data from third-party apps The status of the component "UDPListener" is now displayed correctly in WebUI Global signal names for WebUI added
This commit is contained in:
135
libsrc/protoserver/ProtoClientConnection.h
Normal file
135
libsrc/protoserver/ProtoClientConnection.h
Normal file
@@ -0,0 +1,135 @@
|
||||
#pragma once
|
||||
|
||||
// util
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
#include <utils/Components.h>
|
||||
|
||||
// protobuffer PROTO
|
||||
#include "message.pb.h"
|
||||
|
||||
class QTcpSocket;
|
||||
class QTimer;
|
||||
class Hyperion;
|
||||
|
||||
namespace proto {
|
||||
class HyperionRequest;
|
||||
}
|
||||
|
||||
///
|
||||
/// The Connection object created by a ProtoServer when a new connection is established
|
||||
///
|
||||
class ProtoClientConnection : 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
|
||||
///
|
||||
explicit ProtoClientConnection(QTcpSocket* socket, const int &timeout, QObject *parent);
|
||||
|
||||
signals:
|
||||
///
|
||||
/// @brief Emits whenever the client disconnected
|
||||
///
|
||||
void clientDisconnected();
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// @brief close the socket and call disconnected()
|
||||
///
|
||||
void forceClose();
|
||||
|
||||
private slots:
|
||||
///
|
||||
/// @brief Is called whenever the socket got new data to read
|
||||
///
|
||||
void readyRead();
|
||||
|
||||
///
|
||||
/// @brief Is called when the socket closed the connection, also requests thread exit
|
||||
///
|
||||
void disconnected();
|
||||
|
||||
private:
|
||||
///
|
||||
/// Handle an incoming Proto message
|
||||
///
|
||||
/// @param message the incoming message as string
|
||||
///
|
||||
void handleMessage(const proto::HyperionRequest &message);
|
||||
|
||||
///
|
||||
/// Handle an incoming Proto Color message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleColorCommand(const proto::ColorRequest & message);
|
||||
|
||||
///
|
||||
/// Handle an incoming Proto Image message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleImageCommand(const proto::ImageRequest & message);
|
||||
|
||||
///
|
||||
/// Handle an incoming Proto Clear message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleClearCommand(const proto::ClearRequest & message);
|
||||
|
||||
///
|
||||
/// Handle an incoming Proto Clearall message
|
||||
///
|
||||
void handleClearallCommand();
|
||||
|
||||
///
|
||||
/// Handle an incoming Proto message of unknown type
|
||||
///
|
||||
void handleNotImplemented();
|
||||
|
||||
///
|
||||
/// Send a message to the connected client
|
||||
///
|
||||
/// @param message The Proto message to send
|
||||
///
|
||||
void sendMessage(const google::protobuf::Message &message);
|
||||
|
||||
///
|
||||
/// 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;
|
||||
|
||||
/// The TCP-Socket that is connected tot the Proto-client
|
||||
QTcpSocket* _socket;
|
||||
|
||||
/// address of client
|
||||
const QString _clientAddress;
|
||||
|
||||
QTimer*_timeoutTimer;
|
||||
int _timeout;
|
||||
int _priority;
|
||||
|
||||
/// Link to Hyperion for writing led-values to a priority channel
|
||||
Hyperion* _hyperion;
|
||||
|
||||
/// The buffer used for reading data from the socket
|
||||
QByteArray _receiveBuffer;
|
||||
};
|
Reference in New Issue
Block a user