From cacfbada7a59d7a0194f1c7c65ec756bcc920ef2 Mon Sep 17 00:00:00 2001 From: Paulchen-Panther Date: Fri, 2 Aug 2019 21:12:13 +0200 Subject: [PATCH] The WebUI remote page has been rearranged Set interuption flag to running effects when hyperion emits finished signal Protobuffer, Flatbuffer and Boblight connection priority check to avoid unwanted program behavior Signed-off-by: Paulchen-Panther --- assets/webconfig/content/remote.html | 14 +++---- .../BoblightClientConnection.cpp | 41 ++++++++++++++----- libsrc/effectengine/EffectEngine.cpp | 3 +- libsrc/flatbufserver/FlatBufferClient.cpp | 14 +++++-- libsrc/flatbufserver/FlatBufferClient.h | 3 +- libsrc/flatbufserver/FlatBufferConnection.cpp | 3 ++ libsrc/protoserver/ProtoClientConnection.cpp | 18 +++++--- libsrc/protoserver/ProtoClientConnection.h | 3 +- 8 files changed, 66 insertions(+), 33 deletions(-) diff --git a/assets/webconfig/content/remote.html b/assets/webconfig/content/remote.html index 6bf020ce..292fdf91 100644 --- a/assets/webconfig/content/remote.html +++ b/assets/webconfig/content/remote.html @@ -68,13 +68,6 @@ -
-
-
-
-
-
-
@@ -83,6 +76,13 @@
+
+
+
+
+
+
+
diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index 7099079e..71a1b231 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -44,8 +44,9 @@ BoblightClientConnection::BoblightClientConnection(Hyperion* hyperion, QTcpSocke BoblightClientConnection::~BoblightClientConnection() { - // clear the current channel - _hyperion->clear(_priority); + // clear the current channel + if (_priority != 0 && _priority >= 128 && _priority < 254) + _hyperion->clear(_priority); delete _socket; } @@ -79,8 +80,9 @@ void BoblightClientConnection::readData() void BoblightClientConnection::socketClosed() { - // clear the current channel - _hyperion->clear(_priority); + // clear the current channel + if (_priority != 0 && _priority >= 128 && _priority < 254) + _hyperion->clear(_priority); emit connectionClosed(this); } @@ -155,6 +157,9 @@ void BoblightClientConnection::handleMessage(const QString & message) rgb.green = green; rgb.blue = blue; + if (_priority == 0 || _priority < 128 || _priority >= 254) + return; + // send current color values to hyperion if this is the last led assuming leds values are send in order of id if (ledIndex == _ledColors.size() -1) { @@ -180,21 +185,35 @@ void BoblightClientConnection::handleMessage(const QString & message) int prio = messageParts[2].toInt(&rc); if (rc && prio != _priority) { - // clear the current channel - _hyperion->clear(_priority); + if (_priority != 0 && _hyperion->getPriorityInfo(_priority).componentId == hyperion::COMP_BOBLIGHTSERVER) + _hyperion->clear(_priority); - // register new priority - _hyperion->registerInput(prio, hyperion::COMP_BOBLIGHTSERVER, QString("Boblight@%1").arg(_socket->peerAddress().toString())); + if (prio < 128 || prio >= 254) + { + _priority = 128; + while (_hyperion->getActivePriorities().contains(_priority)) + { + _priority += 1; + } + + Warning(_log, "The priority %i is not in the priority range between 128 and 253. Priority %i is used instead.", prio, _priority); + } + else + { + // register new priority + _hyperion->registerInput(prio, hyperion::COMP_BOBLIGHTSERVER, QString("Boblight@%1").arg(_socket->peerAddress().toString())); + _priority = prio; + } - _priority = prio; return; } } } else if (messageParts[0] == "sync") { - // send current color values to hyperion - _hyperion->setInput(_priority, _ledColors); + if (_priority != 0 && _priority >= 128 && _priority < 254) + _hyperion->setInput(_priority, _ledColors); // send current color values to hyperion + return; } } diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 8e781663..b64eb62a 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -168,10 +168,11 @@ int EffectEngine::runEffectScript(const QString &script, const QString &name, co channelCleared(priority); // create the effect - Effect *effect = new Effect(_hyperion, priority, timeout, script, name, args, imageData); + Effect *effect = new Effect(_hyperion, priority, timeout, script, name, args, imageData); connect(effect, &Effect::setInput, _hyperion, &Hyperion::setInput, Qt::QueuedConnection); connect(effect, &Effect::setInputImage, _hyperion, &Hyperion::setInputImage, Qt::QueuedConnection); connect(effect, &QThread::finished, this, &EffectEngine::effectFinished); + connect(_hyperion, &Hyperion::finished, effect, &Effect::setInteruptionFlag, Qt::DirectConnection); _activeEffects.push_back(effect); // start the effect diff --git a/libsrc/flatbufserver/FlatBufferClient.cpp b/libsrc/flatbufserver/FlatBufferClient.cpp index c0fe674b..6ad88217 100644 --- a/libsrc/flatbufserver/FlatBufferClient.cpp +++ b/libsrc/flatbufserver/FlatBufferClient.cpp @@ -6,9 +6,6 @@ #include #include -#include -#include - FlatBufferClient::FlatBufferClient(QTcpSocket* socket, const int &timeout, QObject *parent) : QObject(parent) , _log(Logger::getInstance("FLATBUFSERVER")) @@ -72,7 +69,9 @@ void FlatBufferClient::disconnected() { Debug(_log, "Socket Closed"); _socket->deleteLater(); - emit clearGlobalInput(_priority); + if (_priority != 0 && _priority >= 100 && _priority < 200) + emit clearGlobalInput(_priority); + emit clientDisconnected(); } @@ -122,6 +121,13 @@ void FlatBufferClient::registationRequired(const int priority) void FlatBufferClient::handleRegisterCommand(const hyperionnet::Register *regReq) { + if (regReq->priority() < 100 || regReq->priority() >= 200) + { + // Warning(_log, "Register request from client %s contains invalid priority %d. Valid rage is between 100 and 199.", QSTRING_CSTR(_clientAddress), regReq->priority()); + sendErrorReply("The priority " + std::to_string(regReq->priority()) + " is not in the priority range between 100 and 199."); + return; + } + _priority = regReq->priority(); emit registerGlobalInput(_priority, hyperion::COMP_FLATBUFSERVER, regReq->origin()->c_str()+_clientAddress); diff --git a/libsrc/flatbufserver/FlatBufferClient.h b/libsrc/flatbufserver/FlatBufferClient.h index a9a2515b..7cb678c7 100644 --- a/libsrc/flatbufserver/FlatBufferClient.h +++ b/libsrc/flatbufserver/FlatBufferClient.h @@ -12,10 +12,9 @@ class QTcpSocket; class QTimer; -class Hyperion; namespace flatbuf { -class HyperionRequest; + class HyperionRequest; } /// diff --git a/libsrc/flatbufserver/FlatBufferConnection.cpp b/libsrc/flatbufserver/FlatBufferConnection.cpp index c2a590f2..07e8a1b1 100644 --- a/libsrc/flatbufserver/FlatBufferConnection.cpp +++ b/libsrc/flatbufserver/FlatBufferConnection.cpp @@ -217,5 +217,8 @@ bool FlatBufferConnection::parseReply(const hyperionnet::Reply *reply) return true; } + else + throw std::runtime_error(reply->error()->str()); + return false; } diff --git a/libsrc/protoserver/ProtoClientConnection.cpp b/libsrc/protoserver/ProtoClientConnection.cpp index e2ccf52d..d7cd13b9 100644 --- a/libsrc/protoserver/ProtoClientConnection.cpp +++ b/libsrc/protoserver/ProtoClientConnection.cpp @@ -7,12 +7,6 @@ #include #include -// Hyperion includes -#include - -// Hyperion instance manager includes -#include - // TODO Remove this class if third-party apps have been migrated (eg. Hyperion Android Gabber, Windows Screen grabber etc.) ProtoClientConnection::ProtoClientConnection(QTcpSocket* socket, const int &timeout, QObject *parent) @@ -130,6 +124,12 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag color.green = qGreen(message.rgbcolor()); color.blue = qBlue(message.rgbcolor()); + if (priority < 100 || priority >= 200) + { + sendErrorReply("The priority " + std::to_string(priority) + " is not in the priority range between 100 and 199."); + return; + } + // make sure the prio is registered before setColor() if(priority != _priority) { @@ -154,6 +154,12 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag int height = message.imageheight(); const std::string & imageData = message.imagedata(); + if (priority < 100 || priority >= 200) + { + sendErrorReply("The priority " + std::to_string(priority) + " is not in the priority range between 100 and 199."); + return; + } + // make sure the prio is registered before setInput() if(priority != _priority) { diff --git a/libsrc/protoserver/ProtoClientConnection.h b/libsrc/protoserver/ProtoClientConnection.h index 8b6c285d..ef88314f 100644 --- a/libsrc/protoserver/ProtoClientConnection.h +++ b/libsrc/protoserver/ProtoClientConnection.h @@ -11,10 +11,9 @@ class QTcpSocket; class QTimer; -class Hyperion; namespace proto { -class HyperionRequest; + class HyperionRequest; } ///