ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
actionsStd.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup server
4  * @copyright ESO - European Southern Observatory
5  * @author
6  *
7  * @brief ActionsStd class header file.
8  */
9 #ifndef SERVER_ACTION_STD_HPP_
10 #define SERVER_ACTION_STD_HPP_
11 
12 #include <rad/actionGroup.hpp>
13 #include <rad/signal.hpp>
14 #include <rad/smAdapter.hpp>
15 
16 #include <string>
17 #include <optional>
18 
19 namespace server {
20 
21 class DataContext;
22 
23 /**
24  * Make a status string from active states (as returned from scxml4cpp::Executor::getStatus()).
25  *
26  * Assumptions:
27  * - Top level state Off is a final state when exiting, otherwise:
28  * - One leaf state (State::isActive() == true).
29  * - Ancestors == 2 (On/<state>/<substate>)
30  *
31  * @note: scml4cpp::State does not provide const-accessors so @a states must be provided as
32  * non-const, but won't modiy it.
33  *
34  * @return "<state>;<substate>" if assumptions hold
35  * @return std::nullopt otherwise.
36  */
37 std::optional<std::string> MakeStatusString(std::list<scxml4cpp::State*>&& states);
38 
39 
40 /**
41  * This class contains the implementation of the actions dealing with
42  * the standard commands from stdif.xml and the following signals:
43  *
44  * - SIGINT
45  * - SIGTERM
46  *
47  * In addition it implements the:
48  * - scxml4cpp::StatusListener interface to receive the notification of change of state from the State Machine engine.
49  * - rad::EventRejectListener interface to receive the notification of rejected event from the State Machine adapter.
50  */
51 class ActionsStd : public rad::ActionGroup {
52  public:
53  /**
54  * Constructor.
55  *
56  * @param[in] ios Reference to the event loop.
57  * @param[in] sm Reference to the SM Adapter used to inject internal events.
58  * @param[in] data Data shared within the application among actions and activities.
59  */
60  ActionsStd(boost::asio::io_service& ios,
61  rad::SMAdapter& sm,
62  DataContext& data);
63 
64  /**
65  * Implementation of the GetState action. This action:
66  * - replies back for the originator of the GetState request with the
67  * current State Machine active state configuration.
68  *
69  * @param[in] c Context containing the last event received by the State Machine.
70  */
71  void GetState(scxml4cpp::Context* c);
72 
73  /**
74  * Implementation of the GetStatus action. This action:
75  * - replies back for the originator of the GetStatus request with the
76  * current State Machine active state configuration formatted.
77  *
78  * @param[in] c Context containing the last event received by the State Machine.
79  */
80  void GetStatus(scxml4cpp::Context* c);
81 
82 
83  /**
84  * Implementation of the Stop action. This action:
85  * - replies back for the originator of the ReqStop request.
86  *
87  * @param[in] c Context containing the last event received by the State Machine.
88  */
89  void Stop(scxml4cpp::Context* c);
90 
91  /**
92  * Implementation of the Init action. This action:
93  * - re-initialize the application run-time data,
94  * - replies back for the originator of the ReqInit request.
95  *
96  * @param[in] c Context containing the last event received by the State Machine.
97  */
98  void Init(scxml4cpp::Context* c);
99 
100  /**
101  * Implementation of the Enable action. This action:
102  * - replies back for the originator of the ReqEnable request.
103  *
104  * @param[in] c Context containing the last event received by the State Machine.
105  */
106  void Enable(scxml4cpp::Context* c);
107 
108  /**
109  * Implementation of the Disable action. This action:
110  * - replies back for the originator of the ReqDisable request.
111  *
112  * @param[in] c Context containing the last event received by the State Machine.
113  */
114  void Disable(scxml4cpp::Context* c);
115 
116  /**
117  * Implementation of the Reset action. This action:
118  * - replies back for the originator of the ReqReset request.
119  *
120  * @param[in] c Context containing the last event received by the State Machine.
121  */
122  void Reset(scxml4cpp::Context* c);
123 
124  /**
125  * Implementation of the SetLogLevel action. This action:
126  * - changes the log level,
127  * - replies back for the originator of the ReqSetLogLevel request.
128  *
129  * @param[in] c Context containing the last event received by the State Machine.
130  */
131  void SetLogLevel(scxml4cpp::Context* c);
132 
133  /**
134  * Implementation of the Exit action. This action:
135  * - replies back for the originator of the ReqExit request.
136  * - stops the event loop.
137  *
138  * @param[in] c Context containing the last event received by the State Machine.
139  */
140  void Exit(scxml4cpp::Context* c);
141 
142  /**
143  * Implementation of the ExitNoReply action. This action:
144  * - stops the event loop.
145  *
146  * @param[in] c Context containing the last event received by the State Machine.
147  */
148  void ExitNoReply(scxml4cpp::Context* c);
149 
150  ActionsStd(const ActionsStd&) = delete; //! Disable copy constructor
151  ActionsStd& operator=(const ActionsStd&) = delete; //! Disable assignment operator
152 
153  private:
154  boost::asio::io_service& m_io_service;
155  rad::SMAdapter& m_sm;
156  rad::Signal m_signal;
157  DataContext& m_data;
158 };
159 
160 } // namespace server
161 
162 #endif // SERVER_ACTION_STD_HPP_
This class contains the implementation of the actions dealing with the standard commands from stdif....
Definition: actionsStd.hpp:51
ActionsStd & operator=(const ActionsStd &)=delete
Disable copy constructor.
void Init(scxml4cpp::Context *c)
Implementation of the Init action.
Definition: actionsStd.cpp:126
void Enable(scxml4cpp::Context *c)
Implementation of the Enable action.
Definition: actionsStd.cpp:137
ActionsStd(boost::asio::io_service &ios, rad::SMAdapter &sm, DataContext &data)
Constructor.
Definition: actionsStd.cpp:61
void GetState(scxml4cpp::Context *c)
Implementation of the GetState action.
Definition: actionsStd.cpp:91
void GetStatus(scxml4cpp::Context *c)
Implementation of the GetStatus action.
Definition: actionsStd.cpp:102
ActionsStd(const ActionsStd &)=delete
void SetLogLevel(scxml4cpp::Context *c)
Implementation of the SetLogLevel action.
Definition: actionsStd.cpp:170
void Disable(scxml4cpp::Context *c)
Implementation of the Disable action.
Definition: actionsStd.cpp:148
void Stop(scxml4cpp::Context *c)
Implementation of the Stop action.
Definition: actionsStd.cpp:115
void ExitNoReply(scxml4cpp::Context *c)
Implementation of the ExitNoReply action.
Definition: actionsStd.cpp:86
void Exit(scxml4cpp::Context *c)
Implementation of the Exit action.
Definition: actionsStd.cpp:74
void Reset(scxml4cpp::Context *c)
Implementation of the Reset action.
Definition: actionsStd.cpp:159
This class provide access to the application run-time data including the in-memory DB.
Definition: dataContext.hpp:21
std::optional< std::string > MakeStatusString(std::list< scxml4cpp::State * > &&states)
Make a status string from active states (as returned from scxml4cpp::Executor::getStatus()).
Definition: actionsStd.cpp:29