refactor: API split (#721)

* refactor: API split

* refactor: cleanup hyperiond
This commit is contained in:
brindosch
2020-03-26 17:59:41 +01:00
committed by GitHub
parent c6c6453267
commit 2739aec1e3
23 changed files with 2044 additions and 1128 deletions

409
include/api/API.h Normal file
View File

@@ -0,0 +1,409 @@
#pragma once
// hyperion includes
#include <utils/Logger.h>
#include <utils/Components.h>
#include <hyperion/Hyperion.h>
#include <hyperion/HyperionIManager.h>
// auth manager
#include <hyperion/AuthManager.h>
#include <utils/ColorRgb.h>
#include <utils/ColorSys.h>
// qt includes
#include <QString>
class QTimer;
class JsonCB;
class HyperionIManager;
const QString NO_AUTH = "No Authorization";
///
/// @brief API for Hyperion to be inherted from a child class with specific protocol implementations
/// Workflow:
/// 1. create the class
/// 2. connect the forceClose signal, as the api might to close the connection for security reasons
/// 3. call Initialize()
/// 4. proceed as usual
///
class API : public QObject
{
Q_OBJECT
public:
#include <api/apiStructs.h>
// workaround Q_ARG std::map template issues
typedef std::map<int, registerData> MapRegister;
typedef QMap<QString, AuthManager::AuthDefinition> MapAuthDefs;
///
/// Constructor
///
///@ param The parent Logger
/// @param localConnection Is this a local network connection? Use utils/NetOrigin to check that
/// @param parent Parent QObject
///
API(Logger *log, const bool &localConnection, QObject *parent);
protected:
///
/// @brief Initialize the API
/// This call is REQUIRED!
///
void init(void);
///
/// @brief Set a single color
/// @param[in] priority The priority of the written color
/// @param[in] ledColor The color to write to the leds
/// @param[in] timeout_ms The time the leds are set to the given color [ms]
/// @param[in] origin The setter
///
void setColor(const int &priority, const std::vector<uint8_t> &ledColors, const int &timeout_ms = -1, const QString &origin = "API", const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Set a image
/// @param[in] data The command data
/// @param[in] comp The component that should be used
/// @param[out] replyMsg The replyMsg on failure
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
/// @return True on success
///
bool setImage(ImageCmdData &data, hyperion::Components comp, QString &replyMsg, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Clear a priority in the Muxer, if -1 all priorities are cleared
/// @param priority The priority to clear
/// @param replyMsg the message on failure
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
/// @return True on success
///
bool clearPriority(const int &priority, QString &replyMsg, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Set a new component state
/// @param comp The component name
/// @param compState The new state of the comp
/// @param replyMsg The reply on failure
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
/// @ return True on success
///
bool setComponentState(const QString &comp, bool &compState, QString &replyMsg, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Set a ledToImageMapping type
/// @param type mapping type string
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
///
void setLedMappingType(const int &type, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Set the 2D/3D modes type
/// @param mode The VideoMode
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
///
void setVideoMode(const VideoMode &mode, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Set an effect
/// @param dat The effect data
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
/// REQUIRED dat fields: effectName, priority, duration, origin
///
void setEffect(const EffectCmdData &dat, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Set source auto select enabled or disabled
/// @param sate The new state
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
///
void setSourceAutoSelect(const bool state, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Set the visible priority to given priority
/// @param priority The priority to set
/// @param callerComp The HYPERION COMPONENT that calls this function! e.g. PROT/FLATBUF
///
void setVisiblePriority(const int &priority, const hyperion::Components &callerComp = hyperion::COMP_INVALID);
///
/// @brief Register a input or update the meta data of a previous register call
/// ATTENTION: Check unregisterInput() method description !!!
/// @param[in] priority The priority of the channel
/// @param[in] component The component of the channel
/// @param[in] origin Who set the channel (CustomString@IP)
/// @param[in] owner Specific owner string, might be empty
/// @param[in] callerComp The component that call this (e.g. PROTO/FLAT)
///
void registerInput(const int &priority, const hyperion::Components &component, const QString &origin, const QString &owner, const hyperion::Components &callerComp);
///
/// @brief Revoke a registerInput() call by priority. We maintain all registered priorities in this scope
/// ATTENTION: This is MANDATORY if you change (priority change) or stop(clear/timeout) DURING lifetime. If this class destructs it's not needed
/// @param priority The priority to unregister
///
void unregisterInput(const int &priority);
///
/// @brief Handle the instance switching
/// @param inst The requested instance
/// @return True on success else false
///
bool setHyperionInstance(const quint8 &inst);
///
/// @brief Get all contrable components and their state
///
std::map<hyperion::Components, bool> getAllComponents();
///
/// @brief Check if Hyperion ist enabled
/// @return True when enabled else false
///
bool isHyperionEnabled();
///
/// @brief Get all instances data
/// @return The instance data
///
QVector<QVariantMap> getAllInstanceData(void);
///
/// @brief Start instance
/// @param index The instance index
///
void startInstance(const quint8 &index);
///
/// @brief Stop instance
/// @param index The instance index
///
void stopInstance(const quint8 &index);
//////////////////////////////////
/// AUTH / ADMINISTRATION METHODS
//////////////////////////////////
///
/// @brief Delete instance. Requires ADMIN ACCESS
/// @param index The instance index
/// @param replyMsg The reply Msg
/// @return False with reply
///
bool deleteInstance(const quint8 &index, QString &replyMsg);
///
/// @brief Create instance. Requires ADMIN ACCESS
/// @param name With given name
/// @return False with reply
///
QString createInstance(const QString &name);
///
/// @brief Rename an instance. Requires ADMIN ACCESS
/// @param index The instance index
/// @param name With given name
/// @return False with reply
///
QString setInstanceName(const quint8 &index, const QString &name);
///
/// @brief Delete an effect. Requires ADMIN ACCESS
/// @param name The effect name
/// @return True on success else false
///
QString deleteEffect(const QString &name);
///
/// @brief Delete an effect. Requires ADMIN ACCESS
/// @param name The effect name
/// @return True on success else false
///
QString saveEffect(const QJsonObject &data);
///
/// @brief Save settings object. Requires ADMIN ACCESS
/// @param data The data object
///
void saveSettings(const QJsonObject &data);
///
/// @brief Test if we are authorized to use the interface
/// @return The result
///
bool isAuthorized() { return _authorized; };
///
/// @brief Test if we are authorized to use the admin interface
/// @return The result
///
bool isAdminAuthorized() { return _adminAuthorized; };
///
/// @brief Update the Password of Hyperion. Requires ADMIN ACCESS
/// @param password Old password
/// @param newPassword New password
/// @return True on success else false
///
bool updateHyperionPassword(const QString &password, const QString &newPassword);
///
/// @brief Get a new token from AuthManager. Requires ADMIN ACCESS
/// @param comment The comment of the request
/// @param def The final definition
/// @return Empty string on success else error message
///
QString createToken(const QString &comment, AuthManager::AuthDefinition &def);
///
/// @brief Rename a token by given id. Requires ADMIN ACCESS
/// @param id The id of the token
/// @param comment The new comment
/// @return Empty string on success else error message
///
QString renameToken(const QString &id, const QString &comment);
///
/// @brief Delete a token by given id. Requires ADMIN ACCESS
/// @param id The id of the token
/// @return Empty string on success else error message
///
QString deleteToken(const QString &id);
///
/// @brief Set a new token request
/// @param comment The comment
/// @param id The id
///
void setNewTokenRequest(const QString &comment, const QString &id);
///
/// @brief Cancel new token request
/// @param comment The comment
/// @param id The id
///
void cancelNewTokenRequest(const QString &comment, const QString &id);
///
/// @brief Handle a pending token request. Requires ADMIN ACCESS
/// @param id The id fo the request
/// @param accept True when it should be accepted, else false
/// @return True on success
bool handlePendingTokenRequest(const QString &id, const bool accept);
///
/// @brief Get the current List of Tokens. Requires ADMIN ACCESS
/// @param def returns the defintions
/// @return True on success
///
bool getTokenList(QVector<AuthManager::AuthDefinition> &def);
///
/// @brief Get all current pending token requests. Requires ADMIN ACCESS
/// @return True on success
///
bool getPendingTokenRequests(QVector<AuthManager::AuthDefinition> &map);
///
/// @brief Is User Token Authorized. On success this will grant acces to API and ADMIN API
/// @param userToken The user Token
/// @return True on succes
///
bool isUserTokenAuthorized(const QString &userToken);
///
/// @brief Get the current User Token (session token). Requires ADMIN ACCESS
/// @param userToken The user Token
/// @return True on success
///
bool getUserToken(QString &userToken);
///
/// @brief Is a token authrized. On success this will grant acces to the API (NOT ADMIN API)
/// @param token The user Token
/// @return True on succes
///
bool isTokenAuthorized(const QString &token);
///
/// @brief Is User authorized. On success this will grant acces to the API and ADMIN API
/// @param password The password of the User
/// @return True if authorized
///
bool isUserAuthorized(const QString &password);
///
/// @brief Test if Hyperion has the default PW
/// @return The result
///
bool hasHyperionDefaultPw();
///
/// @brief Logout revokes all authorizations
///
void logout();
/// Reflect auth status of this client
bool _authorized;
bool _adminAuthorized;
/// Is this a local connection
bool _localConnection;
AuthManager *_authManager;
HyperionIManager *_instanceManager;
Logger *_log;
Hyperion *_hyperion;
signals:
///
/// @brief The API might decide to block connections for security reasons, this emitter should close the socket
///
void forceClose();
///
/// @brief Emits whenever a new Token request is pending. This signal is just active when ADMIN ACCESS has been granted
/// @param id The id of the request
/// @param comment The comment of the request; If the commen is EMPTY the request has been revoked by the caller. So remove it from the pending list
///
void onPendingTokenRequest(const QString &id, const QString &comment);
///
/// @brief Handle emits from AuthManager of accepted/denied/timeouts token request, just if QObject matches with this instance it will emit.
/// @param success If true the request was accepted else false and no token was created
/// @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 onTokenResponse(const bool &success, const QString &token, const QString &comment, const QString &id);
private slots:
///
/// @brief Is called whenever a Hyperion instance wants the current register list
/// @param callerInstance The instance should be returned in the answer call
///
void requestActiveRegister(QObject *callerInstance);
///
/// @brief See onTokenResponse(). Here we validate the caller instance and on success we will emit onTokenResponse()
/// @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 checkTokenResponse(const bool &success, QObject *caller, const QString &token, const QString &comment, const QString &id);
private:
void stopDataConnectionss();
// Contains all active register call data
std::map<int, registerData> _activeRegisters;
// current instance index
quint8 _currInstanceIndex;
};

View File

@@ -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);
};
};

View File

@@ -12,6 +12,8 @@
#include <utils/VideoMode.h>
// settings
#include <utils/settings.h>
// AuthManager
#include <hyperion/AuthManager.h>
class Hyperion;
class ComponentRegister;
@@ -119,6 +121,11 @@ private slots:
///
void handleInstanceChange();
///
/// @brief Handle AuthManager token changes
///
void handleTokenChange(const QVector<AuthManager::AuthDefinition> &def);
private:
/// pointer of Hyperion instance
Hyperion* _hyperion;

36
include/api/apiStructs.h Normal file
View File

@@ -0,0 +1,36 @@
#pragma once
#include <QString>
#include <QByteArray>
struct ImageCmdData
{
int priority;
QString origin;
int64_t duration;
int width;
int height;
int scale;
QString format;
QString imgName;
QByteArray data;
};
struct EffectCmdData
{
int priority;
int duration;
QString pythonScript;
QString origin;
QString effectName;
QString data;
QJsonObject args;
};
struct registerData
{
const hyperion::Components component;
const QString origin;
const QString owner;
const hyperion::Components callerComp;
};

View File

@@ -222,6 +222,22 @@ public:
return deleteRecord(cond);
}
///
/// @brief Rename token record by id
/// @param[in] id The token id
/// @param[in] comment The new comment
/// @return true on success else false
///
inline bool renameToken(const QString &id, const QString &comment)
{
QVariantMap map;
map["comment"] = comment;
VectorPair cond;
cond.append(CPair("id", id));
return updateRecord(cond, map);
}
///
/// @brief Get all 'comment', 'last_use' and 'id' column entries
/// @return A vector of all lists

View File

@@ -41,19 +41,17 @@ public:
///
/// @brief Save an effect with EffectFileHandler
/// @param obj The effect args
/// @param[out] resultMsg The feedback message
/// @return True on success else false
/// @param obj The effect args
/// @return If not empty, it contains the error
///
bool saveEffect(const QJsonObject& obj, QString& resultMsg);
QString saveEffect(const QJsonObject& obj);
///
/// @brief Delete an effect by name.
/// @param[in] effectName The effect name to delete
/// @param[out] resultMsg The message on error
/// @return True on success else false
/// @param effectName The effect name to delete
/// @return If not empty, it contains the error
///
bool deleteEffect(const QString& effectName, QString& resultMsg);
QString deleteEffect(const QString& effectName);
///
/// @brief Get all init data of the running effects and stop them

View File

@@ -29,19 +29,17 @@ public:
///
/// @brief Save an effect
/// @param obj The effect args
/// @param[out] resultMsg The feedback message
/// @return True on success else false
/// @param obj The effect args
/// @return If not empty, it contains the error
///
bool saveEffect(const QJsonObject& obj, QString& resultMsg);
QString saveEffect(const QJsonObject& obj);
///
/// @brief Delete an effect by name.
/// @param[in] effectName The effect name to delete
/// @param[out] resultMsg The message on error
/// @return True on success else false
/// @param effectName The effect name to delete
/// @return If not empty, it contains the error
///
bool deleteEffect(const QString& effectName, QString& resultMsg);
QString deleteEffect(const QString& effectName);
public slots:
///

View File

@@ -20,13 +20,14 @@ class AuthManager : public QObject
private:
friend class HyperionDaemon;
/// constructor is private, can be called from HyperionDaemon
AuthManager(QObject* parent = 0);
AuthManager(QObject *parent = 0);
public:
struct AuthDefinition{
struct AuthDefinition
{
QString id;
QString comment;
QObject* caller;
QObject *caller;
uint64_t timeoutTime;
QString token;
QString lastUse;
@@ -36,43 +37,25 @@ public:
/// @brief Get the unique id (imported from removed class 'Stats')
/// @return The unique id
///
const QString & getID() { return _uuid; };
///
/// @brief Get all available token entries
///
const QVector<AuthDefinition> getTokenList();
const QString &getID() { return _uuid; };
///
/// @brief Check authorization is required according to the user setting
/// @return True if authorization required else false
///
const bool & isAuthRequired() { return _authRequired; };
const bool &isAuthRequired() { return _authRequired; };
///
/// @brief Check if authorization is required for local network connections
/// @return True if authorization required else false
///
const bool & isLocalAuthRequired() { return _localAuthRequired; };
const bool &isLocalAuthRequired() { return _localAuthRequired; };
///
/// @brief Check if authorization is required for local network connections for admin access
/// @return True if authorization required else false
///
const bool & isLocalAdminAuthRequired() { return _localAdminAuthRequired; };
///
/// @brief Check if Hyperion user has default password
/// @return True if so, else false
///
const bool hasHyperionDefaultPw() { return isUserAuthorized("Hyperion","hyperion"); };
///
/// @brief Get the current valid token for user. Make sure this call is allowed!
/// @param For the defined user
/// @return The token
///
const QString getUserToken(const QString & usr = "Hyperion");
const bool &isLocalAdminAuthRequired() { return _localAdminAuthRequired; };
///
/// @brief Reset Hyperion user
@@ -81,11 +64,23 @@ public:
bool resetHyperionUser();
///
/// @brief Create a new token and skip the usual chain
/// @param comment The comment that should be used for
/// @return The new Auth definition
/// @brief Check if user auth is temporary blocked due to failed attempts
/// @return True on blocked and no further Auth requests will be accepted
///
const AuthDefinition createToken(const QString& comment);
bool isUserAuthBlocked() { return (_userAuthAttempts.length() >= 10); };
///
/// @brief Check if token auth is temporary blocked due to failed attempts
/// @return True on blocked and no further Auth requests will be accepted
///
bool isTokenAuthBlocked() { return (_tokenAuthAttempts.length() >= 25); };
/// Pointer of this instance
static AuthManager *manager;
/// Get Pointer of this instance
static AuthManager *getInstance() { return manager; };
public slots:
///
/// @brief Check if user is authorized
@@ -93,14 +88,14 @@ public:
/// @param pw The password
/// @return True if authorized else false
///
bool isUserAuthorized(const QString& user, const QString& pw);
bool isUserAuthorized(const QString &user, const QString &pw);
///
/// @brief Check if token is authorized
/// @param token The token
/// @return True if authorized else false
///
bool isTokenAuthorized(const QString& token);
bool isTokenAuthorized(const QString &token);
///
/// @brief Check if token is authorized
@@ -108,19 +103,29 @@ public:
/// @param token The token
/// @return True if authorized else false
///
bool isUserTokenAuthorized(const QString& usr, const QString& token);
bool isUserTokenAuthorized(const QString &usr, const QString &token);
///
/// @brief Check if user auth is temporary blocked due to failed attempts
/// @return True on blocked and no further Auth requests will be accepted
/// @brief Create a new token and skip the usual chain
/// @param comment The comment that should be used for
/// @return The new Auth definition
///
bool isUserAuthBlocked(){ return (_userAuthAttempts.length() >= 10); };
AuthManager::AuthDefinition createToken(const QString &comment);
///
/// @brief Check if token auth is temporary blocked due to failed attempts
/// @return True on blocked and no further Auth requests will be accepted
/// @brief Rename a token by id
/// @param id The token id
/// @param comment The new comment
/// @return True on success else false (or not found)
///
bool isTokenAuthBlocked(){ return (_tokenAuthAttempts.length() >= 25); };
bool renameToken(const QString &id, const QString &comment);
///
/// @brief Delete a token by id
/// @param id The token id
/// @return True on success else false (or not found)
///
bool deleteToken(const QString &id);
///
/// @brief Change password of user
@@ -129,7 +134,7 @@ public:
/// @param newPw The new password
/// @return True on success else false
///
bool updateUserPassword(const QString& user, const QString& pw, const QString& newPw);
bool updateUserPassword(const QString &user, const QString &pw, const QString &newPw);
///
/// @brief Generate a new pending token request with the provided comment and id as identifier helper
@@ -137,55 +142,55 @@ public:
/// @param comment The comment as ident helper
/// @param id The id created by the caller
///
void setNewTokenRequest(QObject* caller, const QString& comment, const QString& id);
void setNewTokenRequest(QObject *caller, const QString &comment, const QString &id);
///
/// @brief Accept a token request by id, generate token and inform token caller
/// @param id The id of the request
/// @return True on success, false if not found
/// @brief Cancel a pending token request with the provided comment and id as identifier helper
/// @param caller The QObject of the caller to deliver the reply
/// @param comment The comment as ident helper
/// @param id The id created by the caller
///
bool acceptTokenRequest(const QString& id);
void cancelNewTokenRequest(QObject *caller, const QString &comment, const QString &id);
///
/// @brief Deny a token request by id, inform the requester
/// @brief Handle a token request by id, generate token and inform token caller or deny
/// @param id The id of the request
/// @return True on success, false if not found
/// @param accept The accept or deny the request
///
bool denyTokenRequest(const QString& id);
void handlePendingTokenRequest(const QString &id, const bool &accept);
///
/// @brief Get pending requests
/// @return All pending requests
///
const QMap<QString, AuthDefinition> getPendingRequests();
QVector<AuthManager::AuthDefinition> getPendingRequests();
///
/// @brief Delete a token by id
/// @param id The token id
/// @return True on success else false (or not found)
/// @brief Get the current valid token for user. Make sure this call is allowed!
/// @param usr the defined user
/// @return The token
///
bool deleteToken(const QString& id);
const QString getUserToken(const QString &usr = "Hyperion");
/// Pointer of this instance
static AuthManager* manager;
/// Get Pointer of this instance
static AuthManager* getInstance() { return manager; };
///
/// @brief Get all available token entries
///
QVector<AuthManager::AuthDefinition> getTokenList();
public slots:
///
/// @brief Handle settings update from Hyperion Settingsmanager emit
/// @param type settings type from enum
/// @param config configuration object
///
void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
void handleSettingsUpdate(const settings::type &type, const QJsonDocument &config);
signals:
///
/// @brief Emits whenever a new token Request has been created along with the id and comment
/// @param id The id of the request
/// @param comment The comment of the request
/// @param comment The comment of the request; If the comment is EMPTY, it's a revoke of the caller!
///
void newPendingTokenRequest(const QString& id, const QString& comment);
void newPendingTokenRequest(const QString &id, const QString &comment);
///
/// @brief Emits when the user has accepted or denied a token
@@ -195,26 +200,32 @@ signals:
/// @param comment The comment that was part of the request
/// @param id The id that was part of the request
///
void tokenResponse(const bool& success, QObject* caller, const QString& token, const QString& comment, const QString& id);
void tokenResponse(const bool &success, QObject *caller, const QString &token, const QString &comment, const QString &id);
///
/// @brief Emits whenever the token list changes
/// @param data The full list of tokens
///
void tokenChange(QVector<AuthManager::AuthDefinition>);
private:
///
/// @brief Increment counter for token/user auth
/// @param user If true we increment USER auth instead of token
///
void setAuthBlock(const bool& user = false);
void setAuthBlock(const bool &user = false);
/// Database interface for auth table
AuthTable* _authTable;
AuthTable *_authTable;
/// Database interface for meta table
MetaTable* _metaTable;
MetaTable *_metaTable;
/// Unique ID (imported from removed class 'Stats')
QString _uuid;
/// All pending requests
QMap<QString,AuthDefinition> _pendingRequests;
QMap<QString, AuthDefinition> _pendingRequests;
/// Reflect state of global auth
bool _authRequired;
@@ -226,10 +237,10 @@ private:
bool _localAdminAuthRequired;
/// Timer for counting against pendingRequest timeouts
QTimer* _timer;
QTimer *_timer;
// Timer which cleans up the block counter
QTimer* _authBlockTimer;
QTimer *_authBlockTimer;
// Contains timestamps of failed user login attempts
QVector<uint64_t> _userAuthAttempts;
@@ -247,4 +258,4 @@ private slots:
/// @brief Check if there are timeouts for failed login attempts
///
void checkAuthBlockTimeout();
};
};

View File

@@ -78,35 +78,8 @@ public:
///
void freeObjects(bool emitCloseSignal=false);
///
/// @brief Get a pointer to the effect engine
/// @return EffectEngine instance pointer
///
EffectEngine* getEffectEngineInstance() { return _effectEngine; };
///
/// @brief Get a pointer to the priorityMuxer instance
/// @return PriorityMuxer instance pointer
///
PriorityMuxer* getMuxerInstance() { return &_muxer; };
ImageProcessor* getImageProcessor() { return _imageProcessor; };
///
/// @brief Get a setting by settings::type from SettingsManager
/// @param type The settingsType from enum
/// @return Data Document
///
QJsonDocument getSetting(const settings::type& type);
///
/// @brief Save a complete json config
/// @param config The entire config object
/// @param correct If true will correct json against schema before save
/// @return True on success else false
///
bool saveSettings(QJsonObject config, const bool& correct = false);
///
/// @brief Get instance index of this instance
/// @return The index of this instance
@@ -123,103 +96,6 @@ public:
///
QSize getLedGridSize() const { return _ledGridSize; };
///
/// Returns the current priority
///
/// @return The current priority
///
int getCurrentPriority() const;
///
/// Returns true if current priority is given priority
///
/// @return bool
///
bool isCurrentPriority(const int priority) const;
///
/// Returns a list of all registered priorities
///
/// @return The list with priorities
///
QList<int> getActivePriorities() const;
///
/// Returns the information of a specific priorrity channel
///
/// @param[in] priority The priority channel
///
/// @return The information of the given, a not found priority will return lowest priority as fallback
///
const InputInfo getPriorityInfo(const int priority) const;
///
/// @brief Save an effect
/// @param obj The effect args
/// @param[out] resultMsg The feedback message
/// @return True on success else false
///
bool saveEffect(const QJsonObject& obj, QString& resultMsg);
///
/// @brief Delete an effect by name.
/// @param[in] effectName The effect name to delete
/// @param[out] resultMsg The message on error
/// @return True on success else false
///
bool deleteEffect(const QString& effectName, QString& resultMsg);
/// Get the list of available effects
/// @return The list of available effects
const std::list<EffectDefinition> &getEffects() const;
/// Get the list of active effects
/// @return The list of active effects
const std::list<ActiveEffectDefinition> &getActiveEffects();
/// Get the list of available effect schema files
/// @return The list of available effect schema files
const std::list<EffectSchema> &getEffectSchemas();
/// gets the current json config object from SettingsManager
/// @return json config
const QJsonObject& getQJsonConfig();
/// enable/disable automatic/priorized source selection
/// @param enabled the state
void setSourceAutoSelectEnabled(bool enabled);
/// set current input source to visible
/// @param priority the priority channel which should be vidible
/// @return true if success, false on error
bool setCurrentSourcePriority(int priority );
/// gets current state of automatic/priorized source selection
/// @return the state
bool sourceAutoSelectEnabled();
///
/// @brief Called from components to update their current state. DO NOT CALL FROM USERS
/// @param[in] component The component from enum
/// @param[in] state The state of the component [true | false]
///
void setNewComponentState(const hyperion::Components& component, const bool& state);
///
/// @brief Get a list of all contrable components and their current state
/// @return list of components
///
std::map<hyperion::Components, bool> getAllComponents();
///
/// @brief Test if a component is enabled
/// @param The component to test
/// @return Component state
///
int isComponentEnabled(const hyperion::Components& comp);
ComponentRegister& getComponentRegister() { return _componentRegister; };
/// gets the methode how image is maped to leds
const int & getLedMappingType();
@@ -244,6 +120,7 @@ public:
LedDevice * getActiveDevice() const;
public slots:
///
/// @brief Register a new input by priority, the priority is not active (timeout -100 isn't muxer recognized) until you start to update the data with setInput()
/// A repeated call to update the base data of a known priority won't overwrite their current timeout
@@ -322,6 +199,28 @@ public slots:
///
bool clear(const int priority, bool forceClearAll=false);
/// #############
// EFFECTENGINE
///
/// @brief Get a pointer to the effect engine
/// @return EffectEngine instance pointer
///
EffectEngine* getEffectEngineInstance() { return _effectEngine; };
///
/// @brief Save an effect
/// @param obj The effect args
/// @return Empty on success else error message
///
QString saveEffect(const QJsonObject& obj);
///
/// @brief Delete an effect by name.
/// @param effectName The effect name to delete
/// @return Empty on success else error message
///
QString deleteEffect(const QString& effectName);
/// Run the specified effect on the given priority channel and optionally specify a timeout
/// @param effectName Name of the effec to run
/// @param priority The priority channel of the effect
@@ -342,6 +241,122 @@ public slots:
, const QString &imageData = ""
);
/// Get the list of available effects
/// @return The list of available effects
const std::list<EffectDefinition> &getEffects() const;
/// Get the list of active effects
/// @return The list of active effects
const std::list<ActiveEffectDefinition> &getActiveEffects();
/// Get the list of available effect schema files
/// @return The list of available effect schema files
const std::list<EffectSchema> &getEffectSchemas();
/// #############
/// PRIORITYMUXER
///
/// @brief Get a pointer to the priorityMuxer instance
/// @return PriorityMuxer instance pointer
///
PriorityMuxer* getMuxerInstance() { return &_muxer; };
///
/// @brief enable/disable automatic/priorized source selection
/// @param state The new state
///
void setSourceAutoSelect(const bool state);
///
/// @brief set current input source to visible
/// @param priority the priority channel which should be vidible
/// @return true if success, false on error
///
bool setVisiblePriority(const int& priority);
/// gets current state of automatic/priorized source selection
/// @return the state
bool sourceAutoSelectEnabled();
///
/// Returns the current priority
///
/// @return The current priority
///
int getCurrentPriority() const;
///
/// Returns true if current priority is given priority
///
/// @return bool
///
bool isCurrentPriority(const int priority) const;
///
/// Returns a list of all registered priorities
///
/// @return The list with priorities
///
QList<int> getActivePriorities() const;
///
/// Returns the information of a specific priorrity channel
///
/// @param[in] priority The priority channel
///
/// @return The information of the given, a not found priority will return lowest priority as fallback
///
const InputInfo getPriorityInfo(const int priority) const;
/// #############
/// SETTINGSMANAGER
///
/// @brief Get a setting by settings::type from SettingsManager
/// @param type The settingsType from enum
/// @return Data Document
///
QJsonDocument getSetting(const settings::type& type);
/// gets the current json config object from SettingsManager
/// @return json config
const QJsonObject& getQJsonConfig();
///
/// @brief Save a complete json config
/// @param config The entire config object
/// @param correct If true will correct json against schema before save
/// @return True on success else false
///
bool saveSettings(QJsonObject config, const bool& correct = false);
/// ############
/// COMPONENTREGISTER
///
/// @brief Get the component Register
/// return Component register pointer
///
ComponentRegister& getComponentRegister() { return _componentRegister; };
///
/// @brief Called from components to update their current state. DO NOT CALL FROM USERS
/// @param[in] component The component from enum
/// @param[in] state The state of the component [true | false]
///
void setNewComponentState(const hyperion::Components& component, const bool& state);
///
/// @brief Get a list of all contrable components and their current state
/// @return list of components
///
std::map<hyperion::Components, bool> getAllComponents();
///
/// @brief Test if a component is enabled
/// @param The component to test
/// @return Component state
///
int isComponentEnabled(const hyperion::Components& comp);
/// sets the methode how image is maped to leds at ImageProcessor
void setLedMappingType(const int& mappingType);

View File

@@ -32,6 +32,7 @@ public:
static HyperionIManager* getInstance() { return HIMinstance; };
static HyperionIManager* HIMinstance;
public slots:
///
/// @brief Is given instance running?
/// @param inst The instance to check