QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RetryState.h
Go to the documentation of this file.
1#pragma once
2
3#include "QGCState.h"
4
5#include <QtCore/QTimer>
6
7#include <functional>
8
14class RetryState : public QGCState
15{
16 Q_OBJECT
17 Q_DISABLE_COPY(RetryState)
18
19public:
20 using Action = std::function<bool()>;
21
26 Q_ENUM(ExhaustedBehavior)
27
28 RetryState(const QString& stateName, QState* parent,
29 Action action,
30 int maxRetries = 0,
31 int retryDelayMsecs = 1000,
33
34 int currentAttempt() const { return _currentAttempt; }
35 int maxRetries() const { return _maxRetries; }
36 int totalAttempts() const { return _maxRetries + 1; }
37 ExhaustedBehavior exhaustedBehavior() const { return _exhaustedBehavior; }
38 bool wasSkipped() const { return _wasSkipped; }
39
40signals:
42 void retrying(int attempt, int maxAttempts);
43
45 void succeeded();
46
48 void exhausted();
49
51 void skipped();
52
53protected:
54 void onEnter() override;
55
56private slots:
57 void _executeAction();
58
59private:
60 Action _action;
61 int _maxRetries = 0;
62 int _retryDelayMsecs = 1000;
63 ExhaustedBehavior _exhaustedBehavior = EmitError;
64
65 int _currentAttempt = 0;
66 bool _wasSkipped = false;
67 QTimer _retryTimer;
68};
QString stateName() const
Full-featured base class for QGroundControl state machine states.
Definition QGCState.h:23
A state that retries an action and chooses behavior when retries are exhausted.
Definition RetryState.h:15
int currentAttempt() const
Definition RetryState.h:34
void succeeded()
Emitted when the action eventually succeeds.
int totalAttempts() const
Definition RetryState.h:36
std::function< bool()> Action
Definition RetryState.h:20
int maxRetries() const
Definition RetryState.h:35
void skipped()
Emitted when retries are exhausted and behavior is EmitAdvance.
void onEnter() override
Override to perform actions on state entry.
Definition RetryState.cc:17
void exhausted()
Emitted when all retries are exhausted (both behaviors).
@ EmitAdvance
Emit advance() after retries exhausted (skip/continue).
Definition RetryState.h:24
@ EmitError
Emit error() after retries exhausted.
Definition RetryState.h:23
bool wasSkipped() const
Definition RetryState.h:38
ExhaustedBehavior exhaustedBehavior() const
Definition RetryState.h:37
void retrying(int attempt, int maxAttempts)
Emitted before each retry attempt.