Skip to content

Commit

Permalink
Fix issues #1022, #1019, #997, #993, #992, #976, #969, #964, #980 (#1036
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Paulchen-Panther authored Oct 18, 2020
1 parent 9d2e442 commit aa465c0
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ compile_commands.json
# Autogenerated by flatbuffers
libsrc/flatbufserver/hyperion_reply_generated.h
libsrc/flatbufserver/hyperion_request_generated.h

# Kdevelop project files
*.kdev*
31 changes: 16 additions & 15 deletions include/api/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ class API : public QObject
/// @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
/// @return True on success else false
///
void setEffect(const EffectCmdData &dat, hyperion::Components callerComp = hyperion::COMP_INVALID);
bool setEffect(const EffectCmdData &dat, hyperion::Components callerComp = hyperion::COMP_INVALID);

///
/// @brief Set source auto select enabled or disabled
Expand Down Expand Up @@ -174,8 +175,10 @@ class API : public QObject
///
/// @brief Start instance
/// @param index The instance index
/// @param tan The tan
/// @return True on success else false
///
void startInstance(quint8 index);
bool startInstance(quint8 index, int tan = 0);

///
/// @brief Stop instance
Expand Down Expand Up @@ -277,8 +280,9 @@ class API : public QObject
/// @brief Set a new token request
/// @param comment The comment
/// @param id The id
/// @param tan The tan
///
void setNewTokenRequest(const QString &comment, const QString &id);
void setNewTokenRequest(const QString &comment, const QString &id, const int &tan);

///
/// @brief Cancel new token request
Expand Down Expand Up @@ -367,7 +371,7 @@ class API : public QObject

///
/// @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 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);
Expand All @@ -378,8 +382,15 @@ class API : public QObject
/// @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
/// @param tan The tan that was part of the request
///
void onTokenResponse(bool success, const QString &token, const QString &comment, const QString &id, const int &tan);

///
void onTokenResponse(bool success, const QString &token, const QString &comment, const QString &id);
/// @brief Handle emits from HyperionIManager of startInstance request, just if QObject matches with this instance it will emit.
/// @param tan The tan that was part of the request
///
void onStartInstanceResponse(const int &tan);

private slots:
///
Expand All @@ -388,16 +399,6 @@ private slots:
///
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(bool success, QObject *caller, const QString &token, const QString &comment, const QString &id);

private:
void stopDataConnectionss();

Expand Down
7 changes: 4 additions & 3 deletions include/api/JsonAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public slots:
private slots:
///
/// @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
/// @param id The id of the request
/// @param comment The comment which needs to be accepted
///
void newPendingTokenRequest(const QString &id, const QString &comment);

Expand All @@ -76,8 +76,9 @@ private slots:
/// @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
/// @param tan The tan that was part of the request
///
void handleTokenResponse(bool success, const QString &token, const QString &comment, const QString &id);
void handleTokenResponse(bool success, const QString &token, const QString &comment, const QString &id, const int &tan);

///
/// @brief Handle whenever the state of a instance (HyperionIManager) changes according to enum instanceState
Expand Down
10 changes: 6 additions & 4 deletions include/hyperion/AuthManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AuthManager : public QObject
QString id;
QString comment;
QObject *caller;
int tan;
uint64_t timeoutTime;
QString token;
QString lastUse;
Expand Down Expand Up @@ -142,16 +143,16 @@ public slots:
/// @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
/// @param tan The tan created by the caller
///
void setNewTokenRequest(QObject *caller, const QString &comment, const QString &id);
void setNewTokenRequest(QObject *caller, const QString &comment, const QString &id, const int &tan = 0);

///
/// @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
///
void cancelNewTokenRequest(QObject *caller, const QString &comment, const QString &id);
void cancelNewTokenRequest(QObject *caller, const QString &, const QString &id);

///
/// @brief Handle a token request by id, generate token and inform token caller or deny
Expand Down Expand Up @@ -200,8 +201,9 @@ public slots:
/// @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
/// @param tan The tan that was part of the request
///
void tokenResponse(bool success, QObject *caller, const QString &token, const QString &comment, const QString &id);
void tokenResponse(bool success, QObject *caller, const QString &token, const QString &comment, const QString &id, const int &tan);

///
/// @brief Emits whenever the token list changes
Expand Down
21 changes: 18 additions & 3 deletions include/hyperion/HyperionIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class HyperionIManager : public QObject
Q_OBJECT

