mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Add Suspend/Resume support (#1535)
* Add Suspend/Resume support * Support Suspend/Resume/Restart via API, UI and Systray * Support screen lock/unlock scenario * Handle idle scenario * Align with fix for #1368 * Update Windows build * Refactor SuspendHandler to maintain state * Do not start BG-Effect, if system goes into suspend mode * Correct Idle and Resume interaction
This commit is contained in:
20
libsrc/api/JSONRPC_schema/schema-system.json
Normal file
20
libsrc/api/JSONRPC_schema/schema-system.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["system"]
|
||||
},
|
||||
"tan" : {
|
||||
"type" : "integer"
|
||||
},
|
||||
"subcommand": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum": [ "restart", "resume", "suspend", "toggleSuspend", "idle", "toggleIdle" ]
|
||||
}
|
||||
},
|
||||
"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", "instance", "leddevice", "inputsource", "service", "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", "leddevice", "inputsource", "service", "system", "transform", "correction", "temperature" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,8 @@
|
||||
<file alias="schema-instance">JSONRPC_schema/schema-instance.json</file>
|
||||
<file alias="schema-leddevice">JSONRPC_schema/schema-leddevice.json</file>
|
||||
<file alias="schema-inputsource">JSONRPC_schema/schema-inputsource.json</file>
|
||||
<file alias="schema-service">JSONRPC_schema/schema-service.json</file>
|
||||
<file alias="schema-service">JSONRPC_schema/schema-service.json</file>
|
||||
<file alias="schema-system">JSONRPC_schema/schema-system.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>
|
||||
|
@@ -120,6 +120,12 @@ void JsonAPI::initialize()
|
||||
_jsonCB->setSubscriptionsTo(_hyperion);
|
||||
connect(this, &JsonAPI::forwardJsonMessage, _hyperion, &Hyperion::forwardJsonMessage);
|
||||
}
|
||||
|
||||
//notify instance manager on suspend/resume/idle requests
|
||||
connect(this, &JsonAPI::suspendAll, _instanceManager, &HyperionIManager::triggerSuspend);
|
||||
connect(this, &JsonAPI::toggleSuspendAll, _instanceManager, &HyperionIManager::triggerToggleSuspend);
|
||||
connect(this, &JsonAPI::idleAll, _instanceManager, &HyperionIManager::triggerIdle);
|
||||
connect(this, &JsonAPI::toggleIdleAll, _instanceManager, &HyperionIManager::triggerToggleIdle);
|
||||
}
|
||||
|
||||
bool JsonAPI::handleInstanceSwitch(quint8 inst, bool forced)
|
||||
@@ -236,6 +242,8 @@ proceed:
|
||||
handleInputSourceCommand(message, command, tan);
|
||||
else if (command == "service")
|
||||
handleServiceCommand(message, command, tan);
|
||||
else if (command == "system")
|
||||
handleSystemCommand(message, command, tan);
|
||||
|
||||
// BEGIN | The following commands are deprecated but used to ensure backward compatibility with hyperion Classic remote control
|
||||
else if (command == "clearall")
|
||||
@@ -920,15 +928,15 @@ void JsonAPI::handleAdjustmentCommand(const QJsonObject &message, const QString
|
||||
colorAdjustment->_rgbTransform.setBrightnessCompensation(adjustment["brightnessCompensation"].toInt());
|
||||
}
|
||||
|
||||
if (adjustment.contains("saturationGain"))
|
||||
{
|
||||
colorAdjustment->_okhsvTransform.setSaturationGain(adjustment["saturationGain"].toDouble());
|
||||
}
|
||||
if (adjustment.contains("saturationGain"))
|
||||
{
|
||||
colorAdjustment->_okhsvTransform.setSaturationGain(adjustment["saturationGain"].toDouble());
|
||||
}
|
||||
|
||||
if (adjustment.contains("brightnessGain"))
|
||||
{
|
||||
{
|
||||
colorAdjustment->_okhsvTransform.setBrightnessGain(adjustment["brightnessGain"].toDouble());
|
||||
}
|
||||
}
|
||||
|
||||
// commit the changes
|
||||
_hyperion->adjustmentsUpdated();
|
||||
@@ -1799,6 +1807,49 @@ void JsonAPI::handleServiceCommand(const QJsonObject &message, const QString &co
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAPI::handleSystemCommand(const QJsonObject &message, const QString &command, int tan)
|
||||
{
|
||||
DebugIf(verbose, _log, "message: [%s]", QString(QJsonDocument(message).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||
|
||||
const QString &subc = message["subcommand"].toString().trimmed();
|
||||
|
||||
if (subc == "suspend")
|
||||
{
|
||||
emit suspendAll(true);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "resume")
|
||||
{
|
||||
emit suspendAll(false);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "restart")
|
||||
{
|
||||
Process::restartHyperion(11);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "toggleSuspend")
|
||||
{
|
||||
emit toggleSuspendAll();
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "idle")
|
||||
{
|
||||
emit idleAll(true);
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else if (subc == "toggleIdle")
|
||||
{
|
||||
emit toggleIdleAll();
|
||||
sendSuccessReply(command + "-" + subc, tan);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString full_command = command + "-" + subc;
|
||||
sendErrorReply("Unknown or missing subcommand", full_command, tan);
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAPI::handleNotImplemented(const QString &command, int tan)
|
||||
{
|
||||
sendErrorReply("Command not implemented", command, tan);
|
||||
|
@@ -55,12 +55,13 @@ ComponentRegister::ComponentRegister(Hyperion* hyperion)
|
||||
vect << COMP_FORWARDER;
|
||||
#endif
|
||||
|
||||
for(auto e : vect)
|
||||
for(auto e : qAsConst(vect))
|
||||
{
|
||||
_componentStates.emplace(e, (e == COMP_ALL));
|
||||
}
|
||||
|
||||
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &ComponentRegister::handleCompStateChangeRequest);
|
||||
connect(_hyperion, &Hyperion::compStateChangeRequestAll, this, &ComponentRegister::handleCompStateChangeRequestAll);
|
||||
}
|
||||
|
||||
ComponentRegister::~ComponentRegister()
|
||||
@@ -72,56 +73,93 @@ int ComponentRegister::isComponentEnabled(hyperion::Components comp) const
|
||||
return (_componentStates.count(comp)) ? _componentStates.at(comp) : -1;
|
||||
}
|
||||
|
||||
void ComponentRegister::setNewComponentState(hyperion::Components comp, bool activated)
|
||||
void ComponentRegister::setNewComponentState(hyperion::Components comp, bool isActive)
|
||||
{
|
||||
|
||||
if (_componentStates.count(comp) > 0)
|
||||
{
|
||||
if (_componentStates[comp] != activated)
|
||||
if (_componentStates[comp] != isActive)
|
||||
{
|
||||
Debug(_log, "%s: %s", componentToString(comp), (activated ? "enabled" : "disabled"));
|
||||
_componentStates[comp] = activated;
|
||||
Debug(_log, "%s: %s", componentToString(comp), (isActive ? "enabled" : "disabled"));
|
||||
_componentStates[comp] = isActive;
|
||||
// emit component has changed state
|
||||
emit updatedComponentState(comp, activated);
|
||||
emit updatedComponentState(comp, isActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentRegister::handleCompStateChangeRequest(hyperion::Components comps, bool activated)
|
||||
void ComponentRegister::handleCompStateChangeRequest(hyperion::Components comps, bool isActive)
|
||||
{
|
||||
if(comps == COMP_ALL && !_inProgress)
|
||||
if(comps == COMP_ALL )
|
||||
{
|
||||
handleCompStateChangeRequestAll(isActive,{});
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentRegister::handleCompStateChangeRequestAll(bool isActive, const ComponentList& excludeList)
|
||||
{
|
||||
if (!_inProgress)
|
||||
{
|
||||
_inProgress = true;
|
||||
if(!activated && _prevComponentStates.empty())
|
||||
if(!isActive)
|
||||
{
|
||||
Debug(_log,"Disable Hyperion, store current component states");
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
Debug(_log,"Disable Hyperion instance, store current components' state");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log,"Disable selected Hyperion components, store their current state");
|
||||
}
|
||||
|
||||
for(const auto &comp : _componentStates)
|
||||
{
|
||||
// save state
|
||||
_prevComponentStates.emplace(comp.first, comp.second);
|
||||
// disable if enabled
|
||||
if(comp.second)
|
||||
if (!excludeList.contains(comp.first) && comp.first != COMP_ALL)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, false);
|
||||
// save state
|
||||
_prevComponentStates.emplace(comp.first, comp.second);
|
||||
// disable if enabled
|
||||
if(comp.second)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
setNewComponentState(COMP_ALL, false);
|
||||
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
setNewComponentState(COMP_ALL, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(activated && !_prevComponentStates.empty())
|
||||
if(isActive && !_prevComponentStates.empty())
|
||||
{
|
||||
Debug(_log,"Enable Hyperion, recover previous component states");
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
Debug(_log,"Enable Hyperion instance, restore components' previous state");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log,"Enable selected Hyperion components, restore their previous state");
|
||||
}
|
||||
|
||||
for(const auto &comp : _prevComponentStates)
|
||||
{
|
||||
// if comp was enabled, enable again
|
||||
if(comp.second)
|
||||
if (!excludeList.contains(comp.first) && comp.first != COMP_ALL)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, true);
|
||||
// if comp was enabled, enable again
|
||||
if(comp.second)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
_prevComponentStates.clear();
|
||||
setNewComponentState(COMP_ALL, true);
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
setNewComponentState(COMP_ALL, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
_inProgress = false;
|
||||
|
@@ -75,6 +75,8 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
|
||||
#endif
|
||||
, _readOnlyMode(readonlyMode)
|
||||
{
|
||||
qRegisterMetaType<ComponentList>("ComponentList");
|
||||
|
||||
QString subComponent = "I"+QString::number(instance);
|
||||
this->setProperty("instance", (QString) subComponent);
|
||||
|
||||
@@ -117,8 +119,9 @@ void Hyperion::start()
|
||||
connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability);
|
||||
connect(_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged);
|
||||
|
||||
// listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions
|
||||
// connect(&_componentRegister, &ComponentRegister::updatedComponentState, this, &Hyperion::updatedComponentState);
|
||||
// listen for suspend/resume, idle requests to perform core activation/deactivation actions
|
||||
connect(this, &Hyperion::suspendRequest, this, &Hyperion::setSuspend);
|
||||
connect(this, &Hyperion::idleRequest, this, &Hyperion::setIdle);
|
||||
|
||||
// listen for settings updates of this instance (LEDS & COLOR)
|
||||
connect(_settingsManager, &SettingsManager::settingsChanged, this, &Hyperion::handleSettingsUpdate);
|
||||
@@ -377,6 +380,20 @@ int Hyperion::isComponentEnabled(hyperion::Components comp) const
|
||||
return _componentRegister->isComponentEnabled(comp);
|
||||
}
|
||||
|
||||
void Hyperion::setSuspend(bool isSuspend)
|
||||
{
|
||||
bool enable = !isSuspend;
|
||||
emit compStateChangeRequestAll(enable);
|
||||
}
|
||||
|
||||
void Hyperion::setIdle(bool isIdle)
|
||||
{
|
||||
clear(-1);
|
||||
|
||||
bool enable = !isIdle;
|
||||
emit compStateChangeRequestAll(enable, {hyperion::COMP_LEDDEVICE, hyperion::COMP_SMOOTHING} );
|
||||
}
|
||||
|
||||
void Hyperion::registerInput(int priority, hyperion::Components component, const QString& origin, const QString& owner, unsigned smooth_cfg)
|
||||
{
|
||||
_muxer->registerInput(priority, component, origin, owner, smooth_cfg);
|
||||
|
@@ -63,13 +63,43 @@ void HyperionIManager::stopAll()
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::toggleStateAllInstances(bool pause)
|
||||
void HyperionIManager::suspend()
|
||||
{
|
||||
Info(_log,"Suspend all instances and enabled components");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->suspendRequest(true);
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::resume()
|
||||
{
|
||||
Info(_log,"Resume all instances and enabled components");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->suspendRequest(false);
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::toggleIdle(bool isIdle)
|
||||
{
|
||||
Info(_log,"Put all instances in %s state", isIdle ? "idle" : "working");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->idleRequest(isIdle);
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::toggleStateAllInstances(bool enable)
|
||||
{
|
||||
// copy the instances due to loop corruption, even with .erase() return next iter
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->compStateChangeRequest(hyperion::COMP_ALL, pause);
|
||||
emit instance->compStateChangeRequest(hyperion::COMP_ALL, enable);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user