2016-09-07 20:10:37 +02:00
|
|
|
#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)
|
|
|
|
, _log(Logger::getInstance("ComponentRegister"))
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
2018-12-27 23:11:32 +01:00
|
|
|
// init all comps to false
|
|
|
|
QVector<hyperion::Components> vect;
|
2019-07-23 22:00:43 +02:00
|
|
|
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));
|
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentRegister::~ComponentRegister()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
bool ComponentRegister::setHyperionEnable(const bool& state)
|
|
|
|
{
|
|
|
|
if(!state && _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)
|
|
|
|
_hyperion->setComponentState(comp.first, false);
|
|
|
|
}
|
|
|
|
componentStateChanged(COMP_ALL, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(state && !_prevComponentStates.empty())
|
|
|
|
{
|
|
|
|
Debug(_log,"Enable Hyperion, recover previous component states");
|
|
|
|
for(const auto comp : _prevComponentStates)
|
|
|
|
{
|
|
|
|
// if comp was enabled, enable again
|
|
|
|
if(comp.second)
|
|
|
|
_hyperion->setComponentState(comp.first, true);
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
_prevComponentStates.clear();
|
|
|
|
componentStateChanged(COMP_ALL, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-28 18:12:45 +01:00
|
|
|
int ComponentRegister::isComponentEnabled(const hyperion::Components& comp) const
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
2018-12-28 18:12:45 +01:00
|
|
|
return (_componentStates.count(comp)) ? _componentStates.at(comp) : -1;
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
void ComponentRegister::componentStateChanged(const hyperion::Components comp, const bool activated)
|
|
|
|
{
|
|
|
|
if(_componentStates[comp] != activated)
|
2016-09-07 20:10:37 +02:00
|
|
|
{
|
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);
|
2016-09-07 20:10:37 +02:00
|
|
|
}
|
|
|
|
}
|