QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ErrorHandlers Namespace Reference

Functions

FunctionStatelogAndContinue (QGCStateMachine *machine, const QString &stateName, QAbstractState *nextState, const QString &message)
 
FunctionStatelogAndStop (QGCStateMachine *machine, const QString &stateName, const QString &message)
 
std::function< int(int)> exponentialBackoff (int initialDelayMsecs, double multiplier, int maxDelayMsecs)
 
std::function< int(int)> linearBackoff (int initialDelayMsecs, int incrementMsecs, int maxDelayMsecs)
 
std::function< int(int)> constantDelay (int delayMsecs)
 
std::function< int(int)> jitteredExponentialBackoff (int initialDelayMsecs, double multiplier, int maxDelayMsecs, double jitterFraction)
 

Detailed Description

Pre-built error handling utilities.

Provides common error handling patterns as ready-to-use functions and states.

Example usage:

// Log and continue to next state
machine.setGlobalErrorState(
ErrorHandlers::logAndContinue(&machine, "ErrorLogged", nextState));
// Exponential backoff for retries
auto backoff = ErrorHandlers::exponentialBackoff(1000, 2.0, 30000);
int delay = backoff(attemptNumber); // 1000, 2000, 4000, 8000, ...
std::function< int(int)> exponentialBackoff(int initialDelayMsecs, double multiplier, int maxDelayMsecs)
FunctionState * logAndContinue(QGCStateMachine *machine, const QString &stateName, QAbstractState *nextState, const QString &message)

Function Documentation

◆ constantDelay()

std::function< int(int)> ErrorHandlers::constantDelay ( int  delayMsecs)

Create a constant delay calculator (same delay for all attempts)

Parameters
delayMsecsConstant delay in milliseconds
Returns
Function that takes attempt number and returns constant delay

Definition at line 67 of file ErrorHandlers.cc.

◆ exponentialBackoff()

std::function< int(int)> ErrorHandlers::exponentialBackoff ( int  initialDelayMsecs,
double  multiplier = 2.0,
int  maxDelayMsecs = 60000 
)

Create an exponential backoff delay calculator

Parameters
initialDelayMsecsInitial delay in milliseconds
multiplierMultiplier for each subsequent attempt (default 2.0)
maxDelayMsecsMaximum delay cap
Returns
Function that takes attempt number (1-based) and returns delay

Definition at line 44 of file ErrorHandlers.cc.

◆ jitteredExponentialBackoff()

std::function< int(int)> ErrorHandlers::jitteredExponentialBackoff ( int  initialDelayMsecs,
double  multiplier = 2.0,
int  maxDelayMsecs = 60000,
double  jitterFraction = 0.25 
)

Create a jittered exponential backoff (adds randomness to prevent thundering herd)

Parameters
initialDelayMsecsInitial delay in milliseconds
multiplierMultiplier for each subsequent attempt
maxDelayMsecsMaximum delay cap
jitterFractionFraction of delay to add as random jitter (0.0-1.0)
Returns
Function that takes attempt number and returns jittered delay

Definition at line 74 of file ErrorHandlers.cc.

◆ linearBackoff()

std::function< int(int)> ErrorHandlers::linearBackoff ( int  initialDelayMsecs,
int  incrementMsecs,
int  maxDelayMsecs = 60000 
)

Create a linear backoff delay calculator

Parameters
initialDelayMsecsInitial delay in milliseconds
incrementMsecsAmount to add for each subsequent attempt
maxDelayMsecsMaximum delay cap
Returns
Function that takes attempt number (1-based) and returns delay

Definition at line 57 of file ErrorHandlers.cc.

◆ logAndContinue()

FunctionState * ErrorHandlers::logAndContinue ( QGCStateMachine machine,
const QString &  stateName,
QAbstractState *  nextState,
const QString &  message = QString() 
)

Create a state that logs the error and transitions to the next state

Parameters
machineParent state machine
stateNameName for the error logging state
nextStateState to transition to after logging
messageOptional custom message to log

Definition at line 10 of file ErrorHandlers.cc.

References QGCAbstractState::advance().

◆ logAndStop()

FunctionState * ErrorHandlers::logAndStop ( QGCStateMachine machine,
const QString &  stateName,
const QString &  message = QString() 
)

Create a state that logs the error and stops the machine

Parameters
machineParent state machine
stateNameName for the error state
messageOptional custom message to log

Definition at line 28 of file ErrorHandlers.cc.