|
QGroundControl
Ground Control Station for MAVLink Drones
|
#include <SkippableAsyncState.h>
Inheritance diagram for SkippableAsyncState:
Collaboration diagram for SkippableAsyncState:Public Types | |
| using | SkipPredicate = std::function< bool()> |
| using | SetupFunction = std::function< void(SkippableAsyncState *state)> |
| using | SkipAction = std::function< void()> |
Public Types inherited from QGCAbstractState | |
| using | EntryCallback = std::function< void()> |
| using | ExitCallback = std::function< void()> |
| using | EventHandler = std::function< bool(QEvent *)> |
Signals | |
| void | skipped () |
| Emitted when skip predicate returns true and the state is skipped. | |
Signals inherited from WaitStateBase | |
| void | completed () |
| void | timeout () |
| void | timedOut () |
Signals inherited from QGCAbstractState | |
| void | advance () |
| void | error () |
Public Member Functions | |
| SkippableAsyncState (const QString &stateName, QState *parent, SkipPredicate skipPredicate, SetupFunction setupFunc, SkipAction skipAction=nullptr, int timeoutMsecs=0) | |
| void | complete () |
| Call this to signal that the async operation has completed successfully. | |
| void | fail () |
| Call this to signal that the async operation has failed. | |
| template<typename Func > | |
| void | connectToCompletion (typename QtPrivate::FunctionPointer< Func >::Object *sender, Func signal) |
| template<typename Func , typename Slot > | |
| void | connectToCompletion (typename QtPrivate::FunctionPointer< Func >::Object *sender, Func signal, Slot slot) |
| void | setSkipPredicate (SkipPredicate predicate) |
| Set the skip predicate. | |
| void | setSetupFunction (SetupFunction setupFunc) |
| Set the setup function. | |
| void | setSkipAction (SkipAction skipAction) |
| Set the skip action. | |
Public Member Functions inherited from WaitStateBase | |
| WaitStateBase (const QString &stateName, QState *parent, int timeoutMsecs=0) | |
| void | restartWait () |
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 | connectWaitSignal () override |
| Subclasses override to set up their signal connections. | |
| void | disconnectWaitSignal () override |
| Subclasses override to tear down their signal connections. | |
| void | onWaitEntered () override |
| Called when the state is entered - subclasses should call base implementation. | |
Protected Member Functions inherited from WaitStateBase | |
| virtual void | onWaitExited () |
| Called when the state is exited - subclasses should call base implementation. | |
| virtual void | onWaitTimeout () |
| Called when the timeout expires - default emits timeout(), subclasses can override. | |
| void | waitComplete () |
| void | waitFailed () |
| int | timeoutMsecs () const |
Protected Member Functions inherited from QGCAbstractState | |
| virtual void | onEnter () |
| Override to perform actions on state entry. | |
| 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 |
Combines skip condition checking with async operation setup in a single state. Common pattern in initialization workflows where operations should be skipped under certain conditions.
On entry:
Example usage:
Definition at line 32 of file SkippableAsyncState.h.
| using SkippableAsyncState::SetupFunction = std::function<void(SkippableAsyncState* state)> |
Definition at line 39 of file SkippableAsyncState.h.
| using SkippableAsyncState::SkipAction = std::function<void()> |
Definition at line 40 of file SkippableAsyncState.h.
| using SkippableAsyncState::SkipPredicate = std::function<bool()> |
Definition at line 38 of file SkippableAsyncState.h.
| SkippableAsyncState::SkippableAsyncState | ( | const QString & | stateName, |
| QState * | parent, | ||
| SkipPredicate | skipPredicate, | ||
| SetupFunction | setupFunc, | ||
| SkipAction | skipAction = nullptr, |
||
| int | timeoutMsecs = 0 |
||
| ) |
| stateName | Name for this state (for logging) |
| parent | Parent state |
| skipPredicate | If true, skip the async operation and emit skipped() |
| setupFunc | Function called when state is entered and not skipped. Should start the async operation. |
| skipAction | Optional function called when skipping (for cleanup or logging) |
| timeoutMsecs | Timeout in milliseconds, 0 for no timeout |
Definition at line 6 of file SkippableAsyncState.cc.
|
inline |
Call this to signal that the async operation has completed successfully.
Definition at line 57 of file SkippableAsyncState.h.
References WaitStateBase::waitComplete().
Referenced by connectToCompletion().
|
inline |
Connect to an external signal that will trigger completion
| sender | The QObject that will emit the completion signal |
| signal | The signal that indicates completion |
Definition at line 66 of file SkippableAsyncState.h.
References complete().
|
inline |
Connect to an external signal that will trigger completion, with a slot Useful when you need to process the signal data before completing
Definition at line 76 of file SkippableAsyncState.h.
|
overrideprotectedvirtual |
Subclasses override to set up their signal connections.
Implements WaitStateBase.
Definition at line 19 of file SkippableAsyncState.cc.
|
overrideprotectedvirtual |
Subclasses override to tear down their signal connections.
Implements WaitStateBase.
Definition at line 24 of file SkippableAsyncState.cc.
|
inline |
Call this to signal that the async operation has failed.
Definition at line 60 of file SkippableAsyncState.h.
References WaitStateBase::waitFailed().
|
overrideprotectedvirtual |
Called when the state is entered - subclasses should call base implementation.
Reimplemented from WaitStateBase.
Definition at line 32 of file SkippableAsyncState.cc.
References skipped(), and QGCAbstractState::stateName().
|
inline |
Set the setup function.
Definition at line 85 of file SkippableAsyncState.h.
|
inline |
Set the skip action.
Definition at line 88 of file SkippableAsyncState.h.
|
inline |
Set the skip predicate.
Definition at line 82 of file SkippableAsyncState.h.
|
signal |
Emitted when skip predicate returns true and the state is skipped.
Referenced by onWaitEntered().