public:
struct PendingRequests
{
QObject *caller;
int tan;
};

// global instance pointer
static HyperionIManager* getInstance() { return HIMinstance; }
static HyperionIManager* HIMinstance;
Expand All @@ -54,11 +60,11 @@ public slots:

///
/// @brief Start a Hyperion instance
/// @param instance Instance index
/// @param block If true return when thread has been started
/// @param instance Instance index
/// @param block If true return when thread has been started
/// @return Return true on success, false if not found in db
///
bool startInstance(quint8 inst, bool block = false);
bool startInstance(quint8 inst, bool block = false, QObject *caller = nullptr, int tan = 0);

///
/// @brief Stop a Hyperion instance
Expand Down Expand Up @@ -110,6 +116,13 @@ public slots:
///
void change();

///
/// @brief Emits when the user has requested to start a instance
/// @param caller The origin caller instance who requested
/// @param tan The tan that was part of the request
///
void startInstanceResponse(QObject *caller, const int &tan);

signals:
///////////////////////////////////////
/// FROM HYPERIONDAEMON TO HYPERION ///
Expand Down Expand Up @@ -180,4 +193,6 @@ private slots:
const QString _rootPath;
QMap<quint8, Hyperion*> _runningInstances;
QList<quint8> _startQueue;
/// All pending requests
QMap<quint8, PendingRequests> _pendingRequests;
};
2 changes: 1 addition & 1 deletion include/ssdp/SSDPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SSDPHandler : public SSDPServer
{
Q_OBJECT
public:
SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 jsonServerPort, const QString &name, QObject * parent = nullptr);
SSDPHandler(WebServer* webserver, quint16 flatBufPort, quint16 protoBufPort, quint16 jsonServerPort, quint16 sslPort, const QString &name, QObject * parent = nullptr);
~SSDPHandler() override;

///
Expand Down
42 changes: 32 additions & 10 deletions include/ssdp/SSDPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,36 @@ class SSDPServer : public QObject
quint16 getFlatBufPort() const { return _fbsPort.toInt(); };

///
/// @brief set new jsonserver server port
/// @brief set new protobuf server port
///
void setProtoBufPort(quint16 port) { _pbsPort = QString::number(port); };

///
/// @brief Get current protobuf server port
///
quint16 getProtoBufPort() const { return _pbsPort.toInt(); };

///
/// @brief set new json server port
///
void setJsonServerPort(quint16 port) { _jssPort = QString::number(port); };

///
/// @brief get new jsonserver server port
/// @brief get new json server port
///
quint16 getJsonServerPort() const { return _jssPort.toInt(); };

///
///
/// @brief set new ssl server port
///
void setSSLServerPort(quint16 port) { _sslPort = QString::number(port); };

///
/// @brief get new ssl server port
///
quint16 getSSLServerPort() const { return _sslPort.toInt(); };

///
/// @brief set new hyperion name
///
void setHyperionName(const QString &name) { _name = name; };
Expand All @@ -119,13 +139,15 @@ class SSDPServer : public QObject
Logger* _log;
QUdpSocket* _udpSocket;

QString _serverHeader;
QString _uuid;
QString _fbsPort;
QString _jssPort;
QString _name;
QString _descAddress;
bool _running;
QString _serverHeader,
_uuid,
_fbsPort,
_pbsPort,
_jssPort,
_sslPort,
_name,
_descAddress;
bool _running;

private slots:
void readPendingDatagrams();
Expand Down
50 changes: 31 additions & 19 deletions libsrc/api/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ API::API(Logger *log, bool localConnection, QObject *parent)
//connect(ApiSync::getInstance(), &ApiSync::requestActiveRegister, this, &API::requestActiveRegister, Qt::QueuedConnection);

// connect to possible token responses that has been requested
connect(_authManager, &AuthManager::tokenResponse, this, &API::checkTokenResponse);
connect(_authManager, &AuthManager::tokenResponse, [=] (bool success, QObject *caller, const QString &token, const QString &comment, const QString &id, const int &tan)
{
if (this == caller)
emit onTokenResponse(success, token, comment, id, tan);
});

// connect to possible startInstance responses that has been requested
connect(_instanceManager, &HyperionIManager::startInstanceResponse, [=] (QObject *caller, const int &tan)
{
if (this == caller)
emit onStartInstanceResponse(tan);
});
}

