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 
23 namespace odil
24 {
25 
30 {
31 public:
33  enum Result
34  {
35  Accepted=0,
36  RejectedPermanent=1,
37  RejectedTransient=2,
38  };
39 
42  {
43  ULServiceUser=1,
44  ULServiceProviderACSERelatedFunction=2,
45  ULServiceProvderPresentationRelatedFunction=3,
46  };
47 
48  // PS 3.8, 7.1.1.9, and PS 3.8, 9.3.4, and ITU-T X.227 (UL service-user,
49  // UL service-provider ACSE-related function), ITU-T X.226 (UL
50  // service-provider presentation-related function)
53  {
54  // UL service-user
55  NoReasonGiven=1,
56  ApplicationContextNameNotSupported=2,
57  CallingAETitleNotRecognized=3,
58  CallingAPInvocationIdentifierNotRecognized=4,
59  CallingAEQualifierNotRecognized=5,
60  CallingAEInvocationIdentifierNotRecognized=6,
61  CalledAETitleNotRecognized=7,
62  CalledAPInvocationIdentifierNotRecognized=8,
63  CalledAEQualifierNotRecognized=9,
64  CalledAEInvocationIdentifierNotRecognized=10,
65 
66  // UL service-provider, ACSE-related function
67  NoCommonULVersion=2,
68 
69  // UL service-provider, presentation-related function
70  TemporaryCongestion=1,
71  LocalLimitExceeded=2,
72  CalledPresentationAddressUnknown=3,
73  PresentationProtocolVersionNotSupported=4,
74  NoPresentationServiceAccessPointAvailable=7,
75  };
76 
78  typedef dul::StateMachine::duration_type duration_type;
79 
81  Association();
82 
84  Association(Association const & other);
85 
87  ~Association();
88 
90  dul::Transport & get_transport();
91 
93  Association & operator=(Association const & other);
94 
97 
99  std::string const & get_peer_host() const;
101  void set_peer_host(std::string const & host);
102 
104  uint16_t get_peer_port() const;
106  void set_peer_port(uint16_t port);
107 
109 
111  AssociationParameters const & get_parameters() const;
112 
115 
117  void set_parameters(AssociationParameters const & value);
118 
121 
124 
126  duration_type get_tcp_timeout() const;
127 
129  void set_tcp_timeout(duration_type const & duration);
130 
132  duration_type get_message_timeout() const;
133 
135  void set_message_timeout(duration_type const & duration);
136 
138 
141 
143  bool is_associated() const;
144 
146  void associate();
147 
149  void receive_association(
150  boost::asio::ip::tcp const & protocol, unsigned short port,
151  AssociationAcceptor acceptor=default_association_acceptor);
152 
154  void reject(Result result, ResultSource result_source, Diagnostic diagnostic);
155 
157  void release();
159  void abort(int source, int reason);
160 
162 
165 
172  message::Message receive_message();
173 
175  void send_message(
176  message::Message const & message, std::string const & abstract_syntax);
177 
179  uint16_t next_message_id();
180 
182 
183 private:
184  dul::StateMachine _state_machine;
185 
186  std::string _peer_host;
187  uint16_t _peer_port;
188 
189  AssociationParameters _association_parameters;
190  AssociationParameters _negotiated_parameters;
191 
192  std::map<std::string, std::pair<uint8_t, std::string>>
193  _transfer_syntaxes_by_abstract_syntax;
194  std::map<uint8_t, std::string> _transfer_syntaxes_by_id;
195 
196  uint16_t _next_message_id;
197 };
198 
204 {
205 public:
207  : Exception("Association released")
208  {
209  // Nothing else.
210  }
211 };
212 
218 {
219 public:
221  uint8_t source;
222 
224  uint8_t reason;
225 
227  AssociationAborted(unsigned char source, unsigned char reason)
228  : Exception("Association aborted"), source(source), reason(reason)
229  {
230  // Nothing else.
231  }
232 };
233 
234 }
235 
236 #endif // _a52696bc_5c6e_402d_a343_6cb085eb0138
void set_tcp_timeout(duration_type const &duration)
Set the timeout.
Definition: Association.cpp:175
message::Message receive_message()
Receive a generic DIMSE message.
Definition: Association.cpp:356
void set_peer_port(uint16_t port)
Set the port of the peer.
Definition: Association.cpp:118
void associate()
Request an association with the peer.
Definition: Association.cpp:203
Association & operator=(Association const &other)
Assing an un-associated association; it remains un-associated.
Definition: Association.cpp:78
uint16_t get_peer_port() const
Return the port of the peer. Defaults to 104.
Definition: Association.cpp:111
Exception reported when receiving a message after the association was released.
Definition: Association.h:203
dul::Transport & get_transport()
Return the TCP transport.
Definition: Association.cpp:71
void set_peer_host(std::string const &host)
Set the host name of the peer.
Definition: Association.cpp:99
Base class for odil exceptions.
Definition: Exception.h:19
~Association()
Destroy the association, release it if necessary.
Definition: Association.cpp:64
Definition: Association.cpp:39
duration_type get_message_timeout() const
Return the DIMSE timeout, default to 30s.
Definition: Association.cpp:182
void abort(int source, int reason)
Forcefully release the association. Throws an exception if not associated.
Definition: Association.cpp:341
AssociationParameters const & get_negotiated_parameters() const
Return the negotiated association parameters.
Definition: Association.cpp:161
ResultSource
Source of association result (PS 3.8, 7.1.1.8 and PS 3.8, 9.3.4).
Definition: Association.h:41
uint16_t next_message_id()
Return the next available message id.
Definition: Association.cpp:529
Encapsulate association parameters.
Definition: AssociationParameters.h:23
Result
Association result (ITU-T X.227, PS 3.8, 7.1.1.7 and PS 3.8, 9.3.4).
Definition: Association.h:33
AssociationParameters & update_parameters()
Return the association parameters.
Definition: Association.cpp:137
Exception reported when receiving a message after the association was aborted.
Definition: Association.h:217
bool is_associated() const
Test whether the object is currently associated to its peer.
Definition: Association.cpp:196
void release()
Gracefully release the association. Throws an exception if not associated.
Definition: Association.cpp:319
duration_type get_tcp_timeout() const
Return the TCP timeout, default to infinity.
Definition: Association.cpp:168
Diagnostic
Diagnostic of association result.
Definition: Association.h:52
dul::StateMachine::duration_type duration_type
Duration of the timeout.
Definition: Association.h:78
AssociationAborted(unsigned char source, unsigned char reason)
Constructor.
Definition: Association.h:227
uint8_t reason
Reason of the error.
Definition: Association.h:224
AssociationParameters const & get_parameters() const
Return the association parameters.
Definition: Association.cpp:130
Association.
Definition: Association.h:29
Association()
Create a default, un-associated, association.
Definition: Association.cpp:43
uint8_t source
Source of the error.
Definition: Association.h:221
std::string const & get_peer_host() const
Return the host name of the peer. Defaults to "".
Definition: Association.cpp:92
void set_message_timeout(duration_type const &duration)
Set the DIMSE timeout.
Definition: Association.cpp:189
void reject(Result result, ResultSource result_source, Diagnostic diagnostic)
Reject the received association request.
void set_parameters(AssociationParameters const &value)
Set the association parameters, throw an exception when associated.
Definition: Association.cpp:149
void receive_association(boost::asio::ip::tcp const &protocol, unsigned short port, AssociationAcceptor acceptor=default_association_acceptor)
Receive an association from a peer.
Definition: Association.cpp:264
void send_message(message::Message const &message, std::string const &abstract_syntax)
Send a DIMSE message.
Definition: Association.cpp:446