|
QGroundControl
Ground Control Station for MAVLink Drones
|
QGroundControl specific state machine with enhanced error handling. More...
#include <QGCStateMachine.h>
Inheritance diagram for QGCStateMachine:
Collaboration diagram for QGCStateMachine:Public Types | |
| using | EntryCallback = std::function< void()> |
| Name of the currently active state (for QML binding) | |
| using | ExitCallback = std::function< void()> |
| using | EventHandler = std::function< bool(QEvent *)> |
Public Slots | |
| void | start () |
| Start the state machine with debug logging. | |
Signals | |
| void | error () |
| void | progressUpdate (float progress) |
| void | machineEvent (const QString &eventName) |
| void | currentStateNameChanged () |
| Emitted when the current state changes (for QML binding) | |
| void | runningChanged () |
| Emitted when the running state changes (for QML binding) | |
| void | stateHistoryChanged () |
| Emitted when the state history changes (for QML binding) | |
Public Member Functions | |
| QGCStateMachine (const QString &machineName, Vehicle *vehicle, QObject *parent=nullptr) | |
| Vehicle * | vehicle () const |
| QString | machineName () const |
| StateContext & | context () |
| const StateContext & | context () const |
| bool | active () const |
| QString | currentStateName () const |
| QStringList | stateHistory () const |
| void | setStateHistoryLimit (int limit) |
| Set the maximum number of state history entries to keep. | |
| void | setOnEntry (EntryCallback callback) |
| Set a callback to be invoked when the machine starts. | |
| void | setOnExit (ExitCallback callback) |
| Set a callback to be invoked when the machine stops. | |
| void | setCallbacks (EntryCallback onEntry, ExitCallback onExit=nullptr) |
| Set both entry and exit callbacks. | |
| void | setEventHandler (EventHandler handler) |
| void | enablePropertyRestore () |
| bool | isPropertyRestoreEnabled () const |
| Check if property restoration is enabled. | |
| void | setGlobalErrorState (QAbstractState *errorState) |
| QAbstractState * | globalErrorState () const |
| Get the global error state. | |
| void | registerState (QGCState *state) |
| void | registerState (QGCAbstractState *state) |
| FunctionState * | addFunctionState (const QString &stateName, std::function< void()> function) |
| AsyncFunctionState * | addAsyncFunctionState (const QString &stateName, AsyncFunctionState::SetupFunction setupFunction, int timeoutMsecs=0) |
| QGCState * | addErrorRecoveryState (const QString &stateName, ErrorRecoveryBuilder::Action action, int maxRetries=0, int retryDelayMsecs=1000, ErrorRecoveryBuilder::ExhaustedBehavior exhaustedBehavior=ErrorRecoveryBuilder::EmitError, ErrorRecoveryBuilder::Action fallback=nullptr, ErrorRecoveryBuilder::VoidAction rollback=nullptr, int timeoutMsecs=0) |
| DelayState * | addDelayState (int delayMsecs) |
| ParallelState * | addParallelState (const QString &stateName) |
| void | postEvent (const QString &eventName, const QVariant &data=QVariant(), EventPriority priority=NormalPriority) |
| int | postDelayedEvent (const QString &eventName, int delayMsecs, const QVariant &data=QVariant()) |
| bool | cancelDelayedEvent (int eventId) |
| void | setInitialState (QAbstractState *state, bool autoStart=false) |
| QGCFinalState * | addFinalState (const QString &stateName=QString()) |
| ConditionalState * | addConditionalState (const QString &stateName, ConditionalState::Predicate predicate, ConditionalState::Action action=nullptr) |
| template<typename Func > | |
| WaitForSignalState * | addWaitForSignalState (const QString &stateName, const QObject *sender, Func signal, int timeoutMsecs=0) |
| SubMachineState * | addSubMachineState (const QString &stateName, SubMachineState::MachineFactory factory) |
| EventQueuedState * | addEventQueuedState (const QString &stateName, const QString &eventName, int timeoutMsecs=0) |
| QState * | createTimedActionState (const QString &stateName, int durationMsecs, std::function< void()> onEntry=nullptr, std::function< void()> onExit=nullptr) |
| bool | isStateActive (QAbstractState *state) const |
| QSet< QAbstractState * > | activeStates () const |
| QAbstractState * | findState (const QString &stateName) const |
| template<typename T > | |
| QList< T * > | findStates () const |
| Find all states of a specific type. | |
| bool | isInErrorState () const |
| Check if the machine is in an error state. | |
| FunctionState * | addLogAndContinueErrorState (const QString &stateName, QAbstractState *nextState, const QString &message=QString()) |
Create a logging error handler state that advances to nextState. | |
| FunctionState * | addLogAndStopErrorState (const QString &stateName, const QString &message=QString()) |
| Create a logging error handler state that stops the machine. | |
| QString | lastError () const |
| Get the last error message (from Qt's internal error handling) | |
| void | clearError (bool restart=false) |
| bool | resetToState (QAbstractState *state) |
| bool | recoverFromError () |
| void | setRecoveryState (QAbstractState *state) |
| QAbstractState * | recoveryState () const |
| Get the recovery state. | |
| bool | attemptRecovery () |
| void | ensureRunning () |
| Start the machine if not already running. | |
| void | stopMachine (bool deleteOnStop=true) |
| void | restart () |
| Restart the machine (stop then start) | |
| template<typename Func > | |
| QSignalTransition * | addTransition (QState *from, Func signal, QAbstractState *to, QAbstractAnimation *animation=nullptr) |
| template<typename Func > | |
| GuardedTransition * | addGuardedTransition (QState *from, Func signal, QAbstractState *to, GuardedTransition::Guard guard, QAbstractAnimation *animation=nullptr) |
| MachineEventTransition * | addEventTransition (QState *from, const QString &eventName, QAbstractState *to, QAbstractAnimation *animation=nullptr) |
| TimeoutTransition * | addTimeoutTransition (QState *from, int timeoutMsecs, QAbstractState *to, QAbstractAnimation *animation=nullptr) |
| template<typename SenderType , typename Func > | |
| RetryTransition * | addRetryTransition (SenderType *from, Func signal, QAbstractState *to, std::function< void()> retryAction, int maxRetries=1) |
| template<typename SenderType , typename Func > | |
| GuardedTransition * | addConditionalTransition (SenderType *from, Func signal, QAbstractState *to, std::function< bool()> guard) |
| template<typename Sender , typename Signal > | |
| QSignalTransition * | addSelfLoopTransition (QState *state, Sender *sender, Signal signal, std::function< void()> action) |
| template<typename Sender , typename Signal > | |
| InternalTransition * | addInternalTransition (QState *state, Sender *sender, Signal signal, std::function< void()> action) |
| QList< QAbstractTransition * > | transitionsFrom (QAbstractState *state) const |
| QList< QAbstractTransition * > | transitionsTo (QAbstractState *state) const |
| QList< QAbstractState * > | reachableFrom (QAbstractState *state) const |
| QList< QAbstractState * > | predecessorsOf (QAbstractState *state) const |
| QString | dumpCurrentState () const |
| QString | dumpConfiguration () const |
| void | logCurrentState () const |
| Log the current state to debug output. | |
| void | logConfiguration () const |
| Log the full configuration to debug output. | |
| void | setHistoryRecordingEnabled (bool enabled, int maxEntries=1000) |
| Enable/disable structured transition history recording. | |
| bool | historyRecordingEnabled () const |
| QString | dumpRecordedHistory () const |
| QJsonArray | recordedHistoryJson () const |
| void | setProfilingEnabled (bool enabled) |
| Enable/disable state timing profiler. | |
| bool | profilingEnabled () const |
| QString | profilingSummary () const |
| void | setStructuredLoggingEnabled (bool enabled) |
| Enable/disable structured state-machine logger. | |
| bool | structuredLoggingEnabled () const |
| QString | exportAsDot () const |
| QList< QAbstractState * > | unreachableStates () const |
| int | maxPathLength () const |
| QList< QAbstractState * > | deadEndStates () const |
| void | setProgressWeights (const QList< QPair< QAbstractState *, int > > &stateWeights) |
| void | setSubProgress (float subProgress) |
| float | progress () const |
| Get the current overall progress (0.0 to 1.0) | |
| void | resetProgress () |
| Reset progress tracking (call when restarting the machine) | |
| void | setTimeoutOverride (const QString &stateName, int timeoutMsecs) |
| void | removeTimeoutOverride (const QString &stateName) |
| int | timeoutOverride (const QString &stateName) const |
| Get the timeout override for a state, or -1 if not set. | |
| QHash< QString, int > | allTimeoutOverrides () const |
| Get all timeout overrides. | |
| void | clearTimeoutOverrides () |
| Clear all timeout overrides. | |
| QHash< QString, int > | timeoutStats () const |
| Get timeout statistics (how often each state timed out) | |
| void | recordTimeout (const QString &stateName) |
| Record a timeout for statistics. | |
| void | clearTimeoutStats () |
| Clear timeout statistics. | |
Protected Member Functions | |
| virtual void | onEnter () |
| Override to perform actions when machine starts. | |
| virtual void | onLeave () |
| Override to perform actions when machine stops. | |
| void | onEntry (QEvent *event) override |
| void | onExit (QEvent *event) override |
| bool | event (QEvent *event) override |
QGroundControl specific state machine with enhanced error handling.
Definition at line 62 of file QGCStateMachine.h.
| using QGCStateMachine::EntryCallback = std::function<void()> |
Name of the currently active state (for QML binding)
Current progress from 0.0 to 1.0 (for QML binding) Whether the machine is currently running (for QML binding) List of recent state names for history display (for QML binding)
Definition at line 80 of file QGCStateMachine.h.
| using QGCStateMachine::EventHandler = std::function<bool(QEvent*)> |
Definition at line 82 of file QGCStateMachine.h.
| using QGCStateMachine::ExitCallback = std::function<void()> |
Definition at line 81 of file QGCStateMachine.h.
| QGCStateMachine::QGCStateMachine | ( | const QString & | machineName, |
| Vehicle * | vehicle, | ||
| QObject * | parent = nullptr |
||
| ) |
Definition at line 15 of file QGCStateMachine.cc.
References machineName(), progressUpdate(), runningChanged(), setHistoryRecordingEnabled(), setProfilingEnabled(), and setStructuredLoggingEnabled().
|
inline |
Definition at line 96 of file QGCStateMachine.h.
Referenced by currentStateName(), dumpCurrentState(), and Vehicle::isInitialConnectComplete().
|
inline |
Get all currently active states
Definition at line 308 of file QGCStateMachine.h.
Referenced by currentStateName().
| AsyncFunctionState * QGCStateMachine::addAsyncFunctionState | ( | const QString & | stateName, |
| AsyncFunctionState::SetupFunction | setupFunction, | ||
| int | timeoutMsecs = 0 |
||
| ) |
Create and register an AsyncFunctionState
| stateName | Name for the state |
| setupFunction | Function to execute on entry |
| timeoutMsecs | Optional timeout |
Definition at line 109 of file QGCStateMachine.cc.
References registerState().
| ConditionalState * QGCStateMachine::addConditionalState | ( | const QString & | stateName, |
| ConditionalState::Predicate | predicate, | ||
| ConditionalState::Action | action = nullptr |
||
| ) |
Create and register a ConditionalState
| stateName | Name for the state |
| predicate | Condition to evaluate |
| action | Action to execute if predicate is true |
Definition at line 197 of file QGCStateMachine.cc.
References registerState().
|
inline |
Create a conditional guarded transition Transition only taken if guard returns true
| from | Source state (must match signal's object type) |
| signal | Signal that triggers evaluation |
| to | Target state |
| guard | Predicate that must return true |
Definition at line 462 of file QGCStateMachine.h.
| DelayState * QGCStateMachine::addDelayState | ( | int | delayMsecs | ) |
Create and register a DelayState
| delayMsecs | Delay duration |
Definition at line 145 of file QGCStateMachine.cc.
References registerState().
| QGCState * QGCStateMachine::addErrorRecoveryState | ( | const QString & | stateName, |
| ErrorRecoveryBuilder::Action | action, | ||
| int | maxRetries = 0, |
||
| int | retryDelayMsecs = 1000, |
||
| ErrorRecoveryBuilder::ExhaustedBehavior | exhaustedBehavior = ErrorRecoveryBuilder::EmitError, |
||
| ErrorRecoveryBuilder::Action | fallback = nullptr, |
||
| ErrorRecoveryBuilder::VoidAction | rollback = nullptr, |
||
| int | timeoutMsecs = 0 |
||
| ) |
Create and register an ErrorRecoveryState via fluent builder semantics.
| stateName | Name for the state |
| action | Primary action to execute (returns true on success) |
| maxRetries | Number of retries after initial attempt |
| retryDelayMsecs | Delay between retries |
| exhaustedBehavior | Behavior when all options are exhausted |
| fallback | Optional fallback action |
| rollback | Optional rollback action |
| timeoutMsecs | Optional overall timeout |
Definition at line 118 of file QGCStateMachine.cc.
References ErrorRecoveryBuilder::build(), ErrorRecoveryBuilder::onExhausted(), ErrorRecoveryBuilder::retry(), ErrorRecoveryBuilder::withAction(), ErrorRecoveryBuilder::withFallback(), ErrorRecoveryBuilder::withRollback(), and ErrorRecoveryBuilder::withTimeout().
| EventQueuedState * QGCStateMachine::addEventQueuedState | ( | const QString & | stateName, |
| const QString & | eventName, | ||
| int | timeoutMsecs = 0 |
||
| ) |
Create and register an EventQueuedState
| stateName | Name for the state |
| eventName | Event name to wait for |
| timeoutMsecs | Optional timeout (0 = no timeout) |
Definition at line 213 of file QGCStateMachine.cc.
References registerState().
| MachineEventTransition * QGCStateMachine::addEventTransition | ( | QState * | from, |
| const QString & | eventName, | ||
| QAbstractState * | to, | ||
| QAbstractAnimation * | animation = nullptr |
||
| ) |
Create a machine event transition
| from | Source state |
| eventName | Event name to match |
| to | Target state |
| animation | Optional animation to run during transition |
Definition at line 410 of file QGCStateMachine.cc.
| QGCFinalState * QGCStateMachine::addFinalState | ( | const QString & | stateName = QString() | ) |
Add a final state that will stop the machine when entered
| stateName | Name for the state |
Definition at line 191 of file QGCStateMachine.cc.
| FunctionState * QGCStateMachine::addFunctionState | ( | const QString & | stateName, |
| std::function< void()> | function | ||
| ) |
Create and register a FunctionState
| stateName | Name for the state |
| function | Function to execute |
Definition at line 102 of file QGCStateMachine.cc.
References registerState().
|
inline |
Create a guarded transition between states
| from | Source state |
| signal | Signal that triggers the transition |
| to | Target state |
| guard | Predicate that must return true for transition |
| animation | Optional animation to play during transition |
Definition at line 410 of file QGCStateMachine.h.
|
inline |
Create a self-loop internal transition (no state exit/entry). Unlike addSelfLoopTransition, this does NOT trigger onExit/onEntry. Use when you want to handle signals without re-entering the state.
| state | The state containing the transition |
| sender | Object that emits the signal |
| signal | Signal that triggers the action |
| action | Action to perform on each signal |
Definition at line 516 of file QGCStateMachine.h.
| FunctionState * QGCStateMachine::addLogAndContinueErrorState | ( | const QString & | stateName, |
| QAbstractState * | nextState, | ||
| const QString & | message = QString() |
||
| ) |
Create a logging error handler state that advances to nextState.
Definition at line 292 of file QGCStateMachine.cc.
References ErrorHandlers::logAndContinue(), and registerState().
| FunctionState * QGCStateMachine::addLogAndStopErrorState | ( | const QString & | stateName, |
| const QString & | message = QString() |
||
| ) |
Create a logging error handler state that stops the machine.
Definition at line 301 of file QGCStateMachine.cc.
References ErrorHandlers::logAndStop(), and registerState().
| ParallelState * QGCStateMachine::addParallelState | ( | const QString & | stateName | ) |
Create and register a ParallelState
| stateName | Name for the state |
Definition at line 152 of file QGCStateMachine.cc.
References registerState().
|
inline |
Create a retry transition that retries an action before advancing
| from | Source state (must match signal's object type) |
| signal | Signal that triggers retry evaluation |
| to | Target state (used after max retries) |
| retryAction | Action to perform on retry |
| maxRetries | Maximum number of retries before advancing |
Definition at line 445 of file QGCStateMachine.h.
|
inline |
Create a self-loop transition that performs an action but stays in the same state. Useful for handling events/signals without changing state.
Inspired by Qt's rogue example where input events are processed but the state machine stays in the input state.
Example usage:
| state | The state to loop back to |
| sender | Object that emits the signal |
| signal | Signal that triggers the action |
| action | Action to perform on each signal |
Definition at line 494 of file QGCStateMachine.h.
| SubMachineState * QGCStateMachine::addSubMachineState | ( | const QString & | stateName, |
| SubMachineState::MachineFactory | factory | ||
| ) |
Create and register a SubMachineState
| stateName | Name for the state |
| factory | Function that creates the child state machine |
Definition at line 206 of file QGCStateMachine.cc.
References registerState().
| TimeoutTransition * QGCStateMachine::addTimeoutTransition | ( | QState * | from, |
| int | timeoutMsecs, | ||
| QAbstractState * | to, | ||
| QAbstractAnimation * | animation = nullptr |
||
| ) |
Create a timeout transition
| from | Source state |
| timeoutMsecs | Timeout in milliseconds |
| to | Target state |
| animation | Optional animation to run during transition |
Definition at line 421 of file QGCStateMachine.cc.
|
inline |
Create a simple signal transition between states
| from | Source state |
| signal | Signal that triggers the transition |
| to | Target state |
| animation | Optional animation to play during transition |
Definition at line 393 of file QGCStateMachine.h.
|
inline |
Create and register a WaitForSignalState
| stateName | Name for the state |
| sender | Object that emits the signal |
| signal | Signal to wait for |
| timeoutMsecs | Optional timeout (0 = no timeout) |
Definition at line 247 of file QGCStateMachine.h.
References registerState().
|
inline |
Get all timeout overrides.
Definition at line 655 of file QGCStateMachine.h.
| bool QGCStateMachine::attemptRecovery | ( | ) |
Attempt recovery to the recovery state (if set).
Definition at line 363 of file QGCStateMachine.cc.
References resetToState().
| bool QGCStateMachine::cancelDelayedEvent | ( | int | eventId | ) |
Cancel a previously posted delayed event
| eventId | The ID returned by postDelayedEvent |
Definition at line 173 of file QGCStateMachine.cc.
| void QGCStateMachine::clearError | ( | bool | restart = false | ) |
Clear the error state and optionally restart
| restart | If true, restarts the machine after clearing |
Definition at line 309 of file QGCStateMachine.cc.
References restart(), and start().
Referenced by recoverFromError().
|
inline |
Clear all timeout overrides.
Definition at line 658 of file QGCStateMachine.h.
|
inline |
Clear timeout statistics.
Definition at line 667 of file QGCStateMachine.h.
|
inline |
Get the state machine's context for inter-state data passing
Definition at line 91 of file QGCStateMachine.h.
Referenced by QGCAbstractState::context().
|
inline |
Definition at line 92 of file QGCStateMachine.h.
| QState * QGCStateMachine::createTimedActionState | ( | const QString & | stateName, |
| int | durationMsecs, | ||
| std::function< void()> | onEntry = nullptr, |
||
| std::function< void()> | onExit = nullptr |
||
| ) |
Create a composite state that performs an action, waits for a duration, then finishes. The state has internal structure: entry -> timing -> done (final). When done, emits QState::finished() which can be used for transitions.
Inspired by Qt's trafficlight example pattern.
Example usage:
| stateName | Name for the state |
| durationMsecs | How long to stay in the state |
| onEntry | Optional action to perform when state is entered |
| onExit | Optional action to perform when state is exited |
Definition at line 222 of file QGCStateMachine.cc.
| QString QGCStateMachine::currentStateName | ( | ) | const |
Get the name of the currently active state
Definition at line 51 of file QGCStateMachine.cc.
References active(), and activeStates().
|
signal |
Emitted when the current state changes (for QML binding)
| QList< QAbstractState * > QGCStateMachine::deadEndStates | ( | ) | const |
Find states that have no outgoing transitions and are not final states. These are potential dead-ends.
Definition at line 775 of file QGCStateMachine.cc.
References transitionsFrom().
| QString QGCStateMachine::dumpConfiguration | ( | ) | const |
Get a human-readable string showing all states and transitions. Useful for debugging and documentation.
Definition at line 515 of file QGCStateMachine.cc.
References transitionsFrom().
Referenced by logConfiguration().
| QString QGCStateMachine::dumpCurrentState | ( | ) | const |
Get a human-readable string showing the current state. Useful for debugging.
Definition at line 489 of file QGCStateMachine.cc.
References active().
Referenced by logCurrentState().
| QString QGCStateMachine::dumpRecordedHistory | ( | ) | const |
Definition at line 592 of file QGCStateMachine.cc.
References StateHistoryRecorder::dumpHistory().
| void QGCStateMachine::enablePropertyRestore | ( | ) |
Enable automatic property restoration when states exit When enabled, properties set via QGCState::setProperty/setEnabled/setVisible are automatically restored to their previous values when the state exits.
Definition at line 75 of file QGCStateMachine.cc.
| void QGCStateMachine::ensureRunning | ( | ) |
Start the machine if not already running.
Definition at line 378 of file QGCStateMachine.cc.
References start().
|
signal |
Referenced by SubMachineState::onEntry().
|
overrideprotected |
| QString QGCStateMachine::exportAsDot | ( | ) | const |
Export state machine structure as Graphviz DOT format. The output can be rendered using Graphviz tools like dot -Tpng output.dot -o output.png.
Definition at line 633 of file QGCStateMachine.cc.
References transitionsFrom().
| QAbstractState * QGCStateMachine::findState | ( | const QString & | stateName | ) | const |
Find a state by name
| stateName | The object name of the state |
Definition at line 274 of file QGCStateMachine.cc.
|
inline |
Find all states of a specific type.
Definition at line 317 of file QGCStateMachine.h.
|
inline |
Get the global error state.
Definition at line 143 of file QGCStateMachine.h.
| bool QGCStateMachine::historyRecordingEnabled | ( | ) | const |
Definition at line 587 of file QGCStateMachine.cc.
References StateHistoryRecorder::isEnabled().
| bool QGCStateMachine::isInErrorState | ( | ) | const |
Check if the machine is in an error state.
Definition at line 284 of file QGCStateMachine.cc.
Referenced by recoverFromError().
| bool QGCStateMachine::isPropertyRestoreEnabled | ( | ) | const |
Check if property restoration is enabled.
Definition at line 81 of file QGCStateMachine.cc.
| bool QGCStateMachine::isStateActive | ( | QAbstractState * | state | ) | const |
Check if a specific state is currently active
| state | The state to check |
Definition at line 269 of file QGCStateMachine.cc.
|
inline |
Get the last error message (from Qt's internal error handling)
Definition at line 339 of file QGCStateMachine.h.
References errorString.
| void QGCStateMachine::logConfiguration | ( | ) | const |
Log the full configuration to debug output.
Definition at line 568 of file QGCStateMachine.cc.
References dumpConfiguration().
| void QGCStateMachine::logCurrentState | ( | ) | const |
Log the current state to debug output.
Definition at line 563 of file QGCStateMachine.cc.
References dumpCurrentState().
|
signal |
Emitted when a named event is posted to the machine Used by EventQueuedState to detect events
| eventName | Name of the posted event |
Referenced by EventQueuedState::connectWaitSignal(), and postEvent().
|
inline |
Definition at line 87 of file QGCStateMachine.h.
Referenced by SubMachineState::onEntry(), and QGCStateMachine().
| int QGCStateMachine::maxPathLength | ( | ) | const |
Calculate the maximum path length from initial state to any final state. Useful for understanding worst-case execution depth.
Definition at line 735 of file QGCStateMachine.cc.
References reachableFrom().
|
inlineprotectedvirtual |
Override to perform actions when machine starts.
Definition at line 696 of file QGCStateMachine.h.
Referenced by onEntry().
|
overrideprotected |
Definition at line 936 of file QGCStateMachine.cc.
References event(), and onEnter().
Referenced by createTimedActionState(), and setCallbacks().
|
overrideprotected |
Definition at line 947 of file QGCStateMachine.cc.
References event(), and onLeave().
Referenced by createTimedActionState(), and setCallbacks().
|
inlineprotectedvirtual |
Override to perform actions when machine stops.
Definition at line 699 of file QGCStateMachine.h.
Referenced by onExit().
| int QGCStateMachine::postDelayedEvent | ( | const QString & | eventName, |
| int | delayMsecs, | ||
| const QVariant & | data = QVariant() |
||
| ) |
Post a named event with a delay
| eventName | Name of the event |
| delayMsecs | Delay in milliseconds |
| data | Optional payload data |
Definition at line 167 of file QGCStateMachine.cc.
| void QGCStateMachine::postEvent | ( | const QString & | eventName, |
| const QVariant & | data = QVariant(), |
||
| EventPriority | priority = NormalPriority |
||
| ) |
Post a named event to be processed immediately
| eventName | Name of the event |
| data | Optional payload data |
| priority | Event priority (HighPriority events are processed before NormalPriority) |
Definition at line 159 of file QGCStateMachine.cc.
References machineEvent().
| QList< QAbstractState * > QGCStateMachine::predecessorsOf | ( | QAbstractState * | state | ) | const |
Get states that can reach this state
| state | The target state |
Definition at line 472 of file QGCStateMachine.cc.
References transitionsTo().
| bool QGCStateMachine::profilingEnabled | ( | ) | const |
Definition at line 610 of file QGCStateMachine.cc.
References StateMachineProfiler::isEnabled().
| QString QGCStateMachine::profilingSummary | ( | ) | const |
Definition at line 615 of file QGCStateMachine.cc.
References StateMachineProfiler::summary().
| float QGCStateMachine::progress | ( | ) | const |
Get the current overall progress (0.0 to 1.0)
Definition at line 865 of file QGCStateMachine.cc.
|
signal |
Emitted when progress changes (if progress tracking is enabled)
| progress | Overall progress from 0.0 to 1.0 |
Referenced by QGCStateMachine(), and setSubProgress().
| QList< QAbstractState * > QGCStateMachine::reachableFrom | ( | QAbstractState * | state | ) | const |
Get the target states reachable from a state
| state | The source state |
Definition at line 459 of file QGCStateMachine.cc.
References transitionsFrom().
Referenced by maxPathLength(), and unreachableStates().
| QJsonArray QGCStateMachine::recordedHistoryJson | ( | ) | const |
Definition at line 597 of file QGCStateMachine.cc.
References StateHistoryRecorder::toJson().
| void QGCStateMachine::recordTimeout | ( | const QString & | stateName | ) |
Record a timeout for statistics.
Definition at line 915 of file QGCStateMachine.cc.
| bool QGCStateMachine::recoverFromError | ( | ) |
Recover from error state by restarting the machine. If not in error state, this has no effect.
Definition at line 351 of file QGCStateMachine.cc.
References clearError(), and isInErrorState().
|
inline |
Get the recovery state.
Definition at line 363 of file QGCStateMachine.h.
| void QGCStateMachine::registerState | ( | QGCAbstractState * | state | ) |
Register a QGCAbstractState with the machine and automatically wire up error transitions
| state | The state to register |
Definition at line 94 of file QGCStateMachine.cc.
References QGCAbstractState::error().
| void QGCStateMachine::registerState | ( | QGCState * | state | ) |
Register a QGCState with the machine and automatically wire up error transitions If a global error state is set, the state's error() signal will transition to it
| state | The state to register |
Definition at line 86 of file QGCStateMachine.cc.
References QGCAbstractState::error(), and QGCState::localErrorState().
Referenced by addAsyncFunctionState(), addConditionalState(), addDelayState(), addEventQueuedState(), addFunctionState(), addLogAndContinueErrorState(), addLogAndStopErrorState(), addParallelState(), addSubMachineState(), addWaitForSignalState(), and ErrorRecoveryBuilder::build().
| void QGCStateMachine::removeTimeoutOverride | ( | const QString & | stateName | ) |
Remove a timeout override
| stateName | The state name to remove override for |
Definition at line 905 of file QGCStateMachine.cc.
| void QGCStateMachine::resetProgress | ( | ) |
Reset progress tracking (call when restarting the machine)
Definition at line 870 of file QGCStateMachine.cc.
Referenced by resetToState(), and InitialConnectStateMachine::start().
| bool QGCStateMachine::resetToState | ( | QAbstractState * | state | ) |
Reset the machine and restart from a specific state. Useful for retrying from a failed state without restarting the entire sequence.
| state | The state to start from |
Definition at line 317 of file QGCStateMachine.cc.
References resetProgress(), setInitialState(), and start().
Referenced by attemptRecovery().
| void QGCStateMachine::restart | ( | ) |
Restart the machine (stop then start)
Definition at line 391 of file QGCStateMachine.cc.
References start().
Referenced by clearError().
|
signal |
Emitted when the running state changes (for QML binding)
Referenced by QGCStateMachine().
| void QGCStateMachine::setCallbacks | ( | EntryCallback | onEntry, |
| ExitCallback | onExit = nullptr |
||
| ) |
Set both entry and exit callbacks.
Definition at line 926 of file QGCStateMachine.cc.
|
inline |
Set a global event handler for the machine Handler is called before events are processed by states
Definition at line 128 of file QGCStateMachine.h.
| void QGCStateMachine::setGlobalErrorState | ( | QAbstractState * | errorState | ) |
Set a global error state that all QGCState errors will transition to
| errorState | The state to transition to on error |
Definition at line 70 of file QGCStateMachine.cc.
| void QGCStateMachine::setHistoryRecordingEnabled | ( | bool | enabled, |
| int | maxEntries = 1000 |
||
| ) |
Enable/disable structured transition history recording.
Definition at line 578 of file QGCStateMachine.cc.
References StateHistoryRecorder::setEnabled(), and StateHistoryRecorder::setMaxEntries().
Referenced by QGCStateMachine().
| void QGCStateMachine::setInitialState | ( | QAbstractState * | state, |
| bool | autoStart = false |
||
| ) |
Set the initial state and optionally start the machine
| state | The initial state |
| autoStart | If true, starts the machine immediately |
Definition at line 183 of file QGCStateMachine.cc.
References start().
Referenced by resetToState().
|
inline |
Set a callback to be invoked when the machine starts.
Definition at line 114 of file QGCStateMachine.h.
|
inline |
Set a callback to be invoked when the machine stops.
Definition at line 117 of file QGCStateMachine.h.
| void QGCStateMachine::setProfilingEnabled | ( | bool | enabled | ) |
Enable/disable state timing profiler.
Definition at line 602 of file QGCStateMachine.cc.
References StateMachineProfiler::setEnabled().
Referenced by QGCStateMachine().
| void QGCStateMachine::setProgressWeights | ( | const QList< QPair< QAbstractState *, int > > & | stateWeights | ) |
Set up weighted progress tracking for a sequence of states. Each state is assigned a weight representing its relative contribution to overall progress. States with higher weights contribute more to the progress bar.
Example:
| stateWeights | List of state/weight pairs in order of execution |
Definition at line 800 of file QGCStateMachine.cc.
|
inline |
Set a recovery state to transition to after error handling. When an error occurs and this is set, the machine can recover to this state instead of stopping.
| state | The state to recover to (nullptr to disable) |
Definition at line 360 of file QGCStateMachine.h.
|
inline |
Set the maximum number of state history entries to keep.
Definition at line 107 of file QGCStateMachine.h.
| void QGCStateMachine::setStructuredLoggingEnabled | ( | bool | enabled | ) |
Enable/disable structured state-machine logger.
Definition at line 620 of file QGCStateMachine.cc.
References StateMachineLogger::setEnabled().
Referenced by QGCStateMachine().
| void QGCStateMachine::setSubProgress | ( | float | subProgress | ) |
Update sub-progress within the current state (0.0 to 1.0). Call this from state callbacks to show progress within a long-running state.
| subProgress | Progress within current state (0.0 = just started, 1.0 = complete) |
Definition at line 854 of file QGCStateMachine.cc.
References progressUpdate().
| void QGCStateMachine::setTimeoutOverride | ( | const QString & | stateName, |
| int | timeoutMsecs | ||
| ) |
Set a timeout override for a specific state. Use this to adjust timeouts at runtime without recompiling.
| stateName | The object name of the state |
| timeoutMsecs | New timeout in milliseconds |
Definition at line 899 of file QGCStateMachine.cc.
|
slot |
Start the state machine with debug logging.
Definition at line 62 of file QGCStateMachine.cc.
Referenced by clearError(), ensureRunning(), SubMachineState::onEntry(), RequestMetaDataTypeStateMachine::request(), ComponentInformationManager::requestAllComponentInformation(), resetToState(), restart(), setInitialState(), and InitialConnectStateMachine::start().
|
inline |
Get a list of recent state names (limited history for QML display)
Definition at line 104 of file QGCStateMachine.h.
|
signal |
Emitted when the state history changes (for QML binding)
| void QGCStateMachine::stopMachine | ( | bool | deleteOnStop = true | ) |
Stop the machine and optionally delete it
| deleteOnStop | If true, the machine will be deleted when stopped |
Definition at line 385 of file QGCStateMachine.cc.
| bool QGCStateMachine::structuredLoggingEnabled | ( | ) | const |
Definition at line 628 of file QGCStateMachine.cc.
References StateMachineLogger::isEnabled().
| int QGCStateMachine::timeoutOverride | ( | const QString & | stateName | ) | const |
Get the timeout override for a state, or -1 if not set.
Definition at line 910 of file QGCStateMachine.cc.
Referenced by WaitStateBase::restartWait().
|
inline |
Get timeout statistics (how often each state timed out)
Definition at line 661 of file QGCStateMachine.h.
| QList< QAbstractTransition * > QGCStateMachine::transitionsFrom | ( | QAbstractState * | state | ) | const |
Get all transitions originating from a state
| state | The source state |
Definition at line 437 of file QGCStateMachine.cc.
Referenced by deadEndStates(), dumpConfiguration(), exportAsDot(), and reachableFrom().
| QList< QAbstractTransition * > QGCStateMachine::transitionsTo | ( | QAbstractState * | state | ) | const |
Get all transitions targeting a state
| state | The target state |
Definition at line 446 of file QGCStateMachine.cc.
Referenced by predecessorsOf().
| QList< QAbstractState * > QGCStateMachine::unreachableStates | ( | ) | const |
Find states that are not reachable from the initial state. These are typically configuration errors or dead code.
Definition at line 699 of file QGCStateMachine.cc.
References reachableFrom().
|
inline |
Definition at line 86 of file QGCStateMachine.h.
Referenced by ComponentInformationManager::compInfoParam(), and QGCAbstractState::vehicle().