80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
#include "factoractor.h"
|
|
|
|
MultiFactorActor::MultiFactorActor(Actor* factorActor, const uint preCancleMin, QObject *parent):
|
|
Actor(parent),
|
|
factorActor_(factorActor),
|
|
preCancleMin_(preCancleMin)
|
|
{
|
|
activationTime.setMSecsSinceEpoch(0);
|
|
if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
|
}
|
|
|
|
void MultiFactorActor::factorActorSlot(uint8_t value)
|
|
{
|
|
if(value == factorDirection)
|
|
{
|
|
activationTime = QDateTime::currentDateTime();
|
|
}
|
|
}
|
|
|
|
void MultiFactorActor::setValue(uint8_t value)
|
|
{
|
|
if(value)
|
|
{
|
|
QDateTime current = QDateTime::currentDateTime();
|
|
if(current.addSecs(-preCancleMin_*60) > activationTime )
|
|
{
|
|
performAction();
|
|
}
|
|
bool exausted = true;
|
|
for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
|
|
}
|
|
}
|
|
|
|
QString MultiFactorActor::getName() const
|
|
{
|
|
if(name_.size() > 0) return name_;
|
|
else
|
|
{
|
|
QString string;
|
|
string = "Multi Factor \"" + (factorActor_ ? factorActor_->getName() : "NULL") + "\"";
|
|
return string;
|
|
}
|
|
}
|
|
|
|
void MultiFactorActor::setFactorActor(std::shared_ptr<Actor> factorActor)
|
|
{
|
|
factorActor_=factorActor;
|
|
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
|
}
|
|
|
|
void MultiFactorActor::store(QJsonObject &json)
|
|
{
|
|
json["Type"] = "MultiFactor";
|
|
Actor::store(json);
|
|
json["PreCancleMinutes"] = static_cast<int>(preCancleMin_);
|
|
json["FactorDirection"] = factorDirection;
|
|
QJsonObject factorActorObject;
|
|
if(factorActor_)
|
|
{
|
|
factorActor_->store(factorActorObject);
|
|
}
|
|
}
|
|
|
|
void MultiFactorActor::load(const QJsonObject &json, bool preserve)
|
|
{
|
|
Actor::load(json, preserve);
|
|
preCancleMin_ = static_cast<uint>(json["PreCancleMinutes"].toInt(10));
|
|
factorDirection = json["FacotorDirection"].toBool(true);
|
|
if(json["FactorActor"].isObject())
|
|
{
|
|
factorActor_ = Actor::loadActor(json["FactorActor"].toObject());
|
|
}
|
|
if(factorActor_)
|
|
{
|
|
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
|
}
|
|
}
|
|
|
|
|