Odil
A C++11 library for the DICOM standard
Association.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 _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 
20 #include "odil/dul/StateMachine.h"
21 #include "odil/message/Message.h"
22 #include "odil/odil.h"
23 
24 namespace odil
25 {
26 
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 
80 
83 
85  Association(Association const & other);
86 
89 
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 
113 
116 
119 
122 
125 
128 
130  void set_tcp_timeout(duration_type const & duration);
131 
134 
136  void set_message_timeout(duration_type const & duration);
137 
139 
142 
144  bool is_associated() const;
145 
147  void associate();
148 
151  boost::asio::ip::tcp const & protocol, unsigned short port,
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  std::shared_ptr<message::Message> receive_message();
174 
177  std::shared_ptr<message::Message const> message,
178  std::string const & abstract_syntax);
179 
181  uint16_t next_message_id();
182 
184 
185 private:
186  dul::StateMachine _state_machine;
187 
188  std::string _peer_host;
189  uint16_t _peer_port;
190 
191  AssociationParameters _association_parameters;
192  AssociationParameters _negotiated_parameters;
193 
194  std::map<std::string, std::pair<uint8_t, std::string>>
195  _transfer_syntaxes_by_abstract_syntax;
196  std::map<uint8_t, std::string> _transfer_syntaxes_by_id;
197 
198  uint16_t _next_message_id;
199 };
200 
206 {
207 public:
209  virtual ~AssociationReleased() noexcept;
210 };
211 
217 {
218 public:
220  uint8_t source;
221 
223  uint8_t reason;
224 
225  AssociationAborted(unsigned char source, unsigned char reason);
226  virtual ~AssociationAborted() noexcept;
227 };
228 
229 }
230 
231 #endif // _a52696bc_5c6e_402d_a343_6cb085eb0138
odil::Association::set_parameters
void set_parameters(AssociationParameters const &value)
Set the association parameters, throw an exception when associated.
odil::Association::duration_type
dul::StateMachine::duration_type duration_type
Duration of the timeout.
Definition: Association.h:79
odil::Association::Association
Association(Association const &other)
Create an un-associated association.
odil::Association::Result
Result
Association result (ITU-T X.227, PS 3.8, 7.1.1.7 and PS 3.8, 9.3.4).
Definition: Association.h:35
odil::dul::StateMachine::duration_type
boost::asio::deadline_timer::duration_type duration_type
Duration of the timeout.
Definition: StateMachine.h:67
odil::Association::get_peer_host
std::string const & get_peer_host() const
Return the host name of the peer. Defaults to "".
odil::AssociationReleased::~AssociationReleased
virtual ~AssociationReleased() noexcept
odil::Association::is_associated
bool is_associated() const
Test whether the object is currently associated to its peer.
odil::AssociationAborted::AssociationAborted
AssociationAborted(unsigned char source, unsigned char reason)
odil
Definition: Association.h:25
ODIL_API
#define ODIL_API
Definition: odil.h:28
odil::Association::release
void release()
Gracefully release the association. Throws an exception if not associated.
odil::Association::reject
void reject(Result result, ResultSource result_source, Diagnostic diagnostic)
Reject the received association request.
odil::Association::set_message_timeout
void set_message_timeout(duration_type const &duration)
Set the DIMSE timeout.
odil::AssociationAborted::source
uint8_t source
Source of the error.
Definition: Association.h:220
odil::Association::get_transport
dul::Transport & get_transport()
Return the TCP transport.
odil::AssociationParameters
Encapsulate association parameters.
Definition: AssociationParameters.h:27
odil::dul::StateMachine
State machine for the DICOM upper layer.
Definition: StateMachine.h:32
odil::Association::Diagnostic
Diagnostic
Diagnostic of association result.
Definition: Association.h:54
Message.h
odil::Exception
Base class for odil exceptions.
Definition: Exception.h:22
odil::AssociationReleased
Exception reported when receiving a message after the association was released.
Definition: Association.h:206
odil::AssociationAborted::reason
uint8_t reason
Reason of the error.
Definition: Association.h:223
odil.h
AssociationParameters.h
odil::Association::get_peer_port
uint16_t get_peer_port() const
Return the port of the peer. Defaults to 104.
odil::Association::set_peer_host
void set_peer_host(std::string const &host)
Set the host name of the peer.
odil::Association::receive_message
std::shared_ptr< message::Message > receive_message()
Receive a generic DIMSE message.
odil::Association::~Association
~Association()
Destroy the association, release it if necessary.
odil::Association::abort
void abort(int source, int reason)
Forcefully release the association. Throws an exception if not associated.
odil::AssociationAcceptor
std::function< AssociationParameters(AssociationParameters const &)> AssociationAcceptor
Callback to check whether the association request is acceptable.
Definition: AssociationAcceptor.h:30
AssociationAcceptor.h
odil::AssociationAborted
Exception reported when receiving a message after the association was aborted.
Definition: Association.h:217
odil::Association::operator=
Association & operator=(Association const &other)
Assing an un-associated association; it remains un-associated.
odil::Association::receive_association
void receive_association(boost::asio::ip::tcp const &protocol, unsigned short port, AssociationAcceptor acceptor=default_association_acceptor)
Receive an association from a peer.
odil::Association::send_message
void send_message(std::shared_ptr< message::Message const > message, std::string const &abstract_syntax)
Send a DIMSE message.
odil::Association::get_parameters
AssociationParameters const & get_parameters() const
Return the association parameters.
odil::Association::set_tcp_timeout
void set_tcp_timeout(duration_type const &duration)
Set the timeout.
odil::AssociationAborted::~AssociationAborted
virtual ~AssociationAborted() noexcept
odil::AssociationReleased::AssociationReleased
AssociationReleased()
odil::default_association_acceptor
AssociationParameters default_association_acceptor(AssociationParameters const &input)
Default association acceptor.
odil::Association
Association.
Definition: Association.h:31
odil::Association::next_message_id
uint16_t next_message_id()
Return the next available message id.
odil::Association::ResultSource
ResultSource
Source of association result (PS 3.8, 7.1.1.8 and PS 3.8, 9.3.4).
Definition: Association.h:43
odil::dul::Transport
TCP transport for the DICOM Upper Layer.
Definition: Transport.h:34
odil::Association::associate
void associate()
Request an association with the peer. Throws an exception if the endpoint can not be reached.
odil::Association::Association
Association()
Create a default, un-associated, association.
odil::Association::update_parameters
AssociationParameters & update_parameters()
Return the association parameters.
odil::Association::get_tcp_timeout
duration_type get_tcp_timeout() const
Return the TCP timeout, default to infinity.
odil::Association::get_negotiated_parameters
AssociationParameters const & get_negotiated_parameters() const
Return the negotiated association parameters.
odil::Association::get_message_timeout
duration_type get_message_timeout() const
Return the DIMSE timeout, default to 30s.
StateMachine.h
odil::Association::set_peer_port
void set_peer_port(uint16_t port)
Set the port of the peer.