Odil
A C++11 library for the DICOM standard
StateMachine.h
Go to the documentation of this file.
1 /*************************************************************************
2  * odil - Copyright (C) Universite de Strasbourg
3  * Distributed under the terms of the CeCILL-B license, as published by
4  * the CEA-CNRS-INRIA. Refer to the LICENSE file or to
5  * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
6  * for details.
7  ************************************************************************/
8 
9 #ifndef _981c80db_b2ac_4f25_af6c_febf5563d178
10 #define _981c80db_b2ac_4f25_af6c_febf5563d178
11 
12 #include <functional>
13 #include <map>
14 #include <tuple>
15 #include <utility>
16 
17 #include <boost/asio.hpp>
18 
20 #include "odil/dul/EventData.h"
21 #include "odil/dul/Transport.h"
22 #include "odil/odil.h"
23 
24 namespace odil
25 {
26 
27 namespace dul
28 {
29 
32 {
33 public:
34 
36  enum class State
37  {
38  Sta1,
39  Sta2, Sta3, Sta4, Sta5,
40  Sta6,
41  Sta7, Sta8, Sta9, Sta10, Sta11, Sta12,
42  Sta13
43  };
44 
46  enum class Event
47  {
48  None, // dummy event to allow easier initialization
49  TransportConnectionIndication, TransportConnectionConfirmation,
50  TransportConnectionClosedIndication,
51 
52  AAssociateRQLocal, AAssociateRQRemote,
53  AAssociateACLocal, AAssociateACRemote,
54  AAssociateRJLocal, AAssociateRJRemote,
55 
56  AReleaseRQLocal, AReleaseRQRemote,
57  AReleaseRPLocal, AReleaseRPRemote,
58 
59  PDataTFLocal, PDataTFRemote,
60 
61  AAbortLocal, AAbortRemote,
62 
63  ARTIMTimerExpired, InvalidPDU,
64  };
65 
67  typedef boost::asio::deadline_timer::duration_type duration_type;
68 
71 
74 
79  void transition(Event const & event, EventData & data);
80 
82  State get_state() const;
83 
85  Transport const & get_transport() const;
86 
89 
92 
94  void set_timeout(duration_type timeout);
95 
100  void receive(EventData & data);
101 
103  void send_pdu(EventData & data);
104 
106  void receive_pdu(EventData & data);
107 
109  void start_timer(EventData & data);
110 
112  void stop_timer();
113 
121 
127 
128 private:
129 
130  enum class Action
131  {
132  AE_1, AE_2, AE_3, AE_4, AE_5, AE_6, AE_7, AE_8,
133  DT_1, DT_2,
134  AR_1, AR_2, AR_3, AR_4, AR_5, AR_6, AR_7, AR_8, AR_9, AR_10,
135  AA_1, AA_2, AA_3, AA_4, AA_5, AA_6, AA_7, AA_8
136  };
137 
138  typedef std::map<
139  std::tuple<State, Event, bool>,
140  std::pair<Action, State>> TransitionMap;
141 
142  typedef std::map<
143  std::pair<State, Event>,
144  std::function<bool(StateMachine const &, EventData &)>> GuardMap;
145 
146  static TransitionMap const _transitions;
147  static GuardMap const _guards;
148 
150  State _state;
151 
153  Transport _transport;
154 
156  duration_type _timeout;
157 
159  boost::asio::deadline_timer _artim_timer;
160 
162  AssociationAcceptor _association_acceptor;
163 
165  void _send_pdu(EventData & data, uint8_t pdu_type);
166 
171  void AE_1(EventData & data);
172 
174  void AE_2(EventData & data);
175 
177  void AE_3(EventData & data);
178 
183  void AE_4(EventData & data);
184 
186  void AE_5(EventData & data);
187 
189  void AE_6(EventData & data);
190 
192  void AE_7(EventData & data);
193 
195  void AE_8(EventData & data);
196 
198  void DT_1(EventData & data);
199 
201  void DT_2(EventData & data);
202 
204  void AR_1(EventData & data);
205 
207  void AR_2(EventData & data);
208 
213  void AR_3(EventData & data);
214 
216  void AR_4(EventData & data);
217 
219  void AR_5(EventData & data);
220 
222  void AR_6(EventData & data);
223 
225  void AR_7(EventData & data);
226 
228  void AR_8(EventData & data);
229 
231  void AR_9(EventData & data);
232 
234  void AR_10(EventData & data);
235 
240  void AA_1(EventData & data);
241 
243  void AA_2(EventData & data);
244 
250  void AA_3(EventData & data);
251 
253  void AA_4(EventData & data);
254 
256  void AA_5(EventData & data);
257 
259  void AA_6(EventData & data);
260 
262  void AA_7(EventData & data);
263 
268  void AA_8(EventData & data);
269 };
270 
271 }
272 
273 }
274 
275 #endif // _981c80db_b2ac_4f25_af6c_febf5563d178
Data related to events of the DUL state machine.
Definition: EventData.h:28
State machine for the DICOM upper layer.
Definition: StateMachine.h:32
State
States of the state machine.
Definition: StateMachine.h:37
duration_type get_timeout() const
Return the timeout, default to infinity.
State get_state() const
Return the current state.
Transport & get_transport()
Return the TCP transport.
void transition(Event const &event, EventData &data)
Perform the transition related to the event and current state. Raise an exception if no such transiti...
boost::asio::deadline_timer::duration_type duration_type
Duration of the timeout.
Definition: StateMachine.h:67
void receive_pdu(EventData &data)
Receive a PDU on the transport, perform the corresponding transition.
void stop_timer()
Stop the ARTIM timer.
void receive(EventData &data)
Receive a connection on the TCP transport, perform the corresponding transition.
Transport const & get_transport() const
Return the TCP transport.
AssociationAcceptor const & get_association_acceptor() const
Return the callback checking whether the association request is acceptable.
void set_timeout(duration_type timeout)
Set the timeout.
StateMachine()
Constructor, initializing to Sta1.
void set_association_acceptor(AssociationAcceptor const &acceptor)
Set the callback checking whether the association request is acceptable.
~StateMachine()
Destructor, closing the transport.
void start_timer(EventData &data)
Start (or re-start if already started) the ARTIM timer.
void send_pdu(EventData &data)
Send a PDU to the transport, perform the corresponding transition.
Event
Event causing the transitions.
Definition: StateMachine.h:47
Definition: Association.h:25
std::function< AssociationParameters(AssociationParameters const &)> AssociationAcceptor
Callback to check whether the association request is acceptable.
Definition: AssociationAcceptor.h:30
#define ODIL_API
Definition: odil.h:28
TCP transport for the DICOM Upper Layer.
Definition: Transport.h:34