QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FallbackChainState.h
Go to the documentation of this file.
1#pragma once
2
3#include "QGCState.h"
4
5#include <functional>
6
24{
25 Q_OBJECT
26 Q_DISABLE_COPY(FallbackChainState)
27
28public:
30 using Strategy = std::function<bool()>;
31
33 QString name;
35 };
36
37 FallbackChainState(const QString& stateName, QState* parent);
38
42 void addStrategy(const QString& name, Strategy action);
43
45 QString successfulStrategy() const { return _successfulStrategy; }
46
48 int currentStrategyIndex() const { return _currentIndex; }
49
51 int strategyCount() const { return _strategies.size(); }
52
53signals:
55 void tryingStrategy(const QString& name, int index, int total);
56
58 void strategyFailed(const QString& name);
59
61 void strategySucceeded(const QString& name);
62
63protected:
64 void onEnter() override;
65
66private slots:
67 void _tryNextStrategy();
68
69private:
70 QList<StrategyEntry> _strategies;
71 int _currentIndex = -1;
72 QString _successfulStrategy;
73};
A state that tries multiple strategies in order until one succeeds.
std::function< bool()> Strategy
Strategy action - returns true on success.
void onEnter() override
Override to perform actions on state entry.
int strategyCount() const
Get the total number of strategies.
void strategyFailed(const QString &name)
Emitted when a strategy fails and moving to next.
QString successfulStrategy() const
Get the name of the strategy that succeeded.
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)
int currentStrategyIndex() const
Get the current strategy index being tried.
QString stateName() const
Full-featured base class for QGroundControl state machine states.
Definition QGCState.h:23