add timeout transition
This commit is contained in:
@@ -23,8 +23,8 @@
|
||||
|
||||
|
||||
PIStateBase::~PIStateBase() {
|
||||
piDeleteAll(children);
|
||||
piDeleteAll(transitions);
|
||||
piDeleteAll(children);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,9 +76,21 @@ PITransitionBase * PIStateBase::addTransition(PIStateBase * target, int event_id
|
||||
}
|
||||
|
||||
|
||||
PITransitionTimeout * PIStateBase::addTimeoutTransition(PIStateBase * target, PISystemTime timeout) {
|
||||
PITransitionTimeout * ret = new PITransitionTimeout(this, target, timeout);
|
||||
ret->root = root;
|
||||
transitions << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::print(PIString prefix) {
|
||||
PICout(PICoutManipulators::AddNewLine) << prefix << "[" << (isActive() ? "*" : " ") << "] " << getName() << " active "
|
||||
<< activeChildren();
|
||||
auto ac = activeChildren();
|
||||
PICout(PICoutManipulators::AddNone) << prefix << "[" << (isActive() ? "*" : " ") << "] \"" << getName() << "\"";
|
||||
if (ac.isNotEmpty())
|
||||
piCout << ", active" << activeChildren();
|
||||
else
|
||||
piCout << "";
|
||||
prefix += " ";
|
||||
for (auto * c: children)
|
||||
c->print(prefix);
|
||||
@@ -86,6 +98,7 @@ void PIStateBase::print(PIString prefix) {
|
||||
|
||||
|
||||
bool PIStateBase::start() {
|
||||
if (isActive()) return true;
|
||||
if (isAtomic()) {
|
||||
setActive(true);
|
||||
return true;
|
||||
@@ -94,8 +107,10 @@ bool PIStateBase::start() {
|
||||
if (initial_state) {
|
||||
setActive(true);
|
||||
return initial_state->start();
|
||||
} else
|
||||
} else {
|
||||
piCout << "error:" << getName() << "no initial state!";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
setActive(true);
|
||||
for (auto * s: children) {
|
||||
@@ -114,12 +129,16 @@ void PIStateBase::setActive(bool yes) {
|
||||
if (parent_state && yes) parent_state->childActived(this);
|
||||
if (!prev_active && is_active) {
|
||||
onEnter();
|
||||
for (auto * t: transitions)
|
||||
t->enabled();
|
||||
// if (isParallel()) setChildrenActive(true);
|
||||
}
|
||||
if (prev_active && !is_active) {
|
||||
active_state = nullptr;
|
||||
if (isParallel()) setChildrenActiveRecursive(false);
|
||||
onExit();
|
||||
for (auto * t: transitions)
|
||||
t->disabled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user