Websocket auto serverinfo responder (#443)

* serverinfo cb

* remove webui cron

* missing header file

* tcp connection should trigger to
This commit is contained in:
brindosch
2017-06-17 23:29:04 +02:00
committed by GitHub
parent 91c7637a2b
commit d3707cb118
12 changed files with 166 additions and 38 deletions

View File

@@ -11,13 +11,13 @@ SET(Hyperion_QT_HEADERS
${CURRENT_SOURCE_DIR}/LinearColorSmoothing.h
${CURRENT_HEADER_DIR}/GrabberWrapper.h
${CURRENT_HEADER_DIR}/ComponentRegister.h
${CURRENT_HEADER_DIR}/PriorityMuxer.h
)
SET(Hyperion_HEADERS
${CURRENT_HEADER_DIR}/ImageProcessorFactory.h
${CURRENT_HEADER_DIR}/ImageToLedsMap.h
${CURRENT_HEADER_DIR}/LedString.h
${CURRENT_HEADER_DIR}/PriorityMuxer.h
${CURRENT_SOURCE_DIR}/MultiColorAdjustment.h
${CURRENT_HEADER_DIR}/MessageForwarder.h

View File

@@ -4,6 +4,7 @@
#include <exception>
#include <sstream>
#include <unistd.h>
#include <iostream>
// QT includes
#include <QDateTime>
@@ -444,9 +445,13 @@ Hyperion::Hyperion(const QJsonObject &qjsonConfig, const QString configFile)
Debug(_log,"configured leds: %d hw leds: %d", getLedCount(), _hwLedCount);
WarningIf(hwLedCount < getLedCount(), _log, "more leds configured than available. check 'ledCount' in 'device' section");
WarningIf(!configWriteable(), _log, "Your config is not writeable - you won't be able to use the web ui for configuration.");
// initialize hash of current config
configModified();
// setup interval timer for config state checks and initial shot
checkConfigState();
QObject::connect(&_cTimer, SIGNAL(timeout()), this, SLOT(checkConfigState()));
_cTimer.start(2000);
// pipe muxer signal for effect/color timerunner to hyperionStateChanged signal
QObject::connect(&_muxer, &PriorityMuxer::timerunner, this, &Hyperion::hyperionStateChanged);
const QJsonObject & generalConfig = qjsonConfig["general"].toObject();
_configVersionId = generalConfig["configVersion"].toInt(-1);
@@ -511,6 +516,9 @@ void Hyperion::bonjourRecordResolved(const QHostInfo &hostInfo, int port)
_hyperionSessions[_bonjourCurrentServiceToResolve].port = port;
_hyperionSessions[_bonjourCurrentServiceToResolve].address = hostInfo.addresses().isEmpty() ? "" : hostInfo.addresses().first().toString();
Debug(_log, "found hyperion session: %s:%d",QSTRING_CSTR(hostInfo.hostName()), port);
//emit change
emit hyperionStateChanged();
}
}
@@ -532,9 +540,9 @@ Hyperion::BonjourRegister Hyperion::getHyperionSessions()
return _hyperionSessions;
}
bool Hyperion::configModified()
void Hyperion::checkConfigState()
{
bool isModified = false;
// Check config modifications
QFile f(_configFile);
if (f.open(QFile::ReadOnly))
{
@@ -545,25 +553,29 @@ bool Hyperion::configModified()
{
_configHash = hash.result();
}
else
{
isModified = _configHash != hash.result();
}
_configMod = _configHash != hash.result() ? true : false;
}
}
f.close();
return isModified;
}
if(_prevConfigMod != _configMod)
{
emit hyperionStateChanged();
_prevConfigMod = _configMod;
}
bool Hyperion::configWriteable()
{
// Check config writeable
QFile file(_configFile);
QFileInfo fileInfo(file);
return fileInfo.isWritable() && fileInfo.isReadable();
_configWrite = fileInfo.isWritable() && fileInfo.isReadable() ? true : false;
if(_prevConfigWrite != _configWrite)
{
emit hyperionStateChanged();
_prevConfigWrite = _configWrite;
}
}
void Hyperion::registerPriority(const QString &name, const int priority/*, const QString &origin*/)
{
Info(_log, "Register new input source named '%s' for priority channel '%d'", QSTRING_CSTR(name), priority );
@@ -575,12 +587,14 @@ void Hyperion::registerPriority(const QString &name, const int priority/*, const
}
_priorityRegister.insert(name, priority);
emit hyperionStateChanged();
}
void Hyperion::unRegisterPriority(const QString &name)
{
Info(_log, "Unregister input source named '%s' from priority register", QSTRING_CSTR(name));
_priorityRegister.remove(name);
emit hyperionStateChanged();
}
void Hyperion::setSourceAutoSelectEnabled(bool enabled)
@@ -868,7 +882,8 @@ void Hyperion::update()
else
{
int timeout_ms = std::max(0, int(priorityInfo.timeoutTime_ms - QDateTime::currentMSecsSinceEpoch()));
_timer.start(timeout_ms);
// std::min() 200ms forced refresh if color is active to update priorityMuxer properly for forced serverinfo push
_timer.start(std::min(timeout_ms, 200));
}
}

View File

@@ -1,4 +1,4 @@
#include <iostream>
// STL includes
#include <algorithm>
#include <stdexcept>
@@ -18,6 +18,11 @@ PriorityMuxer::PriorityMuxer(int ledCount)
_lowestPriorityInfo.origin = "System";
_activeInputs[_currentPriority] = _lowestPriorityInfo;
// do a reuqest after blocking timer runs out
connect(&_timer, SIGNAL(timeout()), this, SLOT(emitReq()));
_timer.setSingleShot(true);
_blockTimer.setSingleShot(true);
}
PriorityMuxer::~PriorityMuxer()
@@ -96,9 +101,28 @@ void PriorityMuxer::setCurrentTime(const int64_t& now)
infoIt = _activeInputs.erase(infoIt);
}
else
{
{
_currentPriority = std::min(_currentPriority, infoIt->priority);
// call emitReq when effect or color is running with timeout > -1, blacklist prio 255
if(infoIt->priority < 254 && infoIt->timeoutTime_ms > -1 && (infoIt->componentId == hyperion::COMP_EFFECT || infoIt->componentId == hyperion::COMP_COLOR))
{
emitReq();
}
++infoIt;
}
}
}
void PriorityMuxer::emitReq()
{
if(_blockTimer.isActive())
{
_timer.start(500);
}
else
{
emit timerunner();
_blockTimer.start(1000);
}
}