mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Proto- and Flatbuffer now share their input to all instances
Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
@@ -17,7 +17,6 @@ FlatBufferClient::FlatBufferClient(QTcpSocket* socket, const int &timeout, QObje
|
||||
, _timeoutTimer(new QTimer(this))
|
||||
, _timeout(timeout * 1000)
|
||||
, _priority()
|
||||
, _hyperion(HyperionIManager::getInstance()->getHyperionInstance())
|
||||
{
|
||||
// timer setup
|
||||
_timeoutTimer->setSingleShot(true);
|
||||
@@ -72,8 +71,8 @@ void FlatBufferClient::forceClose()
|
||||
void FlatBufferClient::disconnected()
|
||||
{
|
||||
Debug(_log, "Socket Closed");
|
||||
_socket->deleteLater();
|
||||
_hyperion->clear(_priority);
|
||||
_socket->deleteLater();
|
||||
emit clearGlobalInput(_priority);
|
||||
emit clientDisconnected();
|
||||
}
|
||||
|
||||
@@ -103,16 +102,28 @@ void FlatBufferClient::handleColorCommand(const hyperionnet::Color *colorReq)
|
||||
color.blue = qBlue(rgbData);
|
||||
|
||||
// set output
|
||||
_hyperion->setColor(_priority, color, colorReq->duration());
|
||||
emit setGlobalInputColor(_priority, color, colorReq->duration());
|
||||
|
||||
// send reply
|
||||
sendSuccessReply();
|
||||
}
|
||||
|
||||
void FlatBufferClient::registationRequired(const int priority)
|
||||
{
|
||||
if (_priority == priority)
|
||||
{
|
||||
auto reply = hyperionnet::CreateReplyDirect(_builder, nullptr, -1, -1);
|
||||
_builder.Finish(reply);
|
||||
|
||||
// send reply
|
||||
sendMessage();
|
||||
}
|
||||
}
|
||||
|
||||
void FlatBufferClient::handleRegisterCommand(const hyperionnet::Register *regReq)
|
||||
{
|
||||
_priority = regReq->priority();
|
||||
_hyperion->registerInput(_priority, hyperion::COMP_FLATBUFSERVER, regReq->origin()->c_str()+_clientAddress);
|
||||
emit registerGlobalInput(_priority, hyperion::COMP_FLATBUFSERVER, regReq->origin()->c_str()+_clientAddress);
|
||||
|
||||
auto reply = hyperionnet::CreateReplyDirect(_builder, nullptr, -1, (_priority ? _priority : -1));
|
||||
_builder.Finish(reply);
|
||||
@@ -142,7 +153,7 @@ void FlatBufferClient::handleImageCommand(const hyperionnet::Image *image)
|
||||
|
||||
Image<ColorRgb> imageDest(width, height);
|
||||
memmove(imageDest.memptr(), imageData->data(), imageData->size());
|
||||
_hyperion->setInputImage(_priority, imageDest, duration);
|
||||
emit setGlobalInputImage(_priority, imageDest, duration);
|
||||
}
|
||||
|
||||
// send reply
|
||||
@@ -156,7 +167,7 @@ void FlatBufferClient::handleClearCommand(const hyperionnet::Clear *clear)
|
||||
const int priority = clear->priority();
|
||||
|
||||
if (priority == -1) {
|
||||
_hyperion->clearall();
|
||||
emit clearAllGlobalInput();
|
||||
}
|
||||
else {
|
||||
// Check if we are clearing ourselves.
|
||||
@@ -164,7 +175,7 @@ void FlatBufferClient::handleClearCommand(const hyperionnet::Clear *clear)
|
||||
_priority = -1;
|
||||
}
|
||||
|
||||
_hyperion->clear(priority);
|
||||
emit clearGlobalInput(priority);
|
||||
}
|
||||
|
||||
sendSuccessReply();
|
||||
|
@@ -37,12 +37,27 @@ signals:
|
||||
///
|
||||
/// @brief forward register data to HyperionDaemon
|
||||
///
|
||||
void registerGlobalInput(const int priority, const hyperion::Components& component, const QString& origin = "System", const QString& owner = "", unsigned smooth_cfg = 0);
|
||||
void registerGlobalInput(const int priority, const hyperion::Components& component, const QString& origin = "FlatBuffer", const QString& owner = "", unsigned smooth_cfg = 0);
|
||||
|
||||
///
|
||||
/// @brief Forward clear command to HyperionDaemon
|
||||
///
|
||||
void clearGlobalInput(const int priority);
|
||||
|
||||
///
|
||||
/// @brief Forward clearAll command to HyperionDaemon
|
||||
///
|
||||
void clearAllGlobalInput(bool forceClearAll=false);
|
||||
|
||||
///
|
||||
/// @brief forward prepared image to HyperionDaemon
|
||||
///
|
||||
const bool setGlobalInputImage(const int priority, const Image<ColorRgb>& image, const int timeout_ms = -1);
|
||||
const bool setGlobalInputImage(const int priority, const Image<ColorRgb>& image, const int timeout_ms, const bool& clearEffect = false);
|
||||
|
||||
///
|
||||
/// @brief Forward requested color
|
||||
///
|
||||
void setGlobalInputColor(const int priority, const ColorRgb &ledColor, const int timeout_ms, const QString& origin = "FlatBuffer" ,bool clearEffects = true);
|
||||
|
||||
///
|
||||
/// @brief Emits whenever the client disconnected
|
||||
@@ -50,6 +65,11 @@ signals:
|
||||
void clientDisconnected();
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// @brief Requests a registration from the client
|
||||
///
|
||||
void registationRequired(const int priority);
|
||||
|
||||
///
|
||||
/// @brief close the socket and call disconnected()
|
||||
///
|
||||
@@ -125,7 +145,6 @@ private:
|
||||
QTimer *_timeoutTimer;
|
||||
int _timeout;
|
||||
int _priority;
|
||||
Hyperion* _hyperion;
|
||||
|
||||
QByteArray _receiveBuffer;
|
||||
|
||||
|
@@ -210,7 +210,7 @@ bool FlatBufferConnection::parseReply(const hyperionnet::Reply *reply)
|
||||
}
|
||||
|
||||
// We got a registered reply.
|
||||
if (registered != -1 && registered != _priority)
|
||||
if (registered == -1 || registered != _priority)
|
||||
_registered = false;
|
||||
else
|
||||
_registered = true;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
// util
|
||||
#include <utils/NetOrigin.h>
|
||||
#include <utils/GlobalSignals.h>
|
||||
|
||||
// qt
|
||||
#include <QJsonObject>
|
||||
@@ -68,6 +69,12 @@ void FlatBufferServer::newConnection()
|
||||
FlatBufferClient *client = new FlatBufferClient(socket, _timeout, this);
|
||||
// internal
|
||||
connect(client, &FlatBufferClient::clientDisconnected, this, &FlatBufferServer::clientDisconnected);
|
||||
connect(client, &FlatBufferClient::registerGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::registerGlobalInput);
|
||||
connect(client, &FlatBufferClient::clearGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::clearGlobalInput);
|
||||
connect(client, &FlatBufferClient::clearAllGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::clearAllGlobalInput);
|
||||
connect(client, &FlatBufferClient::setGlobalInputImage, GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage);
|
||||
connect(client, &FlatBufferClient::setGlobalInputColor, GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::globalRegRequired, client, &FlatBufferClient::registationRequired);
|
||||
_openConnections.append(client);
|
||||
}
|
||||
else
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
// utils
|
||||
#include <utils/hyperion.h>
|
||||
#include <utils/GlobalSignals.h>
|
||||
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDeviceWrapper.h>
|
||||
@@ -133,6 +134,13 @@ void Hyperion::start()
|
||||
// create the Daemon capture interface
|
||||
_captureCont = new CaptureCont(this);
|
||||
|
||||
// forwards global signals to the corresponding slots
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::registerGlobalInput, this, &Hyperion::registerInput);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::clearGlobalInput, this, &Hyperion::clear);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::clearAllGlobalInput, this, &Hyperion::clearall);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor, this, &Hyperion::setColor);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage, this, &Hyperion::setInputImage);
|
||||
|
||||
// if there is no startup / background eff and no sending capture interface we probably want to push once BLACK (as PrioMuxer won't emit a prioritiy change)
|
||||
update();
|
||||
|
||||
@@ -325,6 +333,12 @@ bool Hyperion::setInput(const int priority, const std::vector<ColorRgb>& ledColo
|
||||
|
||||
bool Hyperion::setInputImage(const int priority, const Image<ColorRgb>& image, int64_t timeout_ms, const bool& clearEffect)
|
||||
{
|
||||
if (!_muxer.hasPriority(priority))
|
||||
{
|
||||
emit GlobalSignals::getInstance()->globalRegRequired(priority);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(_muxer.setInputImage(priority, image, timeout_ms))
|
||||
{
|
||||
// clear effect if this call does not come from an effect
|
||||
@@ -345,7 +359,7 @@ bool Hyperion::setInputInactive(const quint8& priority)
|
||||
return _muxer.setInputInactive(priority);
|
||||
}
|
||||
|
||||
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms, const QString& origin, bool clearEffects)
|
||||
void Hyperion::setColor(const int priority, const ColorRgb &color, const int timeout_ms, const QString& origin, bool clearEffects)
|
||||
{
|
||||
// clear effect if this call does not come from an effect
|
||||
if(clearEffects)
|
||||
@@ -379,7 +393,7 @@ void Hyperion::adjustmentsUpdated()
|
||||
update();
|
||||
}
|
||||
|
||||
bool Hyperion::clear(int priority)
|
||||
bool Hyperion::clear(const int priority)
|
||||
{
|
||||
// send clear signal to the effect engine
|
||||
// (outside the check so the effect gets cleared even when the effect is not sending colors)
|
||||
|
@@ -69,17 +69,17 @@ bool HyperionIManager::startInstance(const quint8& inst, const bool& block)
|
||||
// setup thread management
|
||||
connect(hyperionThread, &QThread::started, hyperion, &Hyperion::start);
|
||||
connect(hyperionThread, &QThread::finished, hyperionThread, &QObject::deleteLater);
|
||||
connect(hyperion, &Hyperion::started, HyperionIManager::getInstance(), &HyperionIManager::handleStarted);
|
||||
connect(hyperion, &Hyperion::finished, HyperionIManager::getInstance(), &HyperionIManager::handleFinished);
|
||||
connect(hyperion, &Hyperion::started, this, &HyperionIManager::handleStarted);
|
||||
connect(hyperion, &Hyperion::finished, this, &HyperionIManager::handleFinished);
|
||||
connect(hyperion, &Hyperion::finished, hyperionThread, &QThread::quit, Qt::DirectConnection);
|
||||
|
||||
// setup further connections
|
||||
// from Hyperion
|
||||
connect(hyperion, &Hyperion::settingsChanged, HyperionIManager::getInstance(), &HyperionIManager::settingsChanged);
|
||||
connect(hyperion, &Hyperion::videoMode, HyperionIManager::getInstance(), &HyperionIManager::requestVideoMode);
|
||||
connect(hyperion, &Hyperion::componentStateChanged, HyperionIManager::getInstance(), &HyperionIManager::componentStateChanged);
|
||||
connect(hyperion, &Hyperion::settingsChanged, this, &HyperionIManager::settingsChanged);
|
||||
connect(hyperion, &Hyperion::videoMode, this, &HyperionIManager::requestVideoMode);
|
||||
connect(hyperion, &Hyperion::componentStateChanged, this, &HyperionIManager::componentStateChanged);
|
||||
// to Hyperion
|
||||
connect(HyperionIManager::getInstance(), &HyperionIManager::newVideoMode, hyperion, &Hyperion::newVideoMode);
|
||||
connect(this, &HyperionIManager::newVideoMode, hyperion, &Hyperion::newVideoMode);
|
||||
|
||||
// add to queue and start
|
||||
_startQueue << inst;
|
||||
@@ -103,7 +103,7 @@ bool HyperionIManager::startInstance(const quint8& inst, const bool& block)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HyperionIManager::stopInstance(const quint8& inst, const bool& block)
|
||||
bool HyperionIManager::stopInstance(const quint8& inst)
|
||||
{
|
||||
// inst 0 can't be stopped
|
||||
if(!isInstAllowed(inst))
|
||||
@@ -121,10 +121,6 @@ bool HyperionIManager::stopInstance(const quint8& inst, const bool& block)
|
||||
// update db
|
||||
_instanceTable->setEnable(inst, false);
|
||||
|
||||
if(block)
|
||||
{
|
||||
hyperion->thread()->wait(10000);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Debug(_log,"Can't stop Hyperion instance index '%d' with name '%s' it's not running'", inst, QSTRING_CSTR(_instanceTable->getNamebyIndex(inst)));
|
||||
@@ -157,8 +153,7 @@ bool HyperionIManager::deleteInstance(const quint8& inst)
|
||||
return false;
|
||||
|
||||
// stop it if required as blocking and wait
|
||||
if (stopInstance(inst, true))
|
||||
;
|
||||
stopInstance(inst);
|
||||
|
||||
if(_instanceTable->deleteInstance(inst))
|
||||
{
|
||||
|
@@ -280,7 +280,6 @@ void PriorityMuxer::setCurrentTime(void)
|
||||
{
|
||||
const int64_t now = QDateTime::currentMSecsSinceEpoch();
|
||||
int newPriority;
|
||||
_activeInputs.contains(140) ? newPriority = 140 : newPriority = PriorityMuxer::LOWEST_PRIORITY;
|
||||
_activeInputs.contains(0) ? newPriority = 0 : newPriority = PriorityMuxer::LOWEST_PRIORITY;
|
||||
|
||||
for (auto infoIt = _activeInputs.begin(); infoIt != _activeInputs.end();)
|
||||
|
@@ -23,7 +23,6 @@ ProtoClientConnection::ProtoClientConnection(QTcpSocket* socket, const int &time
|
||||
, _timeoutTimer(new QTimer(this))
|
||||
, _timeout(timeout * 1000)
|
||||
, _priority()
|
||||
, _hyperion(HyperionIManager::getInstance()->getHyperionInstance())
|
||||
{
|
||||
// timer setup
|
||||
_timeoutTimer->setSingleShot(true);
|
||||
@@ -80,8 +79,8 @@ void ProtoClientConnection::forceClose()
|
||||
void ProtoClientConnection::disconnected()
|
||||
{
|
||||
Debug(_log, "Socket Closed");
|
||||
_socket->deleteLater();
|
||||
_hyperion->clear(_priority);
|
||||
_socket->deleteLater();
|
||||
emit clearGlobalInput(_priority);
|
||||
emit clientDisconnected();
|
||||
}
|
||||
|
||||
@@ -134,13 +133,13 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag
|
||||
// make sure the prio is registered before setColor()
|
||||
if(priority != _priority)
|
||||
{
|
||||
_hyperion->clear(_priority);
|
||||
_hyperion->registerInput(priority, hyperion::COMP_PROTOSERVER, "Proto@"+_clientAddress);
|
||||
emit clearGlobalInput(_priority);
|
||||
emit registerGlobalInput(priority, hyperion::COMP_PROTOSERVER, "Proto@"+_clientAddress);
|
||||
_priority = priority;
|
||||
}
|
||||
|
||||
// set output
|
||||
_hyperion->setColor(_priority, color, duration);
|
||||
emit setGlobalInputColor(_priority, color, duration);
|
||||
|
||||
// send reply
|
||||
sendSuccessReply();
|
||||
@@ -158,8 +157,8 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag
|
||||
// make sure the prio is registered before setInput()
|
||||
if(priority != _priority)
|
||||
{
|
||||
_hyperion->clear(_priority);
|
||||
_hyperion->registerInput(priority, hyperion::COMP_PROTOSERVER, "Proto@"+_clientAddress);
|
||||
emit clearGlobalInput(_priority);
|
||||
emit registerGlobalInput(priority, hyperion::COMP_PROTOSERVER, "Proto@"+_clientAddress);
|
||||
_priority = priority;
|
||||
}
|
||||
|
||||
@@ -174,7 +173,7 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag
|
||||
Image<ColorRgb> image(width, height);
|
||||
memcpy(image.memptr(), imageData.c_str(), imageData.size());
|
||||
|
||||
_hyperion->setInputImage(_priority, image, duration);
|
||||
emit setGlobalInputImage(_priority, image, duration);
|
||||
|
||||
// send reply
|
||||
sendSuccessReply();
|
||||
@@ -187,15 +186,15 @@ void ProtoClientConnection::handleClearCommand(const proto::ClearRequest &messag
|
||||
int priority = message.priority();
|
||||
|
||||
// clear priority
|
||||
_hyperion->clear(priority);
|
||||
emit clearGlobalInput(priority);
|
||||
// send reply
|
||||
sendSuccessReply();
|
||||
}
|
||||
|
||||
void ProtoClientConnection::handleClearallCommand()
|
||||
{
|
||||
// clear priority
|
||||
_hyperion->clearall();
|
||||
// clear all priority
|
||||
emit clearAllGlobalInput();
|
||||
|
||||
// send reply
|
||||
sendSuccessReply();
|
||||
|
@@ -34,12 +34,42 @@ public:
|
||||
explicit ProtoClientConnection(QTcpSocket* socket, const int &timeout, QObject *parent);
|
||||
|
||||
signals:
|
||||
///
|
||||
/// @brief forward register data to HyperionDaemon
|
||||
///
|
||||
void registerGlobalInput(const int priority, const hyperion::Components& component, const QString& origin = "ProtoBuffer", const QString& owner = "", unsigned smooth_cfg = 0);
|
||||
|
||||
///
|
||||
/// @brief Forward clear command to HyperionDaemon
|
||||
///
|
||||
void clearGlobalInput(const int priority);
|
||||
|
||||
///
|
||||
/// @brief Forward clearAll command to HyperionDaemon
|
||||
///
|
||||
void clearAllGlobalInput(bool forceClearAll=false);
|
||||
|
||||
///
|
||||
/// @brief forward prepared image to HyperionDaemon
|
||||
///
|
||||
const bool setGlobalInputImage(const int priority, const Image<ColorRgb>& image, const int timeout_ms, const bool& clearEffect = false);
|
||||
|
||||
///
|
||||
/// @brief Forward requested color
|
||||
///
|
||||
void setGlobalInputColor(const int priority, const ColorRgb &ledColor, const int timeout_ms, const QString& origin = "ProtoBuffer" ,bool clearEffects = true);
|
||||
|
||||
///
|
||||
/// @brief Emits whenever the client disconnected
|
||||
///
|
||||
void clientDisconnected();
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// @brief Requests a registration from the client
|
||||
///
|
||||
void registationRequired(const int priority) { if (_priority == priority) _priority = -1; };
|
||||
|
||||
///
|
||||
/// @brief close the socket and call disconnected()
|
||||
///
|
||||
@@ -127,9 +157,6 @@ private:
|
||||
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;
|
||||
};
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
// util
|
||||
#include <utils/NetOrigin.h>
|
||||
#include <utils/GlobalSignals.h>
|
||||
|
||||
// qt
|
||||
#include <QJsonObject>
|
||||
@@ -68,6 +69,12 @@ void ProtoServer::newConnection()
|
||||
ProtoClientConnection * client = new ProtoClientConnection(socket, _timeout, this);
|
||||
// internal
|
||||
connect(client, &ProtoClientConnection::clientDisconnected, this, &ProtoServer::clientDisconnected);
|
||||
connect(client, &ProtoClientConnection::registerGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::registerGlobalInput);
|
||||
connect(client, &ProtoClientConnection::clearGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::clearGlobalInput);
|
||||
connect(client, &ProtoClientConnection::clearAllGlobalInput, GlobalSignals::getInstance(), &GlobalSignals::clearAllGlobalInput);
|
||||
connect(client, &ProtoClientConnection::setGlobalInputImage, GlobalSignals::getInstance(), &GlobalSignals::setGlobalImage);
|
||||
connect(client, &ProtoClientConnection::setGlobalInputColor, GlobalSignals::getInstance(), &GlobalSignals::setGlobalColor);
|
||||
connect(GlobalSignals::getInstance(), &GlobalSignals::globalRegRequired, client, &ProtoClientConnection::registationRequired);
|
||||
_openConnections.append(client);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user