5#include <QtCore/QTimer>
29 using Action = std::function<bool()>;
72 int _retryDelayMsecs = 1000;
73 int _timeoutMsecs = 0;
84 using Action = std::function<bool()>;
92 void setRetry(
int maxRetries,
int delayMsecs);
110 void _executeAction();
114 void _handleFailure();
115 void _handleExhausted();
121 int _retryDelayMsecs = 1000;
122 int _timeoutMsecs = 0;
125 int _currentAttempt = 0;
126 bool _triedFallback =
false;
127 QString _successPhase;
129 QTimer _timeoutTimer;
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)
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.
The state created by ErrorRecoveryBuilder.
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)
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.