mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
refactor: API split (#721)
* refactor: API split * refactor: cleanup hyperiond
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
// parent class
|
||||
#include <api/API.h>
|
||||
|
||||
// hyperion includes
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/Components.h>
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
@@ -14,7 +16,7 @@ class QTimer;
|
||||
class JsonCB;
|
||||
class AuthManager;
|
||||
|
||||
class JsonAPI : public QObject
|
||||
class JsonAPI : public API
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -28,14 +30,14 @@ public:
|
||||
/// @param localConnection True when the sender has origin home network
|
||||
/// @param noListener if true, this instance won't listen for hyperion push events
|
||||
///
|
||||
JsonAPI(QString peerAddress, Logger* log, const bool& localConnection, QObject* parent, bool noListener = false);
|
||||
JsonAPI(QString peerAddress, Logger *log, const bool &localConnection, QObject *parent, bool noListener = false);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON message
|
||||
///
|
||||
/// @param message the incoming message as string
|
||||
///
|
||||
void handleMessage(const QString & message, const QString& httpAuthHeader = "");
|
||||
void handleMessage(const QString &message, const QString &httpAuthHeader = "");
|
||||
|
||||
///
|
||||
/// @brief Initialization steps
|
||||
@@ -47,36 +49,35 @@ public slots:
|
||||
/// @brief Is called whenever the current Hyperion instance pushes new led raw values (if enabled)
|
||||
/// @param ledColors The current led colors
|
||||
///
|
||||
void streamLedcolorsUpdate(const std::vector<ColorRgb>& ledColors);
|
||||
void streamLedcolorsUpdate(const std::vector<ColorRgb> &ledColors);
|
||||
|
||||
///
|
||||
/// @brief Push images whenever hyperion emits (if enabled)
|
||||
/// @param image The current image
|
||||
///
|
||||
void setImage(const Image<ColorRgb> & image);
|
||||
void setImage(const Image<ColorRgb> &image);
|
||||
|
||||
///
|
||||
/// @brief Process and push new log messages from logger (if enabled)
|
||||
///
|
||||
void incommingLogMessage(const Logger::T_LOG_MESSAGE&);
|
||||
void incommingLogMessage(const Logger::T_LOG_MESSAGE &);
|
||||
|
||||
private slots:
|
||||
///
|
||||
/// @brief Handle emits from AuthManager of new request, just _userAuthorized sessions are allowed to handle them
|
||||
/// @brief Handle emits from API of a new Token request.
|
||||
/// @param id The id of the request
|
||||
/// @param The comment which needs to be accepted
|
||||
///
|
||||
void handlePendingTokenRequest(const QString& id, const QString& comment);
|
||||
void newPendingTokenRequest(const QString &id, const QString &comment);
|
||||
|
||||
///
|
||||
/// @brief Handle emits from AuthManager of accepted/denied/timeouts token request, just if QObject matches with this instance we are allowed to send response.
|
||||
/// @param success If true the request was accepted else false and no token was created
|
||||
/// @param caller The origin caller instance who requested this token
|
||||
/// @param token The new token that is now valid
|
||||
/// @param comment The comment that was part of the request
|
||||
/// @param id The id that was part of the request
|
||||
///
|
||||
void handleTokenResponse(const bool& success, QObject* caller, const QString& token, const QString& comment, const QString& id);
|
||||
void handleTokenResponse(const bool &success, const QString &token, const QString &comment, const QString &id);
|
||||
|
||||
///
|
||||
/// @brief Handle whenever the state of a instance (HyperionIManager) changes according to enum instanceState
|
||||
@@ -84,7 +85,7 @@ private slots:
|
||||
/// @param instance The index of instance
|
||||
/// @param name The name of the instance, just available with H_CREATED
|
||||
///
|
||||
void handleInstanceStateChange(const instanceState& state, const quint8& instance, const QString& name = QString());
|
||||
void handleInstanceStateChange(const instanceState &state, const quint8 &instance, const QString &name = QString());
|
||||
|
||||
signals:
|
||||
///
|
||||
@@ -97,42 +98,15 @@ signals:
|
||||
///
|
||||
void forwardJsonMessage(QJsonObject);
|
||||
|
||||
///
|
||||
/// @brief The API might decide to block connections for security reasons, this emitter should close the socket
|
||||
///
|
||||
void forceClose();
|
||||
|
||||
private:
|
||||
/// Auth management pointer
|
||||
AuthManager* _authManager;
|
||||
|
||||
/// Reflect auth status of this client
|
||||
bool _authorized;
|
||||
bool _userAuthorized;
|
||||
|
||||
/// Reflect auth required
|
||||
bool _apiAuthRequired;
|
||||
|
||||
// true if further callbacks are forbidden (http)
|
||||
bool _noListener;
|
||||
|
||||
/// The peer address of the client
|
||||
QString _peerAddress;
|
||||
|
||||
/// Log instance
|
||||
Logger* _log;
|
||||
|
||||
/// Is this a local connection
|
||||
bool _localConnection;
|
||||
|
||||
/// Hyperion instance manager
|
||||
HyperionIManager* _instanceManager;
|
||||
|
||||
/// Hyperion instance
|
||||
Hyperion* _hyperion;
|
||||
|
||||
// The JsonCB instance which handles data subscription/notifications
|
||||
JsonCB* _jsonCB;
|
||||
JsonCB *_jsonCB;
|
||||
|
||||
// streaming buffers
|
||||
QJsonObject _streaming_leds_reply;
|
||||
@@ -142,17 +116,8 @@ private:
|
||||
/// flag to determine state of log streaming
|
||||
bool _streaming_logging_activated;
|
||||
|
||||
/// timer for live video refresh
|
||||
QTimer* _imageStreamTimer;
|
||||
|
||||
/// image stream connection handle
|
||||
QMetaObject::Connection _imageStreamConnection;
|
||||
|
||||
/// the current streaming image
|
||||
Image<ColorRgb> _currentImage;
|
||||
|
||||
/// timer for led color refresh
|
||||
QTimer* _ledStreamTimer;
|
||||
QTimer *_ledStreamTimer;
|
||||
|
||||
/// led stream connection handle
|
||||
QMetaObject::Connection _ledStreamConnection;
|
||||
@@ -166,21 +131,21 @@ private:
|
||||
/// @param forced indicate if it was a forced switch by system
|
||||
/// @return true on success. false if not found
|
||||
///
|
||||
bool handleInstanceSwitch(const quint8& instance = 0, const bool& forced = false);
|
||||
bool handleInstanceSwitch(const quint8 &instance = 0, const bool &forced = false);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Color message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleColorCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleColorCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Image message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleImageCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleImageCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Effect message
|
||||
@@ -194,126 +159,117 @@ private:
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleCreateEffectCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleCreateEffectCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Effect message (Delete JSON Effect)
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleDeleteEffectCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleDeleteEffectCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON System info message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleSysInfoCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleSysInfoCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Server info message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleServerInfoCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleServerInfoCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Clear message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleClearCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleClearCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Clearall message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleClearallCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleClearallCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Adjustment message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleAdjustmentCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleAdjustmentCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON SourceSelect message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleSourceSelectCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleSourceSelectCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON GetConfig message and check subcommand
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleConfigCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleConfigCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON GetConfig message from handleConfigCommand()
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleSchemaGetCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleSchemaGetCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON SetConfig message from handleConfigCommand()
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleConfigSetCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleConfigSetCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Component State message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleComponentStateCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleComponentStateCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON Led Colors message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleLedColorsCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleLedColorsCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON Logging message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleLoggingCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleLoggingCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON Proccessing message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleProcessingCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleProcessingCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON VideoMode message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleVideoModeCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleVideoModeCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON plugin message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleAuthorizeCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle HTTP on-the-fly token authorization
|
||||
/// @param command The command
|
||||
/// @param tan The tan
|
||||
/// @param token The token to verify
|
||||
/// @return True on succcess else false (pushes failed client feedback)
|
||||
///
|
||||
bool handleHTTPAuth(const QString& command, const int& tan, const QString& token);
|
||||
void handleAuthorizeCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
/// Handle an incoming JSON instance message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleInstanceCommand(const QJsonObject & message, const QString &command, const int tan);
|
||||
void handleInstanceCommand(const QJsonObject &message, const QString &command, const int tan);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON message of unknown type
|
||||
@@ -323,22 +279,22 @@ private:
|
||||
///
|
||||
/// Send a standard reply indicating success
|
||||
///
|
||||
void sendSuccessReply(const QString &command="", const int tan=0);
|
||||
void sendSuccessReply(const QString &command = "", const int tan = 0);
|
||||
|
||||
///
|
||||
/// Send a standard reply indicating success with data
|
||||
///
|
||||
void sendSuccessDataReply(const QJsonDocument &doc, const QString &command="", const int &tan=0);
|
||||
void sendSuccessDataReply(const QJsonDocument &doc, const QString &command = "", const int &tan = 0);
|
||||
|
||||
///
|
||||
/// Send an error message back to the client
|
||||
///
|
||||
/// @param error String describing the error
|
||||
///
|
||||
void sendErrorReply(const QString & error, const QString &command="", const int tan=0);
|
||||
void sendErrorReply(const QString &error, const QString &command = "", const int tan = 0);
|
||||
|
||||
///
|
||||
/// @brief Kill all signal/slot connections to stop possible data emitter
|
||||
///
|
||||
void stopDataConnections(void);
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user