odil
C++11libraryfortheDICOMstandard
Association.h
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 _a52696bc_5c6e_402d_a343_6cb085eb0138
10 #define _a52696bc_5c6e_402d_a343_6cb085eb0138
11 
12 #include <cstdint>
13 #include <functional>
14 #include <map>
15 #include <string>
16 #include <vector>
17 
18 #include "odil/AssociationAcceptor.h"
19 #include "odil/AssociationParameters.h"
20 #include "odil/dul/StateMachine.h"
21 #include "odil/message/Message.h"
22 #include "odil/odil.h"
23 
24 namespace odil
25 {
26 
30 class ODIL_API Association
31 {
32 public:
34  enum Result
35  {
36  Accepted=0,
37  RejectedPermanent=1,
38  RejectedTransient=2,
39  };
40 
43  {
44  ULServiceUser=1,
45  ULServiceProviderACSERelatedFunction=2,
46  ULServiceProvderPresentationRelatedFunction=3,
47  };
48 
49  // PS 3.8, 7.1.1.9, and PS 3.8, 9.3.4, and ITU-T X.227 (UL service-user,
50  // UL service-provider ACSE-related function), ITU-T X.226 (UL
51  // service-provider presentation-related function)
54  {
55  // UL service-user
56  NoReasonGiven=1,
57  ApplicationContextNameNotSupported=2,
58  CallingAETitleNotRecognized=3,
59  CallingAPInvocationIdentifierNotRecognized=4,
60  CallingAEQualifierNotRecognized=5,
61  CallingAEInvocationIdentifierNotRecognized=6,
62  CalledAETitleNotRecognized=7,
63  CalledAPInvocationIdentifierNotRecognized=8,
64  CalledAEQualifierNotRecognized=9,
65  CalledAEInvocationIdentifierNotRecognized=10,
66 
67  // UL service-provider, ACSE-related function
68  NoCommonULVersion=2,
69 
70  // UL service-provider, presentation-related function
71  TemporaryCongestion=1,
72  LocalLimitExceeded=2,
73  CalledPresentationAddressUnknown=3,
74  PresentationProtocolVersionNotSupported=4,
75  NoPresentationServiceAccessPointAvailable=7,
76  };
77 
79  typedef dul::StateMachine::duration_type duration_type;
80 
82  Association();
83 
85  Association(Association const & other);
86 
88  ~Association();
89 
91  dul::Transport & get_transport();
92 
94  Association & operator=(Association const & other);
95 
98 
100  std::string const & get_peer_host() const;
102  void set_peer_host(std::string const & host);
103 
105  uint16_t get_peer_port() const;
107  void set_peer_port(uint16_t port);
108 
110 
112  AssociationParameters const & get_parameters() const;
113 
115  AssociationParameters & update_parameters();
116 
118  void set_parameters(AssociationParameters const & value);
119 
121  AssociationParameters const & get_negotiated_parameters() const;
122 
125 
127  duration_type get_tcp_timeout() const;
128 
130  void set_tcp_timeout(duration_type const & duration);
131 
133  duration_type get_message_timeout() const;
134 
136  void set_message_timeout(duration_type const & duration);
137 
139 
142 
144  bool is_associated() const;
145 
147  void associate();
148 
150  void receive_association(
151  boost::asio::ip::tcp const & protocol, unsigned short port,
152  AssociationAcceptor acceptor=default_association_acceptor);
153 
155  void reject(Result result, ResultSource result_source, Diagnostic diagnostic);
156 
158  void release();
160  void abort(int source, int reason);
161 
163 
166 
173  message::Message receive_message();
174 
176  void send_message(
177  message::Message const & message, std::string const & abstract_syntax);
178 
180  uint16_t next_message_id();
181 
183 
184 private:
185  dul::StateMachine _state_machine;
186 
187  std::string _peer_host;
188  uint16_t _peer_port;
189 
190  AssociationParameters _association_parameters;
191  AssociationParameters _negotiated_parameters;
192 
193  std::map<std::string, std::pair<uint8_t, std::string>>
194  _transfer_syntaxes_by_abstract_syntax;
195  std::map<uint8_t, std::string> _transfer_syntaxes_by_id;
196 
197  uint16_t _next_message_id;
198 };
199 
204 class ODIL_API AssociationReleased: public Exception
205 {
206 public:
208  : Exception("Association released")
209  {
210  // Nothing else.
211  }
212 };
213 
218 class ODIL_API AssociationAborted: public Exception
219 {
220 public:
222  uint8_t source;
223 
225  uint8_t reason;
226 
228  AssociationAborted(unsigned char source, unsigned char reason)
229  : Exception("Association aborted"), source(source), reason(reason)
230  {
231  // Nothing else.
232  }
233 };
234 
235 }
236 
237 #endif // _a52696bc_5c6e_402d_a343_6cb085eb0138
Exception reported when receiving a message after the association was released.
Definition: Association.h:204
Base class for odil exceptions.
Definition: Exception.h:21
Definition: Association.cpp:39
ResultSource
Source of association result (PS 3.8, 7.1.1.8 and PS 3.8, 9.3.4).
Definition: Association.h:42
Encapsulate association parameters.
Definition: AssociationParameters.h:26
Result
Association result (ITU-T X.227, PS 3.8, 7.1.1.7 and PS 3.8, 9.3.4).
Definition: Association.h:34
Exception reported when receiving a message after the association was aborted.
Definition: Association.h:218
Diagnostic
Diagnostic of association result.
Definition: Association.h:53
dul::StateMachine::duration_type duration_type
Duration of the timeout.
Definition: Association.h:79
AssociationAborted(unsigned char source, unsigned char reason)
Constructor.
Definition: Association.h:228
uint8_t reason
Reason of the error.
Definition: Association.h:225
Association.
Definition: Association.h:30
uint8_t source
Source of the error.
Definition: Association.h:222