#include "handeleffect.h" #include #include namespace BuildingControlUnit { HandelEffect::HandelEffect(QObject *parent, const QString &loggerchannel) : QObject(parent) , m_logger(getLogger(QStringLiteral("HandelSingleEffect.") + loggerchannel)) { } bool HandelEffect::init(const QVector &actions, int repetitions = 1) { if (actions.isEmpty()) return false; m_actions = actions; m_currentAction = nullptr; m_repeatCount = repetitions; return true; } void HandelEffect::handleEffect() { if (!m_currentAction) { 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()) { 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(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); return; } case AC_Pause: { const PauseAction *pa = static_cast(m_currentAction); DEBUG_LOG(m_logger) << "---- This is a Pause Action Pause=" << pa->pause << " comment=" << pa->comment; QTimer::singleShot(pa->pause, this, &HandelEffect::handleEffect); return; } case AC_Bsm: { DEBUG_LOG(m_logger) << "---- This is a Bsm Action "; const BsmAction *ba = static_cast(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 "; QTimer::singleShot(0, this, &HandelEffect::handleEffect); } }