mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
second part of PR #578
Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
29
libsrc/api/JSONRPC_schema/schema-instance.json
Normal file
29
libsrc/api/JSONRPC_schema/schema-instance.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["instance"]
|
||||
},
|
||||
"subcommand" : {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["createInstance","deleteInstance","startInstance","stopInstance","saveName","switchTo"]
|
||||
},
|
||||
"tan" : {
|
||||
"type" : "integer"
|
||||
},
|
||||
"instance" : {
|
||||
"type" : "integer",
|
||||
"minimum" : 0,
|
||||
"maximum" : 255
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"minLength" : 5
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "adjustment", "sourceselect", "config", "componentstate", "ledcolors", "logging", "processing", "sysinfo", "videomode", "authorize", "transform", "correction" , "temperature"]
|
||||
"enum" : ["color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "adjustment", "sourceselect", "config", "componentstate", "ledcolors", "logging", "processing", "sysinfo", "videomode", "authorize", "instance", "transform", "correction" , "temperature"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@
|
||||
<file alias="schema-processing">JSONRPC_schema/schema-processing.json</file>
|
||||
<file alias="schema-videomode">JSONRPC_schema/schema-videomode.json</file>
|
||||
<file alias="schema-authorize">JSONRPC_schema/schema-authorize.json</file>
|
||||
<file alias="schema-instance">JSONRPC_schema/schema-instance.json</file>
|
||||
<!-- The following schemas are derecated but used to ensure backward compatibility with hyperion Classic remote control-->
|
||||
<file alias="schema-transform">JSONRPC_schema/schema-hyperion-classic.json</file>
|
||||
<file alias="schema-correction">JSONRPC_schema/schema-hyperion-classic.json</file>
|
||||
|
@@ -49,8 +49,9 @@ JsonAPI::JsonAPI(QString peerAddress, Logger* log, const bool& localConnection,
|
||||
, _noListener(noListener)
|
||||
, _peerAddress(peerAddress)
|
||||
, _log(log)
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _jsonCB(new JsonCB(this))
|
||||
, _instanceManager(HyperionIManager::getInstance())
|
||||
, _hyperion(nullptr)
|
||||
, _jsonCB(nullptr)
|
||||
, _streaming_logging_activated(false)
|
||||
, _image_stream_timeout(0)
|
||||
, _led_stream_timeout(0)
|
||||
@@ -65,11 +66,60 @@ JsonAPI::JsonAPI(QString peerAddress, Logger* log, const bool& localConnection,
|
||||
connect(_authManager, &AuthManager::newPendingTokenRequest, this, &JsonAPI::handlePendingTokenRequest);
|
||||
connect(_authManager, &AuthManager::tokenResponse, this, &JsonAPI::handleTokenResponse);
|
||||
|
||||
// the JsonCB creates json messages you can subscribe to e.g. data change events; forward them to the parent client
|
||||
connect(_jsonCB, &JsonCB::newCallback, this, &JsonAPI::callbackMessage);
|
||||
// listen for killed instances
|
||||
connect(_instanceManager, &HyperionIManager::instanceStateChanged, this, &JsonAPI::handleInstanceStateChange);
|
||||
|
||||
// notify hyperion about a jsonMessageForward
|
||||
connect(this, &JsonAPI::forwardJsonMessage, _hyperion, &Hyperion::forwardJsonMessage);
|
||||
// init Hyperion pointer
|
||||
handleInstanceSwitch(0);
|
||||
|
||||
// // notify hyperion about a jsonMessageForward
|
||||
// connect(this, &JsonAPI::forwardJsonMessage, _hyperion, &Hyperion::forwardJsonMessage);
|
||||
}
|
||||
|
||||
const bool JsonAPI::handleInstanceSwitch(const quint8& inst, const bool& forced)
|
||||
{
|
||||
// check if we are already on the requested instance
|
||||
if(_hyperion != nullptr && _hyperion->getInstanceIndex() == inst)
|
||||
return true;
|
||||
|
||||
if(_instanceManager->IsInstanceRunning(inst))
|
||||
{
|
||||
Debug(_log,"Client '%s' switch to Hyperion instance %d", QSTRING_CSTR(_peerAddress), inst);
|
||||
// cut all connections between hyperion / plugins and this
|
||||
if(_hyperion != nullptr)
|
||||
disconnect(_hyperion, 0, this, 0);
|
||||
|
||||
// get new Hyperion pointer
|
||||
_hyperion = _instanceManager->getHyperionInstance(inst);
|
||||
|
||||
// the JsonCB creates json messages you can subscribe to e.g. data change events; forward them to the parent client
|
||||
QStringList cbCmds;
|
||||
if(_jsonCB != nullptr)
|
||||
{
|
||||
cbCmds = _jsonCB->getSubscribedCommands();
|
||||
delete _jsonCB;
|
||||
}
|
||||
|
||||
_jsonCB = new JsonCB(_hyperion, this);
|
||||
connect(_jsonCB, &JsonCB::newCallback, this, &JsonAPI::callbackMessage);
|
||||
|
||||
// read subs
|
||||
for(const auto & entry : cbCmds)
|
||||
{
|
||||
_jsonCB->subscribeFor(entry);
|
||||
}
|
||||
|
||||
// // imageStream last state
|
||||
// if(_ledcolorsImageActive)
|
||||
// connect(_hyperion, &Hyperion::currentImage, this, &JsonAPI::setImage, Qt::UniqueConnection);
|
||||
//
|
||||
// //ledColor stream last state
|
||||
// if(_ledcolorsLedsActive)
|
||||
// connect(_hyperion, &Hyperion::rawLedColors, this, &JsonAPI::streamLedcolorsUpdate, Qt::UniqueConnection);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void JsonAPI::handleMessage(const QString& messageString, const QString& httpAuthHeader)
|
||||
@@ -140,6 +190,7 @@ void JsonAPI::handleMessage(const QString& messageString, const QString& httpAut
|
||||
else if (command == "logging") handleLoggingCommand (message, command, tan);
|
||||
else if (command == "processing") handleProcessingCommand (message, command, tan);
|
||||
else if (command == "videomode") handleVideoModeCommand (message, command, tan);
|
||||
else if (command == "instance") handleInstanceCommand (message, command, tan);
|
||||
|
||||
// BEGIN | The following commands are derecated but used to ensure backward compatibility with hyperion Classic remote control
|
||||
else if (command == "clearall")
|
||||
@@ -290,7 +341,7 @@ void JsonAPI::handleSysInfoCommand(const QJsonObject&, const QString& command, c
|
||||
hyperion["channel" ] = QString(HYPERION_VERSION_CHANNEL);
|
||||
hyperion["build" ] = QString(HYPERION_BUILD_ID);
|
||||
hyperion["time" ] = QString(__DATE__ " " __TIME__);
|
||||
hyperion["id" ] = _hyperion->getId();
|
||||
hyperion["id" ] = _authManager->getID();
|
||||
info["hyperion"] = hyperion;
|
||||
|
||||
// send the result
|
||||
@@ -485,14 +536,6 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject& message, const QString&
|
||||
info["components"] = component;
|
||||
info["imageToLedMappingType"] = ImageProcessor::mappingTypeToStr(_hyperion->getLedMappingType());
|
||||
|
||||
// Add Hyperion
|
||||
QJsonObject hyperion;
|
||||
hyperion["config_modified" ] = _hyperion->configModified();
|
||||
hyperion["config_writeable"] = _hyperion->configWriteable();
|
||||
hyperion["enabled"] = _hyperion->getComponentRegister().isComponentEnabled(hyperion::COMP_ALL) ? true : false;
|
||||
|
||||
info["hyperion"] = hyperion;
|
||||
|
||||
// add sessions
|
||||
QJsonArray sessions;
|
||||
for (auto session: BonjourBrowserWrapper::getInstance()->getAllServices())
|
||||
@@ -509,6 +552,19 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject& message, const QString&
|
||||
}
|
||||
info["sessions"] = sessions;
|
||||
|
||||
// add instance info
|
||||
QJsonArray instanceInfo;
|
||||
for(const auto & entry : _instanceManager->getInstanceData())
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert("friendly_name", entry["friendly_name"].toString());
|
||||
obj.insert("instance", entry["instance"].toInt());
|
||||
//obj.insert("last_use", entry["last_use"].toString());
|
||||
obj.insert("running", entry["running"].toBool());
|
||||
instanceInfo.append(obj);
|
||||
}
|
||||
info["instance"] = instanceInfo;
|
||||
|
||||
// BEGIN | The following entries are derecated but used to ensure backward compatibility with hyperion Classic remote control
|
||||
// TODO Output the real transformation information instead of default
|
||||
|
||||
@@ -656,6 +712,17 @@ void JsonAPI::handleClearCommand(const QJsonObject& message, const QString& comm
|
||||
sendSuccessReply(command, tan);
|
||||
}
|
||||
|
||||
void JsonAPI::handleClearallCommand(const QJsonObject& message, const QString& command, const int tan)
|
||||
{
|
||||
emit forwardJsonMessage(message);
|
||||
|
||||
// clear priority
|
||||
_hyperion->clearall();
|
||||
|
||||
// send reply
|
||||
sendSuccessReply(command, tan);
|
||||
}
|
||||
|
||||
void JsonAPI::handleAdjustmentCommand(const QJsonObject& message, const QString& command, const int tan)
|
||||
{
|
||||
const QJsonObject & adjustment = message["adjustment"].toObject();
|
||||
@@ -887,8 +954,6 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject& message, const QStr
|
||||
{
|
||||
if(_hyperion->getComponentRegister().setHyperionEnable(compState))
|
||||
sendSuccessReply(command, tan);
|
||||
else
|
||||
sendErrorReply(QString("Hyperion is already %1").arg(compState ? "enabled" : "disabled"), command, tan );
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1187,15 +1252,76 @@ const bool JsonAPI::handleHTTPAuth(const QString& command, const int& tan, const
|
||||
return false;
|
||||
}
|
||||
|
||||
void JsonAPI::handleClearallCommand(const QJsonObject& message, const QString& command, const int tan)
|
||||
void JsonAPI::handleInstanceCommand(const QJsonObject & message, const QString &command, const int tan)
|
||||
{
|
||||
emit forwardJsonMessage(message);
|
||||
const QString & subc = message["subcommand"].toString();
|
||||
const quint8 & inst = message["instance"].toInt();
|
||||
const QString & name = message["name"].toString();
|
||||
|
||||
// clear priority
|
||||
_hyperion->clearall();
|
||||
if(subc == "switchTo")
|
||||
{
|
||||
if(handleInstanceSwitch(inst))
|
||||
sendSuccessReply(command+"-"+subc, tan);
|
||||
else
|
||||
sendErrorReply("Selected Hyperion instance isn't running",command+"-"+subc, tan);
|
||||
return;
|
||||
}
|
||||
|
||||
// send reply
|
||||
sendSuccessReply(command, tan);
|
||||
if(subc == "startInstance")
|
||||
{
|
||||
// silent fail
|
||||
_instanceManager->startInstance(inst);
|
||||
sendSuccessReply(command+"-"+subc, tan);
|
||||
return;
|
||||
}
|
||||
|
||||
if(subc == "stopInstance")
|
||||
{
|
||||
// silent fail
|
||||
_instanceManager->stopInstance(inst);
|
||||
sendSuccessReply(command+"-"+subc, tan);
|
||||
return;
|
||||
}
|
||||
|
||||
if(subc == "deleteInstance")
|
||||
{
|
||||
if(_userAuthorized)
|
||||
{
|
||||
if(_instanceManager->deleteInstance(inst))
|
||||
sendSuccessReply(command+"-"+subc, tan);
|
||||
else
|
||||
sendErrorReply(QString("Failed to delete instance '%1'").arg(inst), command+"-"+subc, tan);
|
||||
}
|
||||
else
|
||||
sendErrorReply("No Authorization",command+"-"+subc, tan);
|
||||
return;
|
||||
}
|
||||
|
||||
// create and save name requires name
|
||||
if(name.isEmpty())
|
||||
sendErrorReply("Name string required for this command",command+"-"+subc, tan);
|
||||
|
||||
if(subc == "createInstance")
|
||||
{
|
||||
if(_userAuthorized)
|
||||
{
|
||||
if(_instanceManager->createInstance(name))
|
||||
sendSuccessReply(command+"-"+subc, tan);
|
||||
else
|
||||
sendErrorReply(QString("The instance name '%1' is already in use").arg(name), command+"-"+subc, tan);
|
||||
}
|
||||
else
|
||||
sendErrorReply("No Authorization",command+"-"+subc, tan);
|
||||
return;
|
||||
}
|
||||
|
||||
if(subc == "saveName")
|
||||
{
|
||||
// silent fail
|
||||
_instanceManager->saveName(inst,name);
|
||||
sendSuccessReply(command+"-"+subc, tan);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAPI::handleNotImplemented()
|
||||
@@ -1363,3 +1489,17 @@ void JsonAPI::handleTokenResponse(const bool& success, QObject* caller, const QS
|
||||
sendErrorReply("Token request timeout or denied", cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAPI::handleInstanceStateChange(const instanceState& state, const quint8& instance, const QString& name)
|
||||
{
|
||||
switch(state){
|
||||
case H_ON_STOP:
|
||||
if(_hyperion->getInstanceIndex() == instance)
|
||||
{
|
||||
handleInstanceSwitch();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,23 @@
|
||||
|
||||
// hyperion
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
// HyperionIManager
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
// components
|
||||
|
||||
#include <hyperion/ComponentRegister.h>
|
||||
// bonjour wrapper
|
||||
|
||||
#include <bonjour/bonjourbrowserwrapper.h>
|
||||
// priorityMuxer
|
||||
|
||||
#include <hyperion/PriorityMuxer.h>
|
||||
|
||||
// utils
|
||||
#include <utils/ColorSys.h>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
|
||||
// Image to led map helper
|
||||
@@ -17,15 +27,15 @@
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
JsonCB::JsonCB(QObject* parent)
|
||||
JsonCB::JsonCB(Hyperion* hyperion, QObject* parent)
|
||||
: QObject(parent)
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _hyperion(hyperion)
|
||||
, _componentRegister(& _hyperion->getComponentRegister())
|
||||
, _bonjour(BonjourBrowserWrapper::getInstance())
|
||||
, _prioMuxer(_hyperion->getMuxerInstance())
|
||||
{
|
||||
_availableCommands << "components-update" << "sessions-update" << "priorities-update" << "imageToLedMapping-update"
|
||||
<< "adjustment-update" << "videomode-update" << "effects-update" << "settings-update";
|
||||
<< "adjustment-update" << "videomode-update" << "effects-update" << "settings-update" << "instance-update";
|
||||
}
|
||||
|
||||
bool JsonCB::subscribeFor(const QString& type)
|
||||
@@ -82,6 +92,12 @@ bool JsonCB::subscribeFor(const QString& type)
|
||||
connect(_hyperion, &Hyperion::settingsChanged, this, &JsonCB::handleSettingsChange, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
if(type == "instance-update")
|
||||
{
|
||||
_subscribedCommands << type;
|
||||
connect(HyperionIManager::getInstance(), &HyperionIManager::change, this, &JsonCB::handleInstanceChange, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -301,3 +317,19 @@ void JsonCB::handleSettingsChange(const settings::type& type, const QJsonDocumen
|
||||
|
||||
doCallback("settings-update", QVariant(dat));
|
||||
}
|
||||
|
||||
void JsonCB::handleInstanceChange()
|
||||
{
|
||||
QJsonArray arr;
|
||||
|
||||
for(const auto & entry : HyperionIManager::getInstance()->getInstanceData())
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert("friendly_name", entry["friendly_name"].toString());
|
||||
obj.insert("instance", entry["instance"].toInt());
|
||||
//obj.insert("last_use", entry["last_use"].toString());
|
||||
obj.insert("running", entry["running"].toBool());
|
||||
arr.append(obj);
|
||||
}
|
||||
doCallback("instance-update", QVariant(arr));
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <HyperionConfig.h>
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/AuthManager.h>
|
||||
|
||||
BonjourServiceRegister::BonjourServiceRegister(QObject *parent)
|
||||
: QObject(parent), dnssref(0), bonjourSocket(0)
|
||||
@@ -79,7 +79,7 @@ void BonjourServiceRegister::registerService(const BonjourRecord &record, quint1
|
||||
}
|
||||
#endif
|
||||
// base txtRec
|
||||
std::vector<std::pair<std::string, std::string> > txtBase = {{"id",Hyperion::getInstance()->getId().toStdString()},{"version",HYPERION_VERSION}};
|
||||
std::vector<std::pair<std::string, std::string> > txtBase = {{"id",AuthManager::getInstance()->getID().toStdString()},{"version",HYPERION_VERSION}};
|
||||
// create txt record
|
||||
TXTRecordRef txtRec;
|
||||
TXTRecordCreate(&txtRec,0,NULL);
|
||||
|
@@ -52,9 +52,7 @@ QSqlDatabase DBManager::getDB() const
|
||||
QSqlDatabase db = QSqlDatabase::database(_dbn);
|
||||
|
||||
if (db.isOpen() && db.isValid())
|
||||
{
|
||||
return db;
|
||||
}
|
||||
else
|
||||
{
|
||||
db = QSqlDatabase::addDatabase("QSQLITE", _dbn);
|
||||
|
@@ -7,6 +7,8 @@
|
||||
#include <QRgb>
|
||||
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
|
||||
FlatBufferClient::FlatBufferClient(QTcpSocket* socket, const int &timeout, QObject *parent)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("FLATBUFSERVER"))
|
||||
@@ -15,7 +17,7 @@ FlatBufferClient::FlatBufferClient(QTcpSocket* socket, const int &timeout, QObje
|
||||
, _timeoutTimer(new QTimer(this))
|
||||
, _timeout(timeout * 1000)
|
||||
, _priority()
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _hyperion(HyperionIManager::getInstance()->getHyperionInstance())
|
||||
{
|
||||
// timer setup
|
||||
_timeoutTimer->setSingleShot(true);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <QFileInfo>
|
||||
@@ -57,9 +58,9 @@ V4L2Grabber::V4L2Grabber(const QString & device
|
||||
setPixelDecimation(pixelDecimation);
|
||||
getV4Ldevices();
|
||||
|
||||
// listen for component change for build-in grabber only
|
||||
if (Hyperion::_hyperion)
|
||||
connect(Hyperion::getInstance(), &Hyperion::componentStateChanged, this, &V4L2Grabber::componentStateChanged);
|
||||
// connect componentStateChange only for build-in grabber
|
||||
if (HyperionIManager::HIMinstance)
|
||||
connect(this, &Grabber::componentStateChanged, this, &V4L2Grabber::componentStateChanged);
|
||||
|
||||
// init
|
||||
setDeviceVideoStandard(device, videoStandard);
|
||||
|
@@ -21,8 +21,10 @@ V4L2Wrapper::V4L2Wrapper(const QString &device,
|
||||
qRegisterMetaType<Image<ColorRgb>>("Image<ColorRgb>");
|
||||
|
||||
// Handle the image in the captured thread using a direct connection
|
||||
QObject::connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::DirectConnection);
|
||||
QObject::connect(&_grabber, SIGNAL(readError(const char*)), this, SLOT(readError(const char*)), Qt::DirectConnection);
|
||||
connect(&_grabber, SIGNAL(newFrame(Image<ColorRgb>)), this, SLOT(newFrame(Image<ColorRgb>)), Qt::DirectConnection);
|
||||
connect(&_grabber, SIGNAL(readError(const char*)), this, SLOT(readError(const char*)), Qt::DirectConnection);
|
||||
|
||||
connect(this, &V4L2Wrapper::componentStateChanged, _ggrabber, &Grabber::componentStateChanged);
|
||||
}
|
||||
|
||||
bool V4L2Wrapper::start()
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include <hyperion/AuthManager.h>
|
||||
|
||||
// util
|
||||
// db
|
||||
#include <db/AuthTable.h>
|
||||
#include <db/MetaTable.h>
|
||||
|
||||
// qt
|
||||
#include <QJsonObject>
|
||||
@@ -9,15 +10,19 @@
|
||||
|
||||
AuthManager* AuthManager::manager = nullptr;
|
||||
|
||||
AuthManager::AuthManager(const QString& rootPath, QObject* parent)
|
||||
AuthManager::AuthManager(QObject* parent)
|
||||
: QObject(parent)
|
||||
, _authTable(new AuthTable(rootPath, this))
|
||||
, _authTable(new AuthTable(this))
|
||||
, _metaTable(new MetaTable(this))
|
||||
, _pendingRequests()
|
||||
, _authRequired(true)
|
||||
, _timer(new QTimer(this))
|
||||
{
|
||||
AuthManager::manager = this;
|
||||
|
||||
// get uuid
|
||||
_uuid = _metaTable->getUUID();
|
||||
|
||||
// setup timer
|
||||
_timer->setInterval(1000);
|
||||
connect(_timer, &QTimer::timeout, this, &AuthManager::checkTimeout);
|
||||
@@ -29,12 +34,12 @@ AuthManager::AuthManager(const QString& rootPath, QObject* parent)
|
||||
}
|
||||
}
|
||||
|
||||
const bool & AuthManager::isAuthRequired()
|
||||
bool & AuthManager::isAuthRequired()
|
||||
{
|
||||
return _authRequired;
|
||||
}
|
||||
|
||||
const bool & AuthManager::isLocalAuthRequired()
|
||||
bool & AuthManager::isLocalAuthRequired()
|
||||
{
|
||||
return _localAuthRequired;
|
||||
}
|
||||
@@ -72,12 +77,12 @@ const QVector<AuthManager::AuthDefinition> AuthManager::getTokenList()
|
||||
return finalVec;
|
||||
}
|
||||
|
||||
const bool AuthManager::isUserAuthorized(const QString& user, const QString& pw)
|
||||
bool AuthManager::isUserAuthorized(const QString& user, const QString& pw)
|
||||
{
|
||||
return _authTable->isUserAuthorized(user, pw);
|
||||
}
|
||||
|
||||
const bool AuthManager::isTokenAuthorized(const QString& token)
|
||||
bool AuthManager::isTokenAuthorized(const QString& token)
|
||||
{
|
||||
return _authTable->tokenExist(token);
|
||||
}
|
||||
@@ -93,7 +98,7 @@ void AuthManager::setNewTokenRequest(QObject* caller, const QString& comment, co
|
||||
}
|
||||
}
|
||||
|
||||
const bool AuthManager::acceptTokenRequest(const QString& id)
|
||||
bool AuthManager::acceptTokenRequest(const QString& id)
|
||||
{
|
||||
if(_pendingRequests.contains(id))
|
||||
{
|
||||
@@ -106,7 +111,7 @@ const bool AuthManager::acceptTokenRequest(const QString& id)
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool AuthManager::denyTokenRequest(const QString& id)
|
||||
bool AuthManager::denyTokenRequest(const QString& id)
|
||||
{
|
||||
if(_pendingRequests.contains(id))
|
||||
{
|
||||
@@ -122,7 +127,7 @@ const QMap<QString, AuthManager::AuthDefinition> AuthManager::getPendingRequests
|
||||
return _pendingRequests;
|
||||
}
|
||||
|
||||
const bool AuthManager::deleteToken(const QString& id)
|
||||
bool AuthManager::deleteToken(const QString& id)
|
||||
{
|
||||
if(_authTable->deleteToken(id))
|
||||
{
|
||||
|
@@ -25,7 +25,7 @@ GrabberWrapper::GrabberWrapper(QString grabberName, Grabber * ggrabber, unsigned
|
||||
connect(_timer, &QTimer::timeout, this, &GrabberWrapper::action);
|
||||
|
||||
// connect the image forwarding
|
||||
_grabberName.startsWith("V4L")
|
||||
(_grabberName.startsWith("V4L"))
|
||||
? connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setV4lImage)
|
||||
: connect(this, &GrabberWrapper::systemImage, GlobalSignals::getInstance(), &GlobalSignals::setSystemImage);
|
||||
}
|
||||
|
@@ -5,17 +5,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
// QT includes
|
||||
#include <QDateTime>
|
||||
#include <QThread>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QCryptographicHash>
|
||||
#include <QTimer>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QHostInfo>
|
||||
#include <QCryptographicHash>
|
||||
#include <QThread>
|
||||
|
||||
// hyperion include
|
||||
#include <hyperion/Hyperion.h>
|
||||
@@ -35,9 +27,6 @@
|
||||
// effect engine includes
|
||||
#include <effectengine/EffectEngine.h>
|
||||
|
||||
// Hyperion Daemon
|
||||
#include <../src/hyperiond/hyperiond.h>
|
||||
|
||||
// settingsManagaer
|
||||
#include <hyperion/SettingsManager.h>
|
||||
|
||||
@@ -50,28 +39,10 @@
|
||||
// Boblight
|
||||
#include <boblightserver/BoblightServer.h>
|
||||
|
||||
Hyperion* Hyperion::_hyperion = nullptr;
|
||||
|
||||
Hyperion* Hyperion::initInstance( HyperionDaemon* daemon, const quint8& instance, const QString configFile, const QString rootPath)
|
||||
{
|
||||
if ( Hyperion::_hyperion != nullptr )
|
||||
throw std::runtime_error("Hyperion::initInstance can be called only one time");
|
||||
Hyperion::_hyperion = new Hyperion(daemon, instance, configFile, rootPath);
|
||||
|
||||
return Hyperion::_hyperion;
|
||||
}
|
||||
|
||||
Hyperion* Hyperion::getInstance()
|
||||
{
|
||||
if ( Hyperion::_hyperion == nullptr )
|
||||
throw std::runtime_error("Hyperion::getInstance used without call of Hyperion::initInstance before");
|
||||
|
||||
return Hyperion::_hyperion;
|
||||
}
|
||||
|
||||
Hyperion::Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString configFile, const QString rootPath)
|
||||
: _daemon(daemon)
|
||||
, _settingsManager(new SettingsManager(instance, configFile, this))
|
||||
Hyperion::Hyperion(const quint8& instance)
|
||||
: QObject()
|
||||
, _instIndex(instance)
|
||||
, _settingsManager(new SettingsManager(instance, this))
|
||||
, _componentRegister(this)
|
||||
, _ledString(hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
|
||||
, _ledStringClone(hyperion::createLedStringClone(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
|
||||
@@ -79,21 +50,33 @@ Hyperion::Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString
|
||||
, _muxer(_ledString.leds().size())
|
||||
, _raw2ledAdjustment(hyperion::createLedColorsAdjustment(_ledString.leds().size(), getSetting(settings::COLOR).object()))
|
||||
, _effectEngine(nullptr)
|
||||
, _messageForwarder(new MessageForwarder(this))
|
||||
, _configFile(configFile)
|
||||
, _rootPath(rootPath)
|
||||
// , _messageForwarder(new MessageForwarder(this))
|
||||
, _log(Logger::getInstance("HYPERION"))
|
||||
, _hwLedCount()
|
||||
, _configHash()
|
||||
, _ledGridSize(hyperion::getLedLayoutGridSize(getSetting(settings::LEDS).array()))
|
||||
, _prevCompId(hyperion::COMP_INVALID)
|
||||
, _ledBuffer(_ledString.leds().size(), ColorRgb::BLACK)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Hyperion::~Hyperion()
|
||||
{
|
||||
freeObjects(false);
|
||||
}
|
||||
|
||||
void Hyperion::start()
|
||||
{
|
||||
// forward settings changed to Hyperion
|
||||
connect(_settingsManager, &SettingsManager::settingsChanged, this, &Hyperion::settingsChanged);
|
||||
|
||||
// get newVideoMode from HyperionIManager
|
||||
connect(this, &Hyperion::newVideoMode, this, &Hyperion::handleNewVideoMode);
|
||||
|
||||
if (!_raw2ledAdjustment->verifyAdjustments())
|
||||
{
|
||||
Warning(_log, "At least one led has no color calibration, please add all leds from your led layout to an 'LED index' field!");
|
||||
}
|
||||
|
||||
// handle hwLedCount
|
||||
_hwLedCount = qMax(unsigned(getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount())), getLedCount());
|
||||
@@ -103,12 +86,14 @@ Hyperion::Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString
|
||||
{
|
||||
_ledStringColorOrder.push_back(led.colorOrder);
|
||||
}
|
||||
|
||||
for (Led& led : _ledStringClone.leds())
|
||||
{
|
||||
_ledStringColorOrder.insert(_ledStringColorOrder.begin() + led.index, led.colorOrder);
|
||||
}
|
||||
|
||||
// connect Hyperion::update with Muxer visible priority changes as muxer updates independent
|
||||
connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::update);
|
||||
|
||||
// listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions
|
||||
connect(&_componentRegister, &ComponentRegister::updatedComponentState, this, &Hyperion::updatedComponentState);
|
||||
|
||||
@@ -135,18 +120,6 @@ Hyperion::Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString
|
||||
_effectEngine = new EffectEngine(this);
|
||||
connect(_effectEngine, &EffectEngine::effectListUpdated, this, &Hyperion::effectListUpdated);
|
||||
|
||||
// setup config state checks and initial shot
|
||||
checkConfigState();
|
||||
if(_fsWatcher.addPath(_configFile))
|
||||
QObject::connect(&_fsWatcher, &QFileSystemWatcher::fileChanged, this, &Hyperion::checkConfigState);
|
||||
else
|
||||
{
|
||||
_cTimer = new QTimer(this);
|
||||
Warning(_log,"Filesystem Observer failed for file: %s, use fallback timer", _configFile.toStdString().c_str());
|
||||
connect(_cTimer, SIGNAL(timeout()), this, SLOT(checkConfigState()));
|
||||
_cTimer->start(2000);
|
||||
}
|
||||
|
||||
// initial startup effect
|
||||
hyperion::handleInitialEffect(this, getSetting(settings::FGEFFECT).object());
|
||||
|
||||
@@ -163,13 +136,15 @@ Hyperion::Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString
|
||||
_boblightServer = new BoblightServer(this, getSetting(settings::BOBLSERVER));
|
||||
connect(this, &Hyperion::settingsChanged, _boblightServer, &BoblightServer::handleSettingsUpdate);
|
||||
|
||||
// set unique id
|
||||
_id = QString(QCryptographicHash::hash(getConfigFileName().toLocal8Bit(),QCryptographicHash::Sha1).toHex());
|
||||
// instance inited
|
||||
emit started();
|
||||
// enter thread event loop
|
||||
}
|
||||
|
||||
Hyperion::~Hyperion()
|
||||
void Hyperion::stop()
|
||||
{
|
||||
freeObjects(false);
|
||||
emit finished();
|
||||
thread()->quit();
|
||||
}
|
||||
|
||||
void Hyperion::freeObjects(bool emitCloseSignal)
|
||||
@@ -187,7 +162,7 @@ void Hyperion::freeObjects(bool emitCloseSignal)
|
||||
delete _captureCont;
|
||||
delete _effectEngine;
|
||||
delete _raw2ledAdjustment;
|
||||
delete _messageForwarder;
|
||||
// delete _messageForwarder;
|
||||
delete _settingsManager;
|
||||
delete _ledDeviceWrapper;
|
||||
}
|
||||
@@ -238,9 +213,6 @@ void Hyperion::handleSettingsUpdate(const settings::type& type, const QJsonDocum
|
||||
// handle hwLedCount update
|
||||
_hwLedCount = qMax(unsigned(getSetting(settings::DEVICE).object()["hardwareLedCount"].toInt(getLedCount())), getLedCount());
|
||||
|
||||
// update led count in device
|
||||
//_ledDeviceWrapper->setLedCount(_hwLedCount);
|
||||
|
||||
// change in leds are also reflected in adjustment
|
||||
delete _raw2ledAdjustment;
|
||||
_raw2ledAdjustment = hyperion::createLedColorsAdjustment(_ledString.leds().size(), getSetting(settings::COLOR).object());
|
||||
@@ -264,17 +236,11 @@ void Hyperion::handleSettingsUpdate(const settings::type& type, const QJsonDocum
|
||||
_imageProcessor->setLedString(_ledString);
|
||||
}
|
||||
|
||||
/* // reinit led device type on change
|
||||
if(_device->getActiveDevice() != dev["type"].toString("file").toLower())
|
||||
{
|
||||
}
|
||||
// update led count
|
||||
_device->setLedCount(_hwLedCount);
|
||||
*/
|
||||
// do always reinit until the led devices can handle dynamic changes
|
||||
dev["currentLedCount"] = int(_hwLedCount); // Inject led count info
|
||||
_ledDeviceWrapper->createLedDevice(dev);
|
||||
}
|
||||
|
||||
// update once to push single color sets / adjustments/ ledlayout resizes and update ledBuffer color
|
||||
update();
|
||||
}
|
||||
@@ -289,12 +255,6 @@ bool Hyperion::saveSettings(QJsonObject config, const bool& correct)
|
||||
return _settingsManager->saveSettings(config, correct);
|
||||
}
|
||||
|
||||
QString Hyperion::getConfigFileName() const
|
||||
{
|
||||
QFileInfo cF(_configFile);
|
||||
return cF.fileName();
|
||||
}
|
||||
|
||||
int Hyperion::getLatchTime() const
|
||||
{
|
||||
return _ledDeviceWrapper->getLatchTime();
|
||||
@@ -310,40 +270,6 @@ unsigned Hyperion::getLedCount() const
|
||||
return _ledString.leds().size();
|
||||
}
|
||||
|
||||
void Hyperion::checkConfigState(QString cfile)
|
||||
{
|
||||
// Check config modifications
|
||||
QFile f(_configFile);
|
||||
if (f.open(QFile::ReadOnly))
|
||||
{
|
||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||
if (hash.addData(&f))
|
||||
{
|
||||
if (_configHash.size() == 0)
|
||||
{
|
||||
_configHash = hash.result();
|
||||
}
|
||||
_configMod = _configHash != hash.result() ? true : false;
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
|
||||
if(_prevConfigMod != _configMod)
|
||||
{
|
||||
_prevConfigMod = _configMod;
|
||||
}
|
||||
|
||||
// Check config writeable
|
||||
QFile file(_configFile);
|
||||
QFileInfo fileInfo(file);
|
||||
_configWrite = fileInfo.isWritable() && fileInfo.isReadable() ? true : false;
|
||||
|
||||
if(_prevConfigWrite != _configWrite)
|
||||
{
|
||||
_prevConfigWrite = _configWrite;
|
||||
}
|
||||
}
|
||||
|
||||
void Hyperion::setSourceAutoSelectEnabled(bool enabled)
|
||||
{
|
||||
if(_muxer.setSourceAutoSelectEnabled(enabled))
|
||||
@@ -367,6 +293,7 @@ void Hyperion::setNewComponentState(const hyperion::Components& component, const
|
||||
|
||||
void Hyperion::setComponentState(const hyperion::Components component, const bool state)
|
||||
{
|
||||
// TODO REMOVE THIS STEP
|
||||
emit componentStateChanged(component, state);
|
||||
}
|
||||
|
||||
@@ -547,7 +474,7 @@ void Hyperion::setVideoMode(const VideoMode& mode)
|
||||
|
||||
const VideoMode & Hyperion::getCurrentVideoMode()
|
||||
{
|
||||
return _daemon->getVideoMode();
|
||||
return _currVideoMode;
|
||||
}
|
||||
|
||||
const QString & Hyperion::getActiveDevice()
|
||||
@@ -567,9 +494,6 @@ void Hyperion::updatedComponentState(const hyperion::Components comp, const bool
|
||||
_prevCompId = comp;
|
||||
_raw2ledAdjustment->setBacklightEnabled((_prevCompId != hyperion::COMP_COLOR && _prevCompId != hyperion::COMP_EFFECT));
|
||||
}
|
||||
|
||||
if(comp == hyperion::COMP_ALL)
|
||||
_muxer.setEnable(state); // first muxer to update all inputs
|
||||
}
|
||||
|
||||
void Hyperion::update()
|
||||
|
207
libsrc/hyperion/HyperionIManager.cpp
Normal file
207
libsrc/hyperion/HyperionIManager.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
|
||||
// hyperion
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <db/InstanceTable.h>
|
||||
|
||||
// qt
|
||||
#include <QThread>
|
||||
|
||||
HyperionIManager* HyperionIManager::HIMinstance;
|
||||
|
||||
HyperionIManager::HyperionIManager(const QString& rootPath, QObject* parent)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("HYPERION"))
|
||||
, _instanceTable( new InstanceTable(rootPath, this) )
|
||||
, _rootPath( rootPath )
|
||||
{
|
||||
HIMinstance = this;
|
||||
qRegisterMetaType<instanceState>("instanceState");
|
||||
}
|
||||
|
||||
Hyperion* HyperionIManager::getHyperionInstance(const quint8& instance)
|
||||
{
|
||||
if(_runningInstances.contains(instance))
|
||||
return _runningInstances.value(instance);
|
||||
|
||||
Warning(_log,"The requested instance index '%d' with name '%s' isn't running, return main instance", instance, QSTRING_CSTR(_instanceTable->getNamebyIndex(instance)));
|
||||
return _runningInstances.value(0);
|
||||
}
|
||||
|
||||
const QVector<QVariantMap> HyperionIManager::getInstanceData()
|
||||
{
|
||||
QVector<QVariantMap> instances = _instanceTable->getAllInstances();
|
||||
for( auto & entry : instances)
|
||||
{
|
||||
// add running state
|
||||
entry["running"] = _runningInstances.contains(entry["instance"].toInt());
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
void HyperionIManager::startAll()
|
||||
{
|
||||
for(const auto entry : _instanceTable->getAllInstances(true))
|
||||
{
|
||||
startInstance(entry["instance"].toInt());
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::stopAll()
|
||||
{
|
||||
// copy the instances due to loop corruption, even with .erase() return next iter
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
instance->stop();
|
||||
}
|
||||
}
|
||||
|
||||
const bool HyperionIManager::startInstance(const quint8& inst, const bool& block)
|
||||
{
|
||||
if(_instanceTable->instanceExist(inst))
|
||||
{
|
||||
if(!_runningInstances.contains(inst) && !_startQueue.contains(inst))
|
||||
{
|
||||
QThread* hyperionThread = new QThread();
|
||||
Hyperion* hyperion = new Hyperion(inst);
|
||||
hyperion->moveToThread(hyperionThread);
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
// to Hyperion
|
||||
connect(HyperionIManager::getInstance(), &HyperionIManager::newVideoMode, hyperion, &Hyperion::newVideoMode);
|
||||
|
||||
// add to queue and start
|
||||
_startQueue << inst;
|
||||
hyperionThread->start();
|
||||
|
||||
// update db
|
||||
_instanceTable->setLastUse(inst);
|
||||
_instanceTable->setEnable(inst, true);
|
||||
|
||||
if(block)
|
||||
{
|
||||
while(!hyperionThread->isRunning()){};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
Debug(_log,"Can't start Hyperion instance index '%d' with name '%s' it's already running or queued for start", inst, QSTRING_CSTR(_instanceTable->getNamebyIndex(inst)));
|
||||
return false;
|
||||
}
|
||||
Debug(_log,"Can't start Hyperion instance index '%d' it doesn't exist in DB", inst);
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool HyperionIManager::stopInstance(const quint8& inst, const bool& block)
|
||||
{
|
||||
// inst 0 can't be stopped
|
||||
if(!isInstAllowed(inst))
|
||||
return false;
|
||||
|
||||
if(_instanceTable->instanceExist(inst))
|
||||
{
|
||||
if(_runningInstances.contains(inst))
|
||||
{
|
||||
// notify a ON_STOP rather sooner than later, queued signal listener should have some time to drop the pointer before it's deleted
|
||||
emit instanceStateChanged(H_ON_STOP, inst);
|
||||
Hyperion* hyperion = _runningInstances.value(inst);
|
||||
hyperion->stop();
|
||||
|
||||
// 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)));
|
||||
return false;
|
||||
}
|
||||
Debug(_log,"Can't stop Hyperion instance index '%d' it doesn't exist in DB", inst);
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool HyperionIManager::createInstance(const QString& name, const bool& start)
|
||||
{
|
||||
quint8 inst;
|
||||
if(_instanceTable->createInstance(name, inst))
|
||||
{
|
||||
Info(_log,"New Hyperion instance created with name '%s'",QSTRING_CSTR(name));
|
||||
emit instanceStateChanged(H_CREATED, inst, name);
|
||||
emit change();
|
||||
|
||||
if(start)
|
||||
startInstance(inst);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool HyperionIManager::deleteInstance(const quint8& inst)
|
||||
{
|
||||
// inst 0 can't be deleted
|
||||
if(!isInstAllowed(inst))
|
||||
return false;
|
||||
|
||||
// stop it if required as blocking
|
||||
stopInstance(inst, true);
|
||||
|
||||
if(_instanceTable->deleteInstance(inst))
|
||||
{
|
||||
Info(_log,"Hyperion instance with index '%d' has been deleted", inst);
|
||||
emit instanceStateChanged(H_DELETED, inst);
|
||||
emit change();
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool HyperionIManager::saveName(const quint8& inst, const QString& name)
|
||||
{
|
||||
if(_instanceTable->saveName(inst, name))
|
||||
{
|
||||
emit change();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void HyperionIManager::handleFinished()
|
||||
{
|
||||
Hyperion* hyperion = qobject_cast<Hyperion*>(sender());
|
||||
const quint8 & instance = hyperion->getInstanceIndex();
|
||||
|
||||
Info(_log,"Hyperion instance '%s' has been stopped", QSTRING_CSTR(_instanceTable->getNamebyIndex(instance)));
|
||||
|
||||
_runningInstances.remove(instance);
|
||||
hyperion->deleteLater();
|
||||
emit instanceStateChanged(H_STOPPED, instance);
|
||||
emit change();
|
||||
|
||||
}
|
||||
|
||||
void HyperionIManager::handleStarted()
|
||||
{
|
||||
Hyperion* hyperion = qobject_cast<Hyperion*>(sender());
|
||||
const quint8 & instance = hyperion->getInstanceIndex();
|
||||
|
||||
Info(_log,"Hyperion instance '%s' has been started", QSTRING_CSTR(_instanceTable->getNamebyIndex(instance)));
|
||||
|
||||
_startQueue.removeAll(instance);
|
||||
_runningInstances.insert(instance, hyperion);
|
||||
emit instanceStateChanged(H_STARTED, instance);
|
||||
emit change();
|
||||
}
|
@@ -22,9 +22,9 @@ PriorityMuxer::PriorityMuxer(int ledCount)
|
||||
, _activeInputs()
|
||||
, _lowestPriorityInfo()
|
||||
, _sourceAutoSelectEnabled(true)
|
||||
, _updateTimer(new QTimer(this))
|
||||
, _timer(new QTimer(this))
|
||||
, _blockTimer(new QTimer(this))
|
||||
, _updateTimer(new QTimer())
|
||||
, _timer(new QTimer())
|
||||
, _blockTimer(new QTimer())
|
||||
{
|
||||
// init lowest priority info
|
||||
_lowestPriorityInfo.priority = PriorityMuxer::LOWEST_PRIORITY;
|
||||
|
@@ -12,13 +12,10 @@
|
||||
// write config to filesystem
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
// hyperion
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
QJsonObject SettingsManager::schemaJson;
|
||||
|
||||
SettingsManager::SettingsManager(const quint8& instance, const QString& configFile, Hyperion* hyperion)
|
||||
: _hyperion(hyperion)
|
||||
SettingsManager::SettingsManager(const quint8& instance, QObject* parent)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("SettingsManager"))
|
||||
, _sTable(new SettingsTable(instance, this))
|
||||
{
|
||||
@@ -41,41 +38,6 @@ SettingsManager::SettingsManager(const quint8& instance, const QString& configFi
|
||||
if(!JsonUtils::readFile(":/hyperion_default.config", defaultConfig, _log))
|
||||
throw std::runtime_error("Failed to read default config");
|
||||
|
||||
// TODO BEGIN - remove when database migration is done
|
||||
|
||||
Info(_log, "Selected configuration file: %s", QSTRING_CSTR(configFile));
|
||||
QJsonSchemaChecker schemaCheckerT;
|
||||
schemaCheckerT.setSchema(schemaJson);
|
||||
|
||||
if(!JsonUtils::readFile(configFile, _qconfig, _log))
|
||||
throw std::runtime_error("Failed to load config!");
|
||||
|
||||
// validate config with schema and correct it if required
|
||||
QPair<bool, bool> validate = schemaCheckerT.validate(_qconfig);
|
||||
|
||||
// errors in schema syntax, abort
|
||||
if (!validate.second)
|
||||
{
|
||||
foreach (auto & schemaError, schemaCheckerT.getMessages())
|
||||
Error(_log, "Schema Syntax Error: %s", QSTRING_CSTR(schemaError));
|
||||
|
||||
throw std::runtime_error("ERROR: Hyperion schema has syntax errors!");
|
||||
}
|
||||
// errors in configuration, correct it!
|
||||
if (!validate.first)
|
||||
{
|
||||
Warning(_log,"Errors have been found in the configuration file. Automatic correction has been applied");
|
||||
_qconfig = schemaCheckerT.getAutoCorrectedConfig(_qconfig);
|
||||
|
||||
foreach (auto & schemaError, schemaCheckerT.getMessages())
|
||||
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
|
||||
|
||||
if (!JsonUtils::write(configFile, _qconfig, _log))
|
||||
throw std::runtime_error("ERROR: Can't save configuration file, aborting");
|
||||
}
|
||||
|
||||
// TODO END - remove when database migration is done
|
||||
|
||||
// transform json to string lists
|
||||
QStringList keyList = defaultConfig.keys();
|
||||
QStringList defValueList;
|
||||
@@ -163,13 +125,6 @@ bool SettingsManager::saveSettings(QJsonObject config, const bool& correct)
|
||||
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
|
||||
}
|
||||
|
||||
// save data to file
|
||||
if(_hyperion != nullptr)
|
||||
{
|
||||
if(!JsonUtils::write(_hyperion->getConfigFilePath(), config, _log))
|
||||
return false;
|
||||
}
|
||||
|
||||
// store the new config
|
||||
_qconfig = config;
|
||||
|
||||
|
@@ -10,8 +10,6 @@
|
||||
#include "hyperion/Hyperion.h"
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
LedDevice::LedDevice(const QJsonObject& config, QObject* parent)
|
||||
: QObject(parent)
|
||||
, _devConfig(config)
|
||||
|
@@ -10,7 +10,10 @@
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
// Hyperion instance manager includes
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
|
||||
// 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)
|
||||
: QObject(parent)
|
||||
@@ -20,7 +23,7 @@ ProtoClientConnection::ProtoClientConnection(QTcpSocket* socket, const int &time
|
||||
, _timeoutTimer(new QTimer(this))
|
||||
, _timeout(timeout * 1000)
|
||||
, _priority()
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _hyperion(HyperionIManager::getInstance()->getHyperionInstance())
|
||||
{
|
||||
// timer setup
|
||||
_timeoutTimer->setSingleShot(true);
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "SSDPDescription.h"
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <HyperionConfig.h>
|
||||
#include <hyperion/AuthManager.h>
|
||||
|
||||
#include <QNetworkInterface>
|
||||
#include <QNetworkConfigurationManager>
|
||||
@@ -140,5 +141,5 @@ const QString SSDPHandler::buildDesc()
|
||||
/// %2 friendly name Hyperion 2.0.0 (192.168.0.177)
|
||||
/// %3 modelNumber 2.0.0
|
||||
/// %4 serialNumber / UDN (H ID) Fjsa723dD0....
|
||||
return SSDP_DESCRIPTION.arg(getBaseAddress(), QString("Hyperion (%2)").arg(_localAddress), QString(HYPERION_VERSION), Hyperion::getInstance()->getId());
|
||||
return SSDP_DESCRIPTION.arg(getBaseAddress(), QString("Hyperion (%2)").arg(_localAddress), QString(HYPERION_VERSION), AuthManager::getInstance()->getID());
|
||||
}
|
||||
|
@@ -1,10 +1,14 @@
|
||||
#include <ssdp/SSDPServer.h>
|
||||
|
||||
// util
|
||||
// utils
|
||||
#include <utils/SysInfo.h>
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
// Hyperion
|
||||
#include <HyperionConfig.h>
|
||||
|
||||
// auth manager
|
||||
#include <hyperion/AuthManager.h>
|
||||
|
||||
#include <QUdpSocket>
|
||||
#include <QDateTime>
|
||||
|
||||
@@ -96,7 +100,7 @@ void SSDPServer::initServer()
|
||||
_serverHeader = data.prettyName+"/"+data.productVersion+" UPnP/1.0 Hyperion/"+QString(HYPERION_VERSION);
|
||||
|
||||
// usn uuid
|
||||
_uuid = Hyperion::getInstance()->getId();
|
||||
_uuid = AuthManager::getInstance()->getID();
|
||||
|
||||
connect(_udpSocket, &QUdpSocket::readyRead, this, &SSDPServer::readPendingDatagrams);
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@
|
||||
|
||||
// hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <hyperion/HyperionIManager.h>
|
||||
#include "HyperionConfig.h"
|
||||
|
||||
// utils includes
|
||||
@@ -27,9 +28,6 @@ UDPListener::UDPListener(const QJsonDocument& config)
|
||||
, _listenPort(0)
|
||||
, _netOrigin(NetOrigin::getInstance())
|
||||
{
|
||||
// listen for component change
|
||||
connect(Hyperion::getInstance(), &Hyperion::componentStateChanged, this, &UDPListener::componentStateChanged);
|
||||
|
||||
// init
|
||||
handleSettingsUpdate(settings::UDPLISTENER, config);
|
||||
}
|
||||
@@ -41,14 +39,14 @@ UDPListener::~UDPListener()
|
||||
delete _server;
|
||||
}
|
||||
|
||||
|
||||
void UDPListener::start()
|
||||
{
|
||||
if ( active() )
|
||||
return;
|
||||
|
||||
QHostAddress mcastGroup;
|
||||
if (_listenAddress.isInSubnet(QHostAddress::parseSubnet("224.0.0.0/4"))) {
|
||||
if (_listenAddress.isInSubnet(QHostAddress::parseSubnet("224.0.0.0/4")))
|
||||
{
|
||||
mcastGroup = _listenAddress;
|
||||
}
|
||||
|
||||
@@ -59,7 +57,8 @@ void UDPListener::start()
|
||||
else
|
||||
{
|
||||
Info(_log, "Started, listening on %s:%d", _listenAddress.toString().toStdString().c_str(), _listenPort);
|
||||
if (!mcastGroup.isNull()) {
|
||||
if (!mcastGroup.isNull())
|
||||
{
|
||||
bool joinGroupOK = _server->joinMulticastGroup(_listenAddress);
|
||||
InfoIf ( joinGroupOK, _log, "Multicast enabled");
|
||||
WarningIf( ! joinGroupOK, _log, "Multicast failed");
|
||||
@@ -78,8 +77,6 @@ void UDPListener::start()
|
||||
_serviceRegister->registerService("_hyperiond-udp._udp", _listenPort);
|
||||
}
|
||||
}
|
||||
|
||||
Hyperion::getInstance()->getComponentRegister().componentStateChanged(COMP_UDPLISTENER, _isActive);
|
||||
}
|
||||
|
||||
void UDPListener::stop()
|
||||
@@ -90,10 +87,9 @@ void UDPListener::stop()
|
||||
_server->close();
|
||||
_isActive = false;
|
||||
Info(_log, "Stopped");
|
||||
Hyperion::getInstance()->getComponentRegister().componentStateChanged(COMP_UDPLISTENER, _isActive);
|
||||
}
|
||||
|
||||
void UDPListener::componentStateChanged(const hyperion::Components component, bool enable)
|
||||
void UDPListener::updatedComponentState(const hyperion::Components component, bool enable)
|
||||
{
|
||||
if (component == COMP_UDPLISTENER)
|
||||
{
|
||||
@@ -110,10 +106,10 @@ uint16_t UDPListener::getPort() const
|
||||
return _server->localPort();
|
||||
}
|
||||
|
||||
|
||||
void UDPListener::readPendingDatagrams()
|
||||
{
|
||||
while (_server->hasPendingDatagrams()) {
|
||||
while (_server->hasPendingDatagrams())
|
||||
{
|
||||
QByteArray datagram;
|
||||
datagram.resize(_server->pendingDatagramSize());
|
||||
QHostAddress sender;
|
||||
@@ -126,7 +122,6 @@ void UDPListener::readPendingDatagrams()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UDPListener::processTheDatagram(const QByteArray * datagram, const QHostAddress * sender)
|
||||
{
|
||||
int packetLedCount = datagram->size()/3;
|
||||
@@ -134,7 +129,8 @@ void UDPListener::processTheDatagram(const QByteArray * datagram, const QHostAdd
|
||||
|
||||
std::vector<ColorRgb> _ledColors(packetLedCount, ColorRgb::BLACK);
|
||||
|
||||
for (int ledIndex=0; ledIndex < packetLedCount; ledIndex++) {
|
||||
for (int ledIndex=0; ledIndex < packetLedCount; ledIndex++)
|
||||
{
|
||||
ColorRgb & rgb = _ledColors[ledIndex];
|
||||
rgb.red = datagram->at(ledIndex*3+0);
|
||||
rgb.green = datagram->at(ledIndex*3+1);
|
||||
|
@@ -95,12 +95,6 @@ namespace FileUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
QString convertPath(const QString path)
|
||||
{
|
||||
QString p = path;
|
||||
return p.replace(QString("$ROOT"), Hyperion::getInstance()->getRootPath());
|
||||
}
|
||||
|
||||
void resolveFileError(const QFile& file, Logger* log)
|
||||
{
|
||||
QFile::FileError error = file.error();
|
||||
|
Reference in New Issue
Block a user