Woman, Life, Freedom


Adaptive AUTOSAR
ARA public interface header documentation
machine_state.h
1#ifndef MACHINE_STATE_H
2#define MACHINE_STATE_H
3
4#include <functional>
5#include "./abstract_state_machine.h"
6
7namespace ara
8{
9 namespace com
10 {
11 namespace helper
12 {
14 enum class SdServerState
15 {
16 NotReady,
20 };
21
23 enum class SdClientState
24 {
28 Stopped,
31 };
32
34 enum class PubSubState
35 {
39 };
40
44 template <typename T>
46 {
47 private:
48 const T mState;
49 std::function<void(T, T)> mTransitionCallback;
50 AbstractStateMachine<T> *mFiniteStateMachine;
51
52 protected:
55 virtual void Deactivate(T nextState) = 0;
56
59 void Transit(T nextState)
60 {
61 Deactivate(nextState);
62 if (mFiniteStateMachine)
63 {
64 mFiniteStateMachine->Transit(mState, nextState);
65 }
66 }
67
70 MachineState(T state) noexcept : mState{state},
71 mFiniteStateMachine{nullptr}
72 {
73 }
74
75 public:
76 virtual ~MachineState() = default;
77 MachineState(const MachineState &) = delete;
78 MachineState &operator=(const MachineState &) = delete;
79
82 T GetState() const noexcept
83 {
84 return mState;
85 }
86
89 virtual void Activate(T previousState) = 0;
90
93 void Register(AbstractStateMachine<T> *finiteStateMachine) noexcept
94 {
95 mFiniteStateMachine = finiteStateMachine;
96 }
97 };
98 }
99 }
100}
101
102#endif
Abstract Finite State Machine (FMS) that transits between states.
Definition: abstract_state_machine.h:14
virtual void Transit(T previousState, T nextState)=0
Tranit from the current state to a new state.
Machine state abstract class.
Definition: machine_state.h:46
virtual void Deactivate(T nextState)=0
Deactivating the current state before transiting to the next state.
T GetState() const noexcept
Get the machine state.
Definition: machine_state.h:82
MachineState(T state) noexcept
Constructor.
Definition: machine_state.h:70
void Register(AbstractStateMachine< T > *finiteStateMachine) noexcept
Register the state to a finite state machine (FSM)
Definition: machine_state.h:93
void Transit(T nextState)
Transit to the next state.
Definition: machine_state.h:59
virtual void Activate(T previousState)=0
Activate the state.
SdClientState
Service discovery client machine state.
Definition: machine_state.h:24
@ ServiceNotSeen
Service is not requested and not seen.
@ ServiceSeen
Service is not requsted, but seen.
@ RepetitionPhase
Client service is in repetition phase.
@ Stopped
Service is stopped.
@ ServiceReady
Service is ready.
@ InitialWaitPhase
Client service is in initial waiting phase.
SdServerState
Service discovery server machine state.
Definition: machine_state.h:15
@ RepetitionPhase
Server's service is in repetition phase.
@ MainPhase
Server's service is in main phase.
@ NotReady
Server's service is down.
@ InitialWaitPhase
Server's service is in initial waiting phase.
PubSubState
Publish-subscribe server machine state.
Definition: machine_state.h:35
@ NotSubscribed
Service server is up, but there is no subscriber.
@ Subscribed
Service server is up, and there is at least a subscriber.
@ ServiceDown
Service server is down.