140 lines
4.0 KiB
C++
Executable File
140 lines
4.0 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* One Effect Handler. Destroyed/created on Range change
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Gerlinde Rudolphus, SLTE, 2021-05-31
|
|
*/
|
|
|
|
#include "handeleffect.h"
|
|
#include <QUrlQuery>
|
|
#include <QTimer>
|
|
|
|
namespace BuildingControlUnit
|
|
{
|
|
|
|
HandelEffect::HandelEffect(QObject *parent, const QString &loggerchannel)
|
|
: QObject(parent)
|
|
, m_logger(getLogger(QStringLiteral("HandelSingleEffect.") + loggerchannel))
|
|
{
|
|
}
|
|
|
|
bool HandelEffect::init(const QVector<Action *> &actions, int repetitions = 1)
|
|
{
|
|
if (actions.isEmpty())
|
|
return false;
|
|
|
|
m_actions = actions;
|
|
m_currentAction = nullptr;
|
|
m_repeatCount = repetitions; // Usually The action list is only worked over once.
|
|
return true;
|
|
}
|
|
|
|
|
|
//void handleEffect(const Effect *effect, QVector<Action *> actions, int damage, bool background);
|
|
void HandelEffect::handleEffect()
|
|
{
|
|
// No current Action? Start over or be ready
|
|
if (!m_currentAction)
|
|
{
|
|
// Infinite Repeat Actions must start with repeatCount = -1
|
|
if (m_repeatCount != 0)
|
|
{
|
|
m_currentAction = m_actions.first();
|
|
--m_repeatCount;
|
|
}
|
|
else
|
|
{
|
|
emit effectReady();
|
|
deleteLater();
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int index = m_actions.indexOf(m_currentAction);
|
|
++index;
|
|
m_currentAction = m_actions.value(index, nullptr);
|
|
if (!m_currentAction)
|
|
{
|
|
QTimer::singleShot(0, this, &HandelEffect::handleEffect);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
switch (m_currentAction->aclass)
|
|
{
|
|
case AC_Unset:
|
|
DEBUG_LOG(m_logger) << "---- This is unset ----";
|
|
break;
|
|
case AC_Standard:
|
|
{
|
|
DEBUG_LOG(m_logger) << "---- This is a standard Action ----";
|
|
if (!m_currentAction->url.isEmpty())
|
|
{
|
|
// Todo: Is there a standard action valid for BSM? If so, we need to consider!
|
|
DEBUG_LOG(m_logger) << "---- emit newHttpRequest(a->url):" << m_currentAction->url.toString();
|
|
emit newHttpRequest(m_currentAction->url);
|
|
}
|
|
break;
|
|
}
|
|
case AC_Repeat:
|
|
{
|
|
DEBUG_LOG(m_logger) << "---- This is a Repeat Action";
|
|
const RepeatAction *ra = static_cast<const RepeatAction *>(m_currentAction);
|
|
|
|
HandelEffect *he = new HandelEffect(this);
|
|
he->init(ra->actions, ra->count);
|
|
connect(he, &HandelEffect::effectReady, this, &HandelEffect::handleEffect);
|
|
connect(he, &HandelEffect::newHttpRequest, this, &HandelEffect::newHttpRequest);
|
|
connect(he, &HandelEffect::triggerAllFlashlights, this, &HandelEffect::triggerAllFlashlights);
|
|
QTimer::singleShot(0, he, &HandelEffect::handleEffect);
|
|
// To avoid the Timer call at the end of this method:
|
|
return;
|
|
// So this instance does nothing unless child-he is ready.
|
|
}
|
|
case AC_Pause:
|
|
{
|
|
const PauseAction *pa = static_cast<const PauseAction *>(m_currentAction);
|
|
DEBUG_LOG(m_logger) << "---- This is a Pause Action Pause=" << pa->pause
|
|
<< " comment=" << pa->comment;
|
|
|
|
QTimer::singleShot(pa->pause, this, &HandelEffect::handleEffect);
|
|
// To avoid the Timer call at the end of this method:
|
|
return;
|
|
// So this instance does nothing unless timer returns.
|
|
}
|
|
case AC_Bsm:
|
|
{
|
|
DEBUG_LOG(m_logger) << "---- This is a Bsm Action ";
|
|
const BsmAction *ba = static_cast<const BsmAction*>(m_currentAction);
|
|
if (!ba->isNull())
|
|
{
|
|
DEBUG_LOG(m_logger) << "emit triggerAllFlashlights ------ atype=" << m_currentAction->atype
|
|
<< " pause=" << ba->pause
|
|
<< " choplength=" << ba->choplength
|
|
<< " pulses=" << ba->pulses
|
|
<< " pulseduration=" << ba->pulseduration
|
|
<< " comment=" << ba->comment
|
|
<< " this: " << this;
|
|
emit triggerAllFlashlights(ba->pulses, ba->pause, ba->choplength, ba->pulseduration);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
DEBUG_LOG(m_logger) << "--- End Action ";
|
|
|
|
// Start next action with ending this method.
|
|
QTimer::singleShot(0, this, &HandelEffect::handleEffect);
|
|
} // end printActions
|
|
|
|
} //namespace BuildingControlUnit
|
|
|
|
|
|
|
|
|