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

#include <AsyncFunctionState.h>

+ Inheritance diagram for AsyncFunctionState:
+ Collaboration diagram for AsyncFunctionState:

Public Types

using SetupFunction = std::function< void(AsyncFunctionState *state)>
 
- Public Types inherited from QGCAbstractState
using EntryCallback = std::function< void()>
 
using ExitCallback = std::function< void()>
 
using EventHandler = std::function< bool(QEvent *)>
 

Public Member Functions

 AsyncFunctionState (const QString &stateName, QState *parent, SetupFunction setupFunction, 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)
 
- 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)
 
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 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
 

Additional Inherited Members

- Signals inherited from WaitStateBase
void completed ()
 
void timeout ()
 
void timedOut ()
 
- Signals inherited from QGCAbstractState
void advance ()
 
void error ()
 

Detailed Description

Calls a function when entered and waits for an external trigger to advance Unlike FunctionState (which advances immediately), this state waits for:

  • A signal from an external object, OR
  • A call to complete() from within the function's callbacks

Useful for async operations like loading from vehicle where you call a function and wait for a completion signal.

Definition at line 14 of file AsyncFunctionState.h.

Member Typedef Documentation

◆ SetupFunction

using AsyncFunctionState::SetupFunction = std::function<void(AsyncFunctionState* state)>

Definition at line 20 of file AsyncFunctionState.h.

Constructor & Destructor Documentation

◆ AsyncFunctionState()

AsyncFunctionState::AsyncFunctionState ( const QString &  stateName,
QState *  parent,
SetupFunction  setupFunction,
int  timeoutMsecs = 0 
)
Parameters
stateNameName for this state (for logging)
parentParent state
setupFunctionFunction called when state is entered. Should start the async operation. The function receives a pointer to this state so it can call complete() when done.
timeoutMsecsTimeout in milliseconds, 0 for no timeout

Definition at line 4 of file AsyncFunctionState.cc.

Member Function Documentation

◆ complete()

void AsyncFunctionState::complete ( )
inline

Call this to signal that the async operation has completed successfully.

Definition at line 30 of file AsyncFunctionState.h.

References WaitStateBase::waitComplete().

Referenced by connectToCompletion().

◆ connectToCompletion() [1/2]

template<typename Func >
void AsyncFunctionState::connectToCompletion ( typename QtPrivate::FunctionPointer< Func >::Object *  sender,
Func  signal 
)
inline

Connect to an external signal that will trigger completion

Parameters
senderThe QObject that will emit the completion signal
signalThe signal that indicates completion

Definition at line 39 of file AsyncFunctionState.h.

References complete().

◆ connectToCompletion() [2/2]

template<typename Func , typename Slot >
void AsyncFunctionState::connectToCompletion ( typename QtPrivate::FunctionPointer< Func >::Object *  sender,
Func  signal,
Slot  slot 
)
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 49 of file AsyncFunctionState.h.

◆ connectWaitSignal()

void AsyncFunctionState::connectWaitSignal ( )
overrideprotectedvirtual

Subclasses override to set up their signal connections.

Implements WaitStateBase.

Definition at line 10 of file AsyncFunctionState.cc.

◆ disconnectWaitSignal()

void AsyncFunctionState::disconnectWaitSignal ( )
overrideprotectedvirtual

Subclasses override to tear down their signal connections.

Implements WaitStateBase.

Definition at line 15 of file AsyncFunctionState.cc.

◆ fail()

void AsyncFunctionState::fail ( )
inline

Call this to signal that the async operation has failed.

Definition at line 33 of file AsyncFunctionState.h.

References WaitStateBase::waitFailed().

◆ onWaitEntered()

void AsyncFunctionState::onWaitEntered ( )
overrideprotectedvirtual

Called when the state is entered - subclasses should call base implementation.

Reimplemented from WaitStateBase.

Definition at line 23 of file AsyncFunctionState.cc.

References QGCAbstractState::stateName(), and WaitStateBase::timeoutMsecs().


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