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

#include <RollbackState.h>

+ Inheritance diagram for RollbackState:
+ Collaboration diagram for RollbackState:

Public Types

using ForwardAction = std::function< bool()>
 Forward action - returns true on success.
 
using RollbackAction = std::function< void()>
 Rollback action - executed on forward failure.
 
- Public Types inherited from QGCAbstractState
using EntryCallback = std::function< void()>
 
using ExitCallback = std::function< void()>
 
using EventHandler = std::function< bool(QEvent *)>
 

Signals

void forwardSucceeded ()
 Emitted when forward action succeeds.
 
void forwardFailed ()
 Emitted when forward action fails (before rollback)
 
void rollingBack ()
 Emitted when rollback starts.
 
void rollbackComplete ()
 Emitted when rollback completes.
 
- Signals inherited from QGCAbstractState
void advance ()
 
void error ()
 

Public Member Functions

 RollbackState (const QString &stateName, QState *parent, ForwardAction forwardAction, RollbackAction rollbackAction)
 
bool wasRolledBack () const
 Check if rollback was executed.
 
bool rollbackSucceeded () const
 Check if rollback succeeded (only valid if wasRolledBack() is true)
 
- 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 executes an action with automatic rollback on failure.

If the forward action fails, the rollback action is executed before emitting the error() signal. This provides transaction-like semantics.

Example usage:

auto* state = new RollbackState("UpdateFirmware", &machine,
[]() { return flashFirmware(); }, // Forward action
[]() { restorePreviousFirmware(); } // Rollback action (void)
);
state->addTransition(state, &RollbackState::advance, successState);
state->addTransition(state, &RollbackState::error, errorState);
QGCStateMachine * machine() const

Definition at line 22 of file RollbackState.h.

Member Typedef Documentation

◆ ForwardAction

using RollbackState::ForwardAction = std::function<bool()>

Forward action - returns true on success.

Definition at line 29 of file RollbackState.h.

◆ RollbackAction

using RollbackState::RollbackAction = std::function<void()>

Rollback action - executed on forward failure.

Definition at line 32 of file RollbackState.h.

Constructor & Destructor Documentation

◆ RollbackState()

RollbackState::RollbackState ( const QString &  stateName,
QState *  parent,
ForwardAction  forwardAction,
RollbackAction  rollbackAction 
)
Parameters
stateNameName for logging
parentParent state
forwardActionAction to execute (returns true on success)
rollbackActionAction to execute on failure (cleanup/restore)

Definition at line 4 of file RollbackState.cc.

Member Function Documentation

◆ forwardFailed

void RollbackState::forwardFailed ( )
signal

Emitted when forward action fails (before rollback)

Referenced by onEnter().

◆ forwardSucceeded

void RollbackState::forwardSucceeded ( )
signal

Emitted when forward action succeeds.

Referenced by onEnter().

◆ onEnter()

void RollbackState::onEnter ( )
overrideprotectedvirtual

Override to perform actions on state entry.

Reimplemented from QGCAbstractState.

Definition at line 12 of file RollbackState.cc.

References QGCAbstractState::advance(), QGCAbstractState::error(), forwardFailed(), forwardSucceeded(), rollbackComplete(), rollingBack(), and QGCAbstractState::stateName().

◆ rollbackComplete

void RollbackState::rollbackComplete ( )
signal

Emitted when rollback completes.

Referenced by onEnter().

◆ rollbackSucceeded()

bool RollbackState::rollbackSucceeded ( ) const
inline

Check if rollback succeeded (only valid if wasRolledBack() is true)

Definition at line 45 of file RollbackState.h.

◆ rollingBack

void RollbackState::rollingBack ( )
signal

Emitted when rollback starts.

Referenced by onEnter().

◆ wasRolledBack()

bool RollbackState::wasRolledBack ( ) const
inline

Check if rollback was executed.

Definition at line 42 of file RollbackState.h.


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