11 _strategies.append({name, std::move(action)});
17 _successfulStrategy.clear();
20 QMetaObject::invokeMethod(
this, &FallbackChainState::_tryNextStrategy, Qt::QueuedConnection);
23void FallbackChainState::_tryNextStrategy()
27 if (_currentIndex >= _strategies.size()) {
29 qCDebug(QGCStateMachineLog) <<
stateName() <<
"all strategies exhausted";
34 const StrategyEntry& entry = _strategies[_currentIndex];
36 qCDebug(QGCStateMachineLog) <<
stateName() <<
"trying strategy" << entry.name
37 <<
"(" << (_currentIndex + 1) <<
"of" << _strategies.size() <<
")";
38 emit
tryingStrategy(entry.name, _currentIndex, _strategies.size());
42 success = entry.action();
46 qCDebug(QGCStateMachineLog) <<
stateName() <<
"strategy succeeded:" << entry.name;
47 _successfulStrategy = entry.name;
51 qCDebug(QGCStateMachineLog) <<
stateName() <<
"strategy failed:" << entry.name;
54 QMetaObject::invokeMethod(
this, &FallbackChainState::_tryNextStrategy, Qt::QueuedConnection);
std::function< bool()> Strategy
Strategy action - returns true on success.
void onEnter() override
Override to perform actions on state entry.
FallbackChainState(const QString &stateName, QState *parent)
void strategyFailed(const QString &name)
Emitted when a strategy fails and moving to next.
void tryingStrategy(const QString &name, int index, int total)
Emitted when trying a strategy.
void strategySucceeded(const QString &name)
Emitted when a strategy succeeds.
void addStrategy(const QString &name, Strategy action)
QString stateName() const