QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstBridgePrimeRetry.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/qglobal.h>
4
5#if defined(QGC_HAS_ANY_GPU_PATH)
6
11namespace GstBridgePrimeRetry {
12
13struct PrimeRetryState
14{
15 bool primed = false;
16 bool primeAttempted = false;
17 int nullCount = 0;
18 int maxRetries = 16;
19};
20
21enum class Decision
22{
23 AlreadyPrimed,
24 ShouldRetry,
25 GiveUp
26};
27
30inline Decision primeRetryGuard(PrimeRetryState& s)
31{
32 if (s.primed) {
33 return Decision::AlreadyPrimed;
34 }
35 if (s.primeAttempted) {
36 return Decision::GiveUp;
37 }
38 s.primeAttempted = true;
39 return Decision::ShouldRetry;
40}
41
45inline bool rearmRetry(PrimeRetryState& s)
46{
47 ++s.nullCount;
48 if (s.nullCount <= s.maxRetries) {
49 s.primeAttempted = false;
50 return true;
51 }
52 return false;
53}
54
56inline bool justGaveUp(const PrimeRetryState& s)
57{
58 return s.nullCount == s.maxRetries + 1;
59}
60
62inline void resetRetry(PrimeRetryState& s)
63{
64 s.primed = false;
65 s.primeAttempted = false;
66 s.nullCount = 0;
67}
68
71inline bool rearmAfterExhaustion(PrimeRetryState& s)
72{
73 if (s.primed) {
74 return false;
75 }
76 if (s.primeAttempted && s.nullCount > s.maxRetries) {
77 s.primeAttempted = false;
78 s.nullCount = 0;
79 return true;
80 }
81 return false;
82}
83
84} // namespace GstBridgePrimeRetry
85
86#endif // QGC_HAS_ANY_GPU_PATH