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

#include <RetryState.h>

+ Inheritance diagram for RetryState:
+ Collaboration diagram for RetryState:

Public Types

enum  ExhaustedBehavior { EmitError , EmitAdvance }
 
using Action = std::function< bool()>
 
- Public Types inherited from QGCAbstractState
using EntryCallback = std::function< void()>
 
using ExitCallback = std::function< void()>
 
using EventHandler = std::function< bool(QEvent *)>
 

Signals

void retrying (int attempt, int maxAttempts)
 Emitted before each retry attempt.
 
void succeeded ()
 Emitted when the action eventually succeeds.
 
void exhausted ()
 Emitted when all retries are exhausted (both behaviors).
 
void skipped ()
 Emitted when retries are exhausted and behavior is EmitAdvance.
 
- Signals inherited from QGCAbstractState
void advance ()
 
void error ()
 

Public Member Functions

 RetryState (const QString &stateName, QState *parent, Action action, int maxRetries=0, int retryDelayMsecs=1000, ExhaustedBehavior exhaustedBehavior=EmitError)
 
int currentAttempt () const
 
int maxRetries () const
 
int totalAttempts () const
 
ExhaustedBehavior exhaustedBehavior () const
 
bool wasSkipped () const
 
- Public Member Functions inherited from QGCState
 QGCState (const QString &stateName, QState *parentState)
 
template<typename PointerToMemberFunction >
QSignalTransition * addThisTransition (PointerToMemberFunction signal, QAbstractState *target)
 Simpler version of QState::addTransition which assumes the sender is this.
 
void setLocalErrorState (QAbstractState *errorState)
 
QAbstractState * localErrorState () const
 Get the per-state error state (nullptr if using global)
 
void setProperty (QObject *object, const char *name, const QVariant &value)
 
void setEnabled (QObject *object, bool enabled)
 Convenience overload for setting enabled state on widgets/controls.
 
void setVisible (QObject *object, bool visible)
 Convenience overload for setting visible state on widgets/controls.
 
- Public Member Functions inherited from QGCAbstractState
 QGCAbstractState (const QString &stateName, QState *parent)
 
QGCStateMachinemachine () const
 
Vehiclevehicle () const
 
QString stateName () const
 
class StateContextcontext () const
 
void setOnEntry (EntryCallback callback)
 Set a callback to be invoked when the state is entered.
 
void setOnExit (ExitCallback callback)
 Set a callback to be invoked when the state is exited.
 
void setCallbacks (EntryCallback onEntry, ExitCallback onExit=nullptr)
 Set both entry and exit callbacks.
 
void setEventHandler (EventHandler handler)
 Set a custom event handler for this state.
 

Protected Member Functions

void onEnter () override
 Override to perform actions on state entry.
 
- Protected Member Functions inherited from QGCAbstractState
virtual void onLeave ()
 Override to perform actions on state exit.
 
void onEntry (QEvent *event) override
 
void onExit (QEvent *event) override
 
bool event (QEvent *event) override
 

Detailed Description

A state that retries an action and chooses behavior when retries are exhausted.

The action is executed on entry. If it fails, the state retries after a delay. Once retries are exhausted, behavior is controlled by ExhaustedBehavior.

Definition at line 13 of file RetryState.h.

Member Typedef Documentation

◆ Action

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

Definition at line 19 of file RetryState.h.

Member Enumeration Documentation

◆ ExhaustedBehavior

Enumerator
EmitError 

Emit error() after retries exhausted.

EmitAdvance 

Emit advance() after retries exhausted (skip/continue).

Definition at line 21 of file RetryState.h.

Constructor & Destructor Documentation

◆ RetryState()

RetryState::RetryState ( const QString &  stateName,
QState *  parent,
Action  action,
int  maxRetries = 0,
int  retryDelayMsecs = 1000,
ExhaustedBehavior  exhaustedBehavior = EmitError 
)

Definition at line 4 of file RetryState.cc.

Member Function Documentation

◆ currentAttempt()

int RetryState::currentAttempt ( ) const
inline

Definition at line 33 of file RetryState.h.

◆ exhausted

void RetryState::exhausted ( )
signal

Emitted when all retries are exhausted (both behaviors).

◆ exhaustedBehavior()

ExhaustedBehavior RetryState::exhaustedBehavior ( ) const
inline

Definition at line 36 of file RetryState.h.

◆ maxRetries()

int RetryState::maxRetries ( ) const
inline

Definition at line 34 of file RetryState.h.

◆ onEnter()

void RetryState::onEnter ( )
overrideprotectedvirtual

Override to perform actions on state entry.

Reimplemented from QGCAbstractState.

Definition at line 17 of file RetryState.cc.

◆ retrying

void RetryState::retrying ( int  attempt,
int  maxAttempts 
)
signal

Emitted before each retry attempt.

◆ skipped

void RetryState::skipped ( )
signal

Emitted when retries are exhausted and behavior is EmitAdvance.

◆ succeeded

void RetryState::succeeded ( )
signal

Emitted when the action eventually succeeds.

◆ totalAttempts()

int RetryState::totalAttempts ( ) const
inline

Definition at line 35 of file RetryState.h.

◆ wasSkipped()

bool RetryState::wasSkipped ( ) const
inline

Definition at line 37 of file RetryState.h.


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