hyperion.ng/libsrc/hyperion/ComponentRegister.cpp

77 lines
2.1 KiB
C++
Raw Normal View History

#include <hyperion/ComponentRegister.h>
#include <iostream>
2018-12-27 23:11:32 +01:00
#include <hyperion/Hyperion.h>
using namespace hyperion;
ComponentRegister::ComponentRegister(Hyperion* hyperion)
: _hyperion(hyperion)
2020-07-19 15:37:47 +02:00
, _log(Logger::getInstance("COMPONENTREG"))
{
2018-12-27 23:11:32 +01:00
// init all comps to false
QVector<hyperion::Components> vect;
vect << COMP_ALL << COMP_SMOOTHING << COMP_BLACKBORDER << COMP_FORWARDER << COMP_BOBLIGHTSERVER << COMP_GRABBER << COMP_V4L << COMP_LEDDEVICE;
2018-12-27 23:11:32 +01:00
for(auto e : vect)
{
_componentStates.emplace(e, ((e == COMP_ALL) ? true : false));
}
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &ComponentRegister::handleCompStateChangeRequest);
}
ComponentRegister::~ComponentRegister()
2018-12-27 23:11:32 +01:00
{
}
2020-08-08 13:09:15 +02:00
int ComponentRegister::isComponentEnabled(hyperion::Components comp) const
{
return (_componentStates.count(comp)) ? _componentStates.at(comp) : -1;
2018-12-27 23:11:32 +01:00
}
2020-08-08 13:09:15 +02:00
void ComponentRegister::setNewComponentState(hyperion::Components comp, bool activated)
2018-12-27 23:11:32 +01:00
{
if(_componentStates[comp] != activated)
{
2018-12-27 23:11:32 +01:00
Debug( _log, "%s: %s", componentToString(comp), (activated? "enabled" : "disabled"));
_componentStates[comp] = activated;
// emit component has changed state
emit updatedComponentState(comp, activated);
}
}
2020-08-08 13:09:15 +02:00
void ComponentRegister::handleCompStateChangeRequest(hyperion::Components comps, bool activated)
{
if(comps == COMP_ALL && !_inProgress)
{
_inProgress = true;
if(!activated && _prevComponentStates.empty())
{
Debug(_log,"Disable Hyperion, store current component states");
for(const auto comp : _componentStates)
{
// save state
_prevComponentStates.emplace(comp.first, comp.second);
// disable if enabled
if(comp.second)
emit _hyperion->compStateChangeRequest(comp.first, false);
}
setNewComponentState(COMP_ALL, false);
}
else if(activated && !_prevComponentStates.empty())
{
Debug(_log,"Enable Hyperion, recover previous component states");
for(const auto comp : _prevComponentStates)
{
// if comp was enabled, enable again
if(comp.second)
emit _hyperion->compStateChangeRequest(comp.first, true);
}
_prevComponentStates.clear();
setNewComponentState(COMP_ALL, true);
}
_inProgress = false;
}
2020-03-05 18:29:10 +01:00
}