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

#include <FallbackChainState.h>

+ Inheritance diagram for FallbackChainState:
+ Collaboration diagram for FallbackChainState:

Classes

struct  StrategyEntry
 

Public Types

using Strategy = std::function< bool()>
 Strategy action - returns true on success.
 
- Public Types inherited from QGCAbstractState
using EntryCallback = std::function< void()>
 
using ExitCallback = std::function< void()>
 
using EventHandler = std::function< bool(QEvent *)>
 

Signals

void tryingStrategy (const QString &name, int index, int total)
 Emitted when trying a strategy.
 
void strategyFailed (const QString &name)
 Emitted when a strategy fails and moving to next.
 
void strategySucceeded (const QString &name)
 Emitted when a strategy succeeds.
 
- Signals inherited from QGCAbstractState
void advance ()
 
void error ()
 

Public Member Functions

 FallbackChainState (const QString &stateName, QState *parent)
 
void addStrategy (const QString &name, Strategy action)
 
QString successfulStrategy () const
 Get the name of the strategy that succeeded.
 
int currentStrategyIndex () const
 Get the current strategy index being tried.
 
int strategyCount () const
 Get the total number of strategies.
 
- 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 tries multiple strategies in order until one succeeds.

Strategies are executed in the order they were added. If a strategy succeeds, the state emits advance(). If all strategies fail, error() is emitted.

Example usage:

auto* state = new FallbackChainState("Connect", &machine);
state->addStrategy("Primary", []() { return connectPrimary(); });
state->addStrategy("Backup", []() { return connectBackup(); });
state->addStrategy("Offline", []() { return goOffline(); });
state->addTransition(state, &FallbackChainState::advance, connectedState);
state->addTransition(state, &FallbackChainState::error, failedState);
QGCStateMachine * machine() const

Definition at line 22 of file FallbackChainState.h.

Member Typedef Documentation

◆ Strategy

using FallbackChainState::Strategy = std::function<bool()>

Strategy action - returns true on success.

Definition at line 29 of file FallbackChainState.h.

Constructor & Destructor Documentation

◆ FallbackChainState()

FallbackChainState::FallbackChainState ( const QString &  stateName,
QState *  parent 
)

Definition at line 4 of file FallbackChainState.cc.

Member Function Documentation

◆ addStrategy()

void FallbackChainState::addStrategy ( const QString &  name,
Strategy  action 
)

Add a strategy to the chain

Parameters
nameStrategy name for logging
actionStrategy action (returns true on success)

Definition at line 9 of file FallbackChainState.cc.

◆ currentStrategyIndex()

int FallbackChainState::currentStrategyIndex ( ) const
inline

Get the current strategy index being tried.

Definition at line 47 of file FallbackChainState.h.

◆ onEnter()

void FallbackChainState::onEnter ( )
overrideprotectedvirtual

Override to perform actions on state entry.

Reimplemented from QGCAbstractState.

Definition at line 14 of file FallbackChainState.cc.

◆ strategyCount()

int FallbackChainState::strategyCount ( ) const
inline

Get the total number of strategies.

Definition at line 50 of file FallbackChainState.h.

◆ strategyFailed

void FallbackChainState::strategyFailed ( const QString &  name)
signal

Emitted when a strategy fails and moving to next.

◆ strategySucceeded

void FallbackChainState::strategySucceeded ( const QString &  name)
signal

Emitted when a strategy succeeds.

◆ successfulStrategy()

QString FallbackChainState::successfulStrategy ( ) const
inline

Get the name of the strategy that succeeded.

Definition at line 44 of file FallbackChainState.h.

◆ tryingStrategy

void FallbackChainState::tryingStrategy ( const QString &  name,
int  index,
int  total 
)
signal

Emitted when trying a strategy.


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