void API::init()
Expand Down Expand Up @@ -211,16 +222,19 @@ void API::setVideoMode(VideoMode mode, hyperion::Components callerComp)
QMetaObject::invokeMethod(_hyperion, "setVideoMode", Qt::QueuedConnection, Q_ARG(VideoMode, mode));
}

void API::setEffect(const EffectCmdData &dat, hyperion::Components callerComp)
bool API::setEffect(const EffectCmdData &dat, hyperion::Components callerComp)
{
int res;
if (!dat.args.isEmpty())
{
QMetaObject::invokeMethod(_hyperion, "setEffect", Qt::QueuedConnection, Q_ARG(QString, dat.effectName), Q_ARG(QJsonObject, dat.args), Q_ARG(int, dat.priority), Q_ARG(int, dat.duration), Q_ARG(QString, dat.pythonScript), Q_ARG(QString, dat.origin), Q_ARG(QString, dat.data));
QMetaObject::invokeMethod(_hyperion, "setEffect", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, res), Q_ARG(QString, dat.effectName), Q_ARG(QJsonObject, dat.args), Q_ARG(int, dat.priority), Q_ARG(int, dat.duration), Q_ARG(QString, dat.pythonScript), Q_ARG(QString, dat.origin), Q_ARG(QString, dat.data));
}
else
{
QMetaObject::invokeMethod(_hyperion, "setEffect", Qt::QueuedConnection, Q_ARG(QString, dat.effectName), Q_ARG(int, dat.priority), Q_ARG(int, dat.duration), Q_ARG(QString, dat.origin));
QMetaObject::invokeMethod(_hyperion, "setEffect", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, res), Q_ARG(QString, dat.effectName), Q_ARG(int, dat.priority), Q_ARG(int, dat.duration), Q_ARG(QString, dat.origin));
}

return res >= 0;
}

void API::setSourceAutoSelect(bool state, hyperion::Components callerComp)
Expand Down Expand Up @@ -285,9 +299,14 @@ QVector<QVariantMap> API::getAllInstanceData()
return vec;
}

void API::startInstance(quint8 index)
bool API::startInstance(quint8 index, int tan)
{
QMetaObject::invokeMethod(_instanceManager, "startInstance", Qt::QueuedConnection, Q_ARG(quint8, index));
bool res;
(_instanceManager->thread() != this->thread())
? QMetaObject::invokeMethod(_instanceManager, "startInstance", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(quint8, index), Q_ARG(bool, false), Q_ARG(QObject*, this), Q_ARG(int, tan))
: res = _instanceManager->startInstance(index, false, this, tan);

return res;
}

void API::stopInstance(quint8 index)
Expand Down Expand Up @@ -407,9 +426,9 @@ QString API::deleteToken(const QString &id)
return "";
}

void API::setNewTokenRequest(const QString &comment, const QString &id)
void API::setNewTokenRequest(const QString &comment, const QString &id, const int &tan)
{
QMetaObject::invokeMethod(_authManager, "setNewTokenRequest", Qt::QueuedConnection, Q_ARG(QObject *, this), Q_ARG(QString, comment), Q_ARG(QString, id));
QMetaObject::invokeMethod(_authManager, "setNewTokenRequest", Qt::QueuedConnection, Q_ARG(QObject *, this), Q_ARG(QString, comment), Q_ARG(QString, id), Q_ARG(int, tan));
}

void API::cancelNewTokenRequest(const QString &comment, const QString &id)
Expand Down Expand Up @@ -465,12 +484,11 @@ bool API::getUserToken(QString &userToken)

bool API::isTokenAuthorized(const QString &token)
{
bool res;
QMetaObject::invokeMethod(_authManager, "isTokenAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, res), Q_ARG(QString, token));
if (res)
_authorized = true;
(_authManager->thread() != this->thread())
? QMetaObject::invokeMethod(_authManager, "isTokenAuthorized", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, _authorized), Q_ARG(QString, token))
: _authorized = _authManager->isTokenAuthorized(token);

return res;
return _authorized;
}

bool API::isUserAuthorized(const QString &password)
Expand Down Expand Up @@ -503,12 +521,6 @@ void API::logout()
stopDataConnectionss();
}

void API::checkTokenResponse(bool success, QObject *caller, const QString &token, const QString &comment, const QString &id)
{
if (this == caller)
emit onTokenResponse(success, token, comment, id);
}

void API::stopDataConnectionss()
{
}
Loading

0 comments on commit aa465c0

Please sign in to comment.