5#include <QtCore/QTimer>
30 using Action = std::function<bool()>;
73 int _retryDelayMsecs = 1000;
74 int _timeoutMsecs = 0;
86 using Action = std::function<bool()>;
94 void setRetry(
int maxRetries,
int delayMsecs);
112 void _executeAction();
116 void _handleFailure();
117 void _handleExhausted();
123 int _retryDelayMsecs = 1000;
124 int _timeoutMsecs = 0;
127 int _currentAttempt = 0;
128 bool _triedFallback =
false;
129 QString _successPhase;
131 QTimer _timeoutTimer;
Fluent builder for creating error recovery states.
ErrorRecoveryBuilder & retry(int maxRetries, int delayMsecs=1000)
ErrorRecoveryBuilder & withFallback(Action fallback)
Add a fallback action to try if primary fails.
ErrorRecoveryBuilder & withAction(Action action)
Set the primary action to execute.
ExhaustedBehavior
What to do when all recovery options are exhausted.
@ EmitAdvance
Continue anyway (skip).
@ LogAndAdvance
Log warning and continue.
@ LogAndError
Log warning and emit error().
@ EmitError
Emit error() signal (default).
ErrorRecoveryBuilder(QGCStateMachine *machine, const QString &stateName)
std::function< bool()> Action
std::function< void()> VoidAction
ErrorRecoveryBuilder & onExhausted(ExhaustedBehavior behavior)
Configure what happens when all options are exhausted.
ErrorRecoveryBuilder & withRollback(VoidAction rollback)
Add a rollback action to execute on failure.
QGCState * build()
Build and return the configured state.
ErrorRecoveryBuilder & withTimeout(int timeoutMsecs)
Set a timeout for the entire operation.
void setRollback(VoidAction rollback)
std::function< bool()> Action
void onEnter() override
Override to perform actions on state entry.
void setTimeout(int timeoutMsecs)
void setFallback(Action fallback)
QString successPhase() const
Get the phase that succeeded (if any).
ErrorRecoveryState(const QString &stateName, QState *parent)
void retrying(int attempt, int maxAttempts)
std::function< void()> VoidAction
void setAction(Action action)
void setExhaustedBehavior(ErrorRecoveryBuilder::ExhaustedBehavior behavior)
void setRetry(int maxRetries, int delayMsecs)
QString stateName() const
QGroundControl specific state machine with enhanced error handling.
Full-featured base class for QGroundControl state machine states.
QGCState(const QString &stateName, QState *parentState)