QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ErrorRecoveryBuilder Class Reference

#include <ErrorRecoveryBuilder.h>

Public Types

enum  ExhaustedBehavior { EmitError , EmitAdvance , LogAndError , LogAndAdvance }
 What to do when all recovery options are exhausted. More...
 
using Action = std::function< bool()>
 
using VoidAction = std::function< void()>
 

Public Member Functions

 ErrorRecoveryBuilder (QGCStateMachine *machine, const QString &stateName)
 
ErrorRecoveryBuilderwithAction (Action action)
 Set the primary action to execute.
 
ErrorRecoveryBuilderretry (int maxRetries, int delayMsecs=1000)
 
ErrorRecoveryBuilderwithFallback (Action fallback)
 Add a fallback action to try if primary fails.
 
ErrorRecoveryBuilderwithRollback (VoidAction rollback)
 Add a rollback action to execute on failure.
 
ErrorRecoveryBuilderonExhausted (ExhaustedBehavior behavior)
 Configure what happens when all options are exhausted.
 
ErrorRecoveryBuilderwithTimeout (int timeoutMsecs)
 Set a timeout for the entire operation.
 
QGCStatebuild ()
 Build and return the configured state.
 

Detailed Description

Fluent builder for creating error recovery states.

Combines multiple error recovery patterns into a single state using a declarative fluent API.

Example usage:

auto* state = ErrorRecoveryBuilder(&machine, "CriticalOp")
.withAction([]() { return doWork(); })
.retry(3, 1000)
.withFallback([]() { return fallbackWork(); })
.withRollback([]() { cleanup(); })
.build();
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.
@ LogAndError
Log warning and emit error()
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.

Definition at line 26 of file ErrorRecoveryBuilder.h.

Member Typedef Documentation

◆ Action

using ErrorRecoveryBuilder::Action = std::function<bool()>

Definition at line 29 of file ErrorRecoveryBuilder.h.

◆ VoidAction

using ErrorRecoveryBuilder::VoidAction = std::function<void()>

Definition at line 30 of file ErrorRecoveryBuilder.h.

Member Enumeration Documentation

◆ ExhaustedBehavior

What to do when all recovery options are exhausted.

Enumerator
EmitError 

Emit error() signal (default)

EmitAdvance 

Continue anyway (skip)

LogAndError 

Log warning and emit error()

LogAndAdvance 

Log warning and continue.

Definition at line 33 of file ErrorRecoveryBuilder.h.

Constructor & Destructor Documentation

◆ ErrorRecoveryBuilder()

ErrorRecoveryBuilder::ErrorRecoveryBuilder ( QGCStateMachine machine,
const QString &  stateName 
)

Definition at line 9 of file ErrorRecoveryBuilder.cc.

Member Function Documentation

◆ build()

QGCState * ErrorRecoveryBuilder::build ( )

Build and return the configured state.

Definition at line 52 of file ErrorRecoveryBuilder.cc.

◆ onExhausted()

ErrorRecoveryBuilder & ErrorRecoveryBuilder::onExhausted ( ExhaustedBehavior  behavior)

Configure what happens when all options are exhausted.

Definition at line 40 of file ErrorRecoveryBuilder.cc.

◆ retry()

ErrorRecoveryBuilder & ErrorRecoveryBuilder::retry ( int  maxRetries,
int  delayMsecs = 1000 
)

Configure retry behavior

Parameters
maxRetriesMaximum number of retry attempts
delayMsecsDelay between retries

Definition at line 21 of file ErrorRecoveryBuilder.cc.

◆ withAction()

ErrorRecoveryBuilder & ErrorRecoveryBuilder::withAction ( Action  action)

Set the primary action to execute.

Definition at line 15 of file ErrorRecoveryBuilder.cc.

◆ withFallback()

ErrorRecoveryBuilder & ErrorRecoveryBuilder::withFallback ( Action  fallback)

Add a fallback action to try if primary fails.

Definition at line 28 of file ErrorRecoveryBuilder.cc.

◆ withRollback()

ErrorRecoveryBuilder & ErrorRecoveryBuilder::withRollback ( VoidAction  rollback)

Add a rollback action to execute on failure.

Definition at line 34 of file ErrorRecoveryBuilder.cc.

◆ withTimeout()

ErrorRecoveryBuilder & ErrorRecoveryBuilder::withTimeout ( int  timeoutMsecs)

Set a timeout for the entire operation.

Definition at line 46 of file ErrorRecoveryBuilder.cc.


The documentation for this class was generated from the following files: