Woman, Life, Freedom


Adaptive AUTOSAR
ARA public interface header documentation
repetition_state.h
1#ifndef REPETITION_STATE_H
2#define REPETITION_STATE_H
3
4#include <thread>
5#include <cmath>
6#include <chrono>
7#include "./timer_set_state.h"
8
9namespace ara
10{
11 namespace com
12 {
13 namespace someip
14 {
15 namespace sd
16 {
17 namespace fsm
18 {
22 template <typename T>
24 {
25 protected:
27 const int RepetitionsMax;
28
31
32 virtual void SetTimer() override
33 {
34 for (uint32_t i = 0; i < RepetitionsMax; ++i)
35 {
36 int _doubledDelay = std::pow(2, i) * RepetitionsBaseDelay;
37 auto _delay = std::chrono::milliseconds(_doubledDelay);
38 bool _interrupted = this->WaitFor(_delay);
39
40 if (_interrupted)
41 {
42 break;
43 }
44 else
45 {
46 // Invoke the on timer expiration callback
47 this->OnTimerExpired();
48 }
49 }
50 }
51
52 public:
61 T currentState,
62 T nextState,
63 T stoppedState,
64 std::function<void()> onTimerExpired,
65 uint32_t repetitionsMax,
66 int repetitionsBaseDelay) : helper::MachineState<T>(currentState),
67 TimerSetState<T>(nextState, stoppedState, onTimerExpired),
68 RepetitionsMax{static_cast<int>(repetitionsMax)},
69 RepetitionsBaseDelay{repetitionsBaseDelay}
70 {
71 if (repetitionsBaseDelay < 0)
72 {
73 throw std::invalid_argument("Invalid repetition base delay.");
74 }
75 }
76
77 RepetitionState() = delete;
78 RepetitionState(const RepetitionState &) = delete;
79 RepetitionState &operator=(const RepetitionState &) = delete;
80 };
81 }
82 }
83 }
84 }
85}
86
87#endif
MachineState(T state) noexcept
Constructor.
Definition: machine_state.h:70
Server's or client's service repetition state.
Definition: repetition_state.h:24
const int RepetitionsMax
Maximum iteration in repetition phase.
Definition: repetition_state.h:27
RepetitionState(T currentState, T nextState, T stoppedState, std::function< void()> onTimerExpired, uint32_t repetitionsMax, int repetitionsBaseDelay)
Constructor.
Definition: repetition_state.h:60
virtual void SetTimer() override
Set the phase time on state activation.
Definition: repetition_state.h:32
const int RepetitionsBaseDelay
Repetition iteration delay in milliseconds.
Definition: repetition_state.h:30
Server's or client's service timer set state.
Definition: timer_set_state.h:24
bool WaitFor(std::chrono::milliseconds duration)
Wait for certian period of time.
Definition: timer_set_state.h:49
const std::function< void()> OnTimerExpired
Delegate which is invoked by timer's thread when the timer is expired.
Definition: timer_set_state.h:76