|
QGroundControl
Ground Control Station for MAVLink Drones
|
#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) | |
| QGCStateMachine * | machine () const |
| Vehicle * | vehicle () const |
| QString | stateName () const |
| class StateContext * | context () 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 |
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:
Definition at line 22 of file RollbackState.h.
| using RollbackState::ForwardAction = std::function<bool()> |
Forward action - returns true on success.
Definition at line 29 of file RollbackState.h.
| using RollbackState::RollbackAction = std::function<void()> |
Rollback action - executed on forward failure.
Definition at line 32 of file RollbackState.h.
| RollbackState::RollbackState | ( | const QString & | stateName, |
| QState * | parent, | ||
| ForwardAction | forwardAction, | ||
| RollbackAction | rollbackAction | ||
| ) |
| stateName | Name for logging |
| parent | Parent state |
| forwardAction | Action to execute (returns true on success) |
| rollbackAction | Action to execute on failure (cleanup/restore) |
Definition at line 4 of file RollbackState.cc.
|
signal |
Emitted when forward action fails (before rollback)
Referenced by onEnter().
|
signal |
Emitted when forward action succeeds.
Referenced by 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().
|
signal |
Emitted when rollback completes.
Referenced by onEnter().
|
inline |
Check if rollback succeeded (only valid if wasRolledBack() is true)
Definition at line 45 of file RollbackState.h.
|
signal |
Emitted when rollback starts.
Referenced by onEnter().
|
inline |
Check if rollback was executed.
Definition at line 42 of file RollbackState.h.