QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SkippableAsyncState.cc
Go to the documentation of this file.
3
4#include <QtCore/QMetaObject>
5
7 QState* parent,
8 SkipPredicate skipPredicate,
9 SetupFunction setupFunc,
10 SkipAction skipAction,
11 int timeoutMsecs)
12 : WaitStateBase(stateName, parent, timeoutMsecs)
13 , _skipPredicate(std::move(skipPredicate))
14 , _setupFunction(std::move(setupFunc))
15 , _skipAction(std::move(skipAction))
16{
17}
18
20{
21 // Connection is set up dynamically via connectToCompletion() in the setup function
22}
23
25{
26 if (_completionConnection) {
27 disconnect(_completionConnection);
28 _completionConnection = {};
29 }
30}
31
33{
34 _wasSkipped = false;
35
36 // Evaluate skip predicate
37 if (_skipPredicate && _skipPredicate()) {
38 qCDebug(QGCStateMachineLog) << "Skip condition met, skipping" << stateName();
39 _wasSkipped = true;
40
41 // Execute skip action if provided
42 if (_skipAction) {
43 _skipAction();
44 }
45
46 // Defer signal emission to avoid firing during state entry
47 // This ensures the state machine finishes entering before transitions are evaluated
48 QMetaObject::invokeMethod(this, &SkippableAsyncState::skipped, Qt::QueuedConnection);
49 return;
50 }
51
52 // Not skipped - execute the setup function
53 qCDebug(QGCStateMachineLog) << "Condition not met, executing" << stateName();
54 if (_setupFunction) {
55 _setupFunction(this);
56 }
57}
QString stateName() const
std::function< void()> SkipAction
void skipped()
Emitted when skip predicate returns true and the state is skipped.
std::function< bool()> SkipPredicate
void onWaitEntered() override
Called when the state is entered - subclasses should call base implementation.
std::function< void(SkippableAsyncState *state)> SetupFunction
SkippableAsyncState(const QString &stateName, QState *parent, SkipPredicate skipPredicate, SetupFunction setupFunc, SkipAction skipAction=nullptr, int timeoutMsecs=0)
void connectWaitSignal() override
Subclasses override to set up their signal connections.
void disconnectWaitSignal() override
Subclasses override to tear down their signal connections.
Base class for states that wait for something with optional timeout.