|
10 | 10 |
|
11 | 11 | #pragma once
|
12 | 12 |
|
13 |
| -namespace arduino { namespace tattempt { |
| 13 | +/** |
| 14 | + * The TimedAttempt class manages retry attempts with configurable delays. |
| 15 | + * It allows setting minimum and maximum delays, and provides methods to |
| 16 | + * begin, retry, reset, and check the status of attempts. |
| 17 | + */ |
| 18 | +class TimedAttempt { |
| 19 | + |
| 20 | +public: |
| 21 | + /** |
| 22 | + * Constructor to initialize TimedAttempt with minimum and maximum delay |
| 23 | + * @param minDelay: minimum delay between attempts |
| 24 | + * @param maxDelay: maximum delay between attempts |
| 25 | + */ |
| 26 | + TimedAttempt(unsigned long minDelay, unsigned long maxDelay); |
| 27 | + |
| 28 | + /** |
| 29 | + * Begin the attempt with a fixed delay |
| 30 | + * @param delay: fixed delay between attempts |
| 31 | + */ |
| 32 | + void begin(unsigned long delay); |
| 33 | + |
| 34 | + /** |
| 35 | + * Begin the attempt with a range of delays |
| 36 | + * @param minDelay: minimum delay between attempts |
| 37 | + * @param maxDelay: maximum delay between attempts |
| 38 | + */ |
| 39 | + void begin(unsigned long minDelay, unsigned long maxDelay); |
| 40 | + |
| 41 | + /** |
| 42 | + * Reconfigure the attempt with new minimum and maximum delays and reload |
| 43 | + * @param minDelay: new minimum delay between attempts |
| 44 | + * @param maxDelay: new maximum delay between attempts |
| 45 | + * @return the new delay after reconfiguration |
| 46 | + */ |
| 47 | + unsigned long reconfigure(unsigned long minDelay, unsigned long maxDelay); |
| 48 | + |
| 49 | + /** |
| 50 | + * Retry the attempt, incrementing the retry count and reloading the delay |
| 51 | + * @return the new delay after retry |
| 52 | + */ |
| 53 | + unsigned long retry(); |
| 54 | + |
| 55 | + /** |
| 56 | + * Reload the delay based on the retry count and return the new delay |
| 57 | + * @return the new delay after reload |
| 58 | + */ |
| 59 | + unsigned long reload(); |
| 60 | + |
| 61 | + /** |
| 62 | + * Reset the retry count to zero |
| 63 | + */ |
| 64 | + void reset(); |
| 65 | + |
| 66 | + /** |
| 67 | + * Check if a retry has been attempted |
| 68 | + * @return true if a retry has been attempted, false otherwise |
| 69 | + */ |
| 70 | + bool isRetry(); |
| 71 | + |
| 72 | + /** |
| 73 | + * Check if the current attempt has expired based on the delay |
| 74 | + * @return true if the current attempt has expired, false otherwise |
| 75 | + */ |
| 76 | + bool isExpired(); |
| 77 | + |
| 78 | + /** |
| 79 | + * Get the current retry count |
| 80 | + * @return the current retry count |
| 81 | + */ |
| 82 | + unsigned int getRetryCount(); |
14 | 83 |
|
15 | 84 | /**
|
16 |
| - * The TimedAttempt class manages retry attempts with configurable delays. |
17 |
| - * It allows setting minimum and maximum delays, and provides methods to |
18 |
| - * begin, retry, reset, and check the status of attempts. |
19 |
| - */ |
20 |
| - class TimedAttempt { |
21 |
| - |
22 |
| - public: |
23 |
| - /** |
24 |
| - * Constructor to initialize TimedAttempt with minimum and maximum delay |
25 |
| - * @param minDelay: minimum delay between attempts |
26 |
| - * @param maxDelay: maximum delay between attempts |
27 |
| - */ |
28 |
| - TimedAttempt(unsigned long minDelay, unsigned long maxDelay); |
29 |
| - |
30 |
| - /** |
31 |
| - * Begin the attempt with a fixed delay |
32 |
| - * @param delay: fixed delay between attempts |
33 |
| - */ |
34 |
| - void begin(unsigned long delay); |
35 |
| - |
36 |
| - /** |
37 |
| - * Begin the attempt with a range of delays |
38 |
| - * @param minDelay: minimum delay between attempts |
39 |
| - * @param maxDelay: maximum delay between attempts |
40 |
| - */ |
41 |
| - void begin(unsigned long minDelay, unsigned long maxDelay); |
42 |
| - |
43 |
| - /** |
44 |
| - * Reconfigure the attempt with new minimum and maximum delays and reload |
45 |
| - * @param minDelay: new minimum delay between attempts |
46 |
| - * @param maxDelay: new maximum delay between attempts |
47 |
| - * @return the new delay after reconfiguration |
48 |
| - */ |
49 |
| - unsigned long reconfigure(unsigned long minDelay, unsigned long maxDelay); |
50 |
| - |
51 |
| - /** |
52 |
| - * Retry the attempt, incrementing the retry count and reloading the delay |
53 |
| - * @return the new delay after retry |
54 |
| - */ |
55 |
| - unsigned long retry(); |
56 |
| - |
57 |
| - /** |
58 |
| - * Reload the delay based on the retry count and return the new delay |
59 |
| - * @return the new delay after reload |
60 |
| - */ |
61 |
| - unsigned long reload(); |
62 |
| - |
63 |
| - /** |
64 |
| - * Reset the retry count to zero |
65 |
| - */ |
66 |
| - void reset(); |
67 |
| - |
68 |
| - /** |
69 |
| - * Check if a retry has been attempted |
70 |
| - * @return true if a retry has been attempted, false otherwise |
71 |
| - */ |
72 |
| - bool isRetry(); |
73 |
| - |
74 |
| - /** |
75 |
| - * Check if the current attempt has expired based on the delay |
76 |
| - * @return true if the current attempt has expired, false otherwise |
77 |
| - */ |
78 |
| - bool isExpired(); |
79 |
| - |
80 |
| - /** |
81 |
| - * Get the current retry count |
82 |
| - * @return the current retry count |
83 |
| - */ |
84 |
| - unsigned int getRetryCount(); |
85 |
| - |
86 |
| - /** |
87 |
| - * Get the current wait time for the next retry |
88 |
| - * @return the current wait time for the next retry |
89 |
| - */ |
90 |
| - unsigned int getWaitTime(); |
91 |
| - |
92 |
| - private: |
93 |
| - unsigned long _minDelay; |
94 |
| - unsigned long _maxDelay; |
95 |
| - unsigned long _retryTick; |
96 |
| - unsigned long _retryDelay; |
97 |
| - unsigned int _retryCount; |
98 |
| - }; |
99 |
| - |
100 |
| -}} // arduino::tattempt |
| 85 | + * Get the current wait time for the next retry |
| 86 | + * @return the current wait time for the next retry |
| 87 | + */ |
| 88 | + unsigned int getWaitTime(); |
| 89 | + |
| 90 | +private: |
| 91 | + unsigned long _minDelay; |
| 92 | + unsigned long _maxDelay; |
| 93 | + unsigned long _retryTick; |
| 94 | + unsigned long _retryDelay; |
| 95 | + unsigned int _retryCount; |
| 96 | +}; |
0 commit comments