QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RollbackState.cc
Go to the documentation of this file.
1#include "RollbackState.h"
3
4RollbackState::RollbackState(const QString& stateName, QState* parent,
5 ForwardAction forwardAction, RollbackAction rollbackAction)
6 : QGCState(stateName, parent)
7 , _forwardAction(std::move(forwardAction))
8 , _rollbackAction(std::move(rollbackAction))
9{
10}
11
13{
14 _wasRolledBack = false;
15 _rollbackSucceeded = false;
16
17 qCDebug(QGCStateMachineLog) << stateName() << "executing forward action";
18
19 bool success = false;
20 if (_forwardAction) {
21 success = _forwardAction();
22 }
23
24 if (success) {
25 qCDebug(QGCStateMachineLog) << stateName() << "forward action succeeded";
26 emit forwardSucceeded();
27 emit advance();
28 } else {
29 qCDebug(QGCStateMachineLog) << stateName() << "forward action failed, rolling back";
30 emit forwardFailed();
31
32 _wasRolledBack = true;
33 emit rollingBack();
34
35 if (_rollbackAction) {
36 _rollbackAction();
37 _rollbackSucceeded = true;
38 qCDebug(QGCStateMachineLog) << stateName() << "rollback completed";
39 }
40
41 emit rollbackComplete();
42 emit error();
43 }
44}
QString stateName() const
void onEnter() override
Override to perform actions on state entry.
std::function< bool()> ForwardAction
Forward action - returns true on success.
void forwardSucceeded()
Emitted when forward action succeeds.
void rollingBack()
Emitted when rollback starts.
void forwardFailed()
Emitted when forward action fails (before rollback)
void rollbackComplete()
Emitted when rollback completes.
std::function< void()> RollbackAction
Rollback action - executed on forward failure.
RollbackState(const QString &stateName, QState *parent, ForwardAction forwardAction, RollbackAction rollbackAction)