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
13class RetryState : public QGCState
14{
15 Q_OBJECT
16 Q_DISABLE_COPY(RetryState)
17
18public:
19 using Action = std::function<bool()>;
20
25 Q_ENUM(ExhaustedBehavior)
26
27 RetryState(const QString& stateName, QState* parent,
28 Action action,
29 int maxRetries = 0,
30 int retryDelayMsecs = 1000,
32
33 int currentAttempt() const { return _currentAttempt; }
34 int maxRetries() const { return _maxRetries; }
35 int totalAttempts() const { return _maxRetries + 1; }
36 ExhaustedBehavior exhaustedBehavior() const { return _exhaustedBehavior; }
37 bool wasSkipped() const { return _wasSkipped; }
38
39signals:
41 void retrying(int attempt, int maxAttempts);
42
44 void succeeded();
45
47 void exhausted();
48
50 void skipped();
51
52protected:
53 void onEnter() override;
54
55private slots:
56 void _executeAction();
57
58private:
59 Action _action;
60 int _maxRetries = 0;
61 int _retryDelayMsecs = 1000;
62 ExhaustedBehavior _exhaustedBehavior = EmitError;
63
64 int _currentAttempt = 0;
65 bool _wasSkipped = false;
66 QTimer _retryTimer;
67};
QString stateName() const
int currentAttempt() const
Definition RetryState.h:33
void succeeded()
Emitted when the action eventually succeeds.
int totalAttempts() const
Definition RetryState.h:35
std::function< bool()> Action
Definition RetryState.h:19
int maxRetries() const
Definition RetryState.h:34
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:23
@ EmitError
Emit error() after retries exhausted.
Definition RetryState.h:22
bool wasSkipped() const
Definition RetryState.h:37
ExhaustedBehavior exhaustedBehavior() const
Definition RetryState.h:36
void retrying(int attempt, int maxAttempts)
Emitted before each retry attempt.