From a8da7acd143fd755816cd4345d88d75bc66c1cee Mon Sep 17 00:00:00 2001 From: redpanther Date: Sat, 16 Jul 2016 22:51:31 +0200 Subject: [PATCH] make proto uses priorityRegister --- libsrc/grabber/amlogic/AmlogicWrapper.cpp | 5 ++- libsrc/grabber/dispmanx/DispmanxWrapper.cpp | 4 +- .../framebuffer/FramebufferWrapper.cpp | 4 +- libsrc/grabber/osx/OsxWrapper.cpp | 4 +- libsrc/grabber/v4l2/V4L2Wrapper.cpp | 11 ++++-- libsrc/jsonserver/JsonClientConnection.cpp | 11 ++++++ libsrc/protoserver/ProtoClientConnection.cpp | 37 ++++++++++++------- libsrc/protoserver/ProtoClientConnection.h | 6 ++- libsrc/protoserver/ProtoConnectionWrapper.cpp | 8 ++-- libsrc/protoserver/ProtoServer.cpp | 14 +++---- libsrc/webconfig/StaticFileServing.cpp | 2 +- 11 files changed, 69 insertions(+), 37 deletions(-) diff --git a/libsrc/grabber/amlogic/AmlogicWrapper.cpp b/libsrc/grabber/amlogic/AmlogicWrapper.cpp index c4efcc77..24eedc84 100644 --- a/libsrc/grabber/amlogic/AmlogicWrapper.cpp +++ b/libsrc/grabber/amlogic/AmlogicWrapper.cpp @@ -31,8 +31,6 @@ AmlogicWrapper::AmlogicWrapper(const unsigned grabWidth, const unsigned grabHeig // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); - - _hyperion->registerPriority("Amlogic Grabber", _priority); } AmlogicWrapper::~AmlogicWrapper() @@ -46,6 +44,7 @@ void AmlogicWrapper::start() { // Start the timer with the pre configured interval _timer.start(); + _hyperion->registerPriority("Amlogic Grabber"); } void AmlogicWrapper::action() @@ -72,6 +71,8 @@ void AmlogicWrapper::stop() { // Stop the timer, effectivly stopping the process _timer.stop(); + _hyperion->unRegisterPriority("Amlogic Grabber", _priority); + } void AmlogicWrapper::setGrabbingMode(const GrabbingMode mode) diff --git a/libsrc/grabber/dispmanx/DispmanxWrapper.cpp b/libsrc/grabber/dispmanx/DispmanxWrapper.cpp index 0a070138..f2783deb 100644 --- a/libsrc/grabber/dispmanx/DispmanxWrapper.cpp +++ b/libsrc/grabber/dispmanx/DispmanxWrapper.cpp @@ -31,8 +31,6 @@ DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHe // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); - - _hyperion->registerPriority("Dispmanx Grabber", _priority); } DispmanxWrapper::~DispmanxWrapper() @@ -46,6 +44,7 @@ void DispmanxWrapper::start() { // Start the timer with the pre configured interval _timer.start(); + _hyperion->registerPriority("Dispmanx Grabber", _priority); } void DispmanxWrapper::action() @@ -68,6 +67,7 @@ void DispmanxWrapper::stop() { // Stop the timer, effectivly stopping the process _timer.stop(); + _hyperion->unRegisterPriority("Dispmanx Grabber"); } void DispmanxWrapper::setGrabbingMode(const GrabbingMode mode) diff --git a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp index e3732c29..0e0c2c8f 100644 --- a/libsrc/grabber/framebuffer/FramebufferWrapper.cpp +++ b/libsrc/grabber/framebuffer/FramebufferWrapper.cpp @@ -26,8 +26,6 @@ FramebufferWrapper::FramebufferWrapper(const std::string & device, const unsigne // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); - - _hyperion->registerPriority("FrameBuffer Grabber", _priority); } FramebufferWrapper::~FramebufferWrapper() @@ -41,6 +39,7 @@ void FramebufferWrapper::start() { // Start the timer with the pre configured interval _timer.start(); + _hyperion->registerPriority("FrameBuffer Grabber", _priority); } void FramebufferWrapper::action() @@ -57,6 +56,7 @@ void FramebufferWrapper::stop() { // Stop the timer, effectivly stopping the process _timer.stop(); + _hyperion->unRegisterPriority("FrameBuffer Grabber"); } void FramebufferWrapper::setGrabbingMode(const GrabbingMode mode) diff --git a/libsrc/grabber/osx/OsxWrapper.cpp b/libsrc/grabber/osx/OsxWrapper.cpp index b2cda007..afde051f 100644 --- a/libsrc/grabber/osx/OsxWrapper.cpp +++ b/libsrc/grabber/osx/OsxWrapper.cpp @@ -26,8 +26,6 @@ OsxWrapper::OsxWrapper(const unsigned display, const unsigned grabWidth, const u // Connect the QTimer to this QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); - - _hyperion->registerPriority("OsxFrameGrabber", _priority); } OsxWrapper::~OsxWrapper() @@ -41,6 +39,7 @@ void OsxWrapper::start() { // Start the timer with the pre configured interval _timer.start(); + _hyperion->registerPriority("OsxFrameGrabber", _priority); } void OsxWrapper::action() @@ -57,6 +56,7 @@ void OsxWrapper::stop() { // Stop the timer, effectivly stopping the process _timer.stop(); + _hyperion->unRegisterPriority("OsxFrameGrabber"); } void OsxWrapper::setGrabbingMode(const GrabbingMode mode) diff --git a/libsrc/grabber/v4l2/V4L2Wrapper.cpp b/libsrc/grabber/v4l2/V4L2Wrapper.cpp index 3de05b5b..b685c962 100644 --- a/libsrc/grabber/v4l2/V4L2Wrapper.cpp +++ b/libsrc/grabber/v4l2/V4L2Wrapper.cpp @@ -35,8 +35,6 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device, // set the signal detection threshold of the grabber _grabber.setSignalThreshold( redSignalThreshold, greenSignalThreshold, blueSignalThreshold, 50); - _hyperion->registerPriority("V4L2", _priority); - // register the image type qRegisterMetaType>("Image"); qRegisterMetaType>("std::vector"); @@ -71,14 +69,21 @@ bool V4L2Wrapper::start() { bool grabber_started = _grabber.start(); if ( ! grabber_started ) + { _timer.stop(); - + } + else + { + _hyperion->registerPriority("V4L2", _priority); + } + return grabber_started; } void V4L2Wrapper::stop() { _grabber.stop(); + _hyperion->unRegisterPriority("V4L2"); } void V4L2Wrapper::setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom) diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 6f402c29..9c88135d 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -387,6 +387,7 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) Json::Value & priorities = info["priorities"] = Json::Value(Json::arrayValue); uint64_t now = QDateTime::currentMSecsSinceEpoch(); QList activePriorities = _hyperion->getActivePriorities(); + const Hyperion::PriorityRegister& priorityRegister = _hyperion->getPriorityRegister(); foreach (int priority, activePriorities) { const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(priority); Json::Value & item = priorities[priorities.size()]; @@ -395,6 +396,16 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) { item["duration_ms"] = Json::Value::UInt(priorityInfo.timeoutTime_ms - now); } + + item["owner"] = "unknown"; + for(auto const &entry : priorityRegister) + { + if (entry.second == priority) + { + item["owner"] = entry.first; + break; + } + } } // collect temperature correction information diff --git a/libsrc/protoserver/ProtoClientConnection.cpp b/libsrc/protoserver/ProtoClientConnection.cpp index 9082635e..5db92eac 100644 --- a/libsrc/protoserver/ProtoClientConnection.cpp +++ b/libsrc/protoserver/ProtoClientConnection.cpp @@ -20,16 +20,19 @@ // project includes #include "ProtoClientConnection.h" -ProtoClientConnection::ProtoClientConnection(QTcpSocket *socket, Hyperion * hyperion) : - QObject(), - _socket(socket), - _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()), - _hyperion(hyperion), - _receiveBuffer() +ProtoClientConnection::ProtoClientConnection(QTcpSocket *socket) + : QObject() + , _socket(socket) + , _imageProcessor(ImageProcessorFactory::getInstance().newImageProcessor()) + , _hyperion(Hyperion::getInstance()) + , _receiveBuffer() + , _priority(-1) { // connect internal signals and slots connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed())); connect(_socket, SIGNAL(readyRead()), this, SLOT(readData())); + + _priorityChannelName = "proto@"+ _socket->peerAddress().toString().toStdString(); } ProtoClientConnection::~ProtoClientConnection() @@ -76,6 +79,7 @@ void ProtoClientConnection::readData() void ProtoClientConnection::socketClosed() { + _hyperion->unRegisterPriority(_priorityChannelName); emit connectionClosed(this); } @@ -110,6 +114,7 @@ void ProtoClientConnection::handleMessage(const proto::HyperionRequest & message // forward messages emit newMessage(&message); + int prevPriority = _priority; switch (message.command()) { case proto::HyperionRequest::COLOR: @@ -142,12 +147,18 @@ void ProtoClientConnection::handleMessage(const proto::HyperionRequest & message default: handleNotImplemented(); } + + if (prevPriority != _priority) + { + _hyperion->registerPriority(_priorityChannelName, _priority); + prevPriority = _priority; + } } void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &message) { // extract parameters - int priority = message.priority(); + _priority = message.priority(); int duration = message.has_duration() ? message.duration() : -1; ColorRgb color; color.red = qRed(message.rgbcolor()); @@ -155,7 +166,7 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag color.blue = qBlue(message.rgbcolor()); // set output - _hyperion->setColor(priority, color, duration); + _hyperion->setColor(_priority, color, duration); // send reply sendSuccessReply(); @@ -164,7 +175,7 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &message) { // extract parameters - int priority = message.priority(); + _priority = message.priority(); int duration = message.has_duration() ? message.duration() : -1; int width = message.imagewidth(); int height = message.imageheight(); @@ -186,7 +197,7 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag // process the image std::vector ledColors = _imageProcessor->process(image); - _hyperion->setColors(priority, ledColors, duration); + _hyperion->setColors(_priority, ledColors, duration); // send reply sendSuccessReply(); @@ -196,11 +207,11 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag void ProtoClientConnection::handleClearCommand(const proto::ClearRequest &message) { // extract parameters - int priority = message.priority(); + _priority = message.priority(); // clear priority - _hyperion->clear(priority); - + _hyperion->clear(_priority); + _hyperion->unRegisterPriority(_priorityChannelName); // send reply sendSuccessReply(); } diff --git a/libsrc/protoserver/ProtoClientConnection.h b/libsrc/protoserver/ProtoClientConnection.h index d5d31c89..f2777d4c 100644 --- a/libsrc/protoserver/ProtoClientConnection.h +++ b/libsrc/protoserver/ProtoClientConnection.h @@ -34,7 +34,7 @@ public: /// @param socket The Socket object for this connection /// @param hyperion The Hyperion server /// - ProtoClientConnection(QTcpSocket * socket, Hyperion * hyperion); + ProtoClientConnection(QTcpSocket * socket); /// /// Destructor @@ -137,4 +137,8 @@ private: /// The buffer used for reading data from the socket QByteArray _receiveBuffer; + + int _priority; + + std::string _priorityChannelName; }; diff --git a/libsrc/protoserver/ProtoConnectionWrapper.cpp b/libsrc/protoserver/ProtoConnectionWrapper.cpp index 3c2ad0cd..e236e223 100644 --- a/libsrc/protoserver/ProtoConnectionWrapper.cpp +++ b/libsrc/protoserver/ProtoConnectionWrapper.cpp @@ -1,10 +1,10 @@ // protoserver includes #include "protoserver/ProtoConnectionWrapper.h" -ProtoConnectionWrapper::ProtoConnectionWrapper(const std::string & address, int priority, int duration_ms, bool skipProtoReply) : - _priority(priority), - _duration_ms(duration_ms), - _connection(address) +ProtoConnectionWrapper::ProtoConnectionWrapper(const std::string & address, int priority, int duration_ms, bool skipProtoReply) + : _priority(priority) + , _duration_ms(duration_ms) + , _connection(address) { _connection.setSkipReply(skipProtoReply); connect(&_connection, SIGNAL(setGrabbingMode(GrabbingMode)), this, SIGNAL(setGrabbingMode(GrabbingMode))); diff --git a/libsrc/protoserver/ProtoServer.cpp b/libsrc/protoserver/ProtoServer.cpp index 46d38029..b3b0a654 100644 --- a/libsrc/protoserver/ProtoServer.cpp +++ b/libsrc/protoserver/ProtoServer.cpp @@ -7,12 +7,12 @@ #include "protoserver/ProtoConnection.h" #include "ProtoClientConnection.h" -ProtoServer::ProtoServer(uint16_t port) : - QObject(), - _hyperion(Hyperion::getInstance()), - _server(), - _openConnections(), - _log(Logger::getInstance("PROTOSERVER")) +ProtoServer::ProtoServer(uint16_t port) + : QObject() + , _hyperion(Hyperion::getInstance()) + , _server() + , _openConnections() + , _log(Logger::getInstance("PROTOSERVER")) { MessageForwarder * forwarder = _hyperion->getForwarder(); @@ -59,7 +59,7 @@ void ProtoServer::newConnection() if (socket != nullptr) { Debug(_log, "New connection"); - ProtoClientConnection * connection = new ProtoClientConnection(socket, _hyperion); + ProtoClientConnection * connection = new ProtoClientConnection(socket); _openConnections.insert(connection); // register slot for cleaning up after the connection closed diff --git a/libsrc/webconfig/StaticFileServing.cpp b/libsrc/webconfig/StaticFileServing.cpp index 25e5f9a4..4230b23e 100644 --- a/libsrc/webconfig/StaticFileServing.cpp +++ b/libsrc/webconfig/StaticFileServing.cpp @@ -17,7 +17,7 @@ StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint _mimeDb = new QMimeDatabase; _server = new QtHttpServer (this); - _server->setServerName (QStringLiteral ("Qt Static HTTP File Server")); + _server->setServerName (QStringLiteral ("Hyperion WebConfig")); connect (_server, &QtHttpServer::started, this, &StaticFileServing::onServerStarted); connect (_server, &QtHttpServer::stopped, this, &StaticFileServing::onServerStopped);