Odil
A C++11 library for the DICOM standard
Transport.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 _1619bae8_acba_4bf8_8205_aa8dd0085c66
10 #define _1619bae8_acba_4bf8_8205_aa8dd0085c66
11 
12 #include <memory>
13 #include <string>
14 
15 #include <boost/asio.hpp>
16 #include <boost/date_time.hpp>
17 
18 #include "odil/odil.h"
19 
20 namespace odil
21 {
22 
23 namespace dul
24 {
25 
33 struct ODIL_API Transport
34 {
36  typedef boost::asio::ip::tcp::socket Socket;
37 
39  typedef boost::asio::deadline_timer::duration_type duration_type;
40 
42  Transport();
43 
46 
48  boost::asio::io_service const & get_service() const;
49 
51  boost::asio::io_service & get_service();
52 
54  std::shared_ptr<Socket const> get_socket() const;
55 
57  std::shared_ptr<Socket> get_socket();
58 
60  duration_type get_timeout() const;
61 
63  void set_timeout(duration_type timeout);
64 
66  bool is_open() const;
67 
69  void connect(Socket::endpoint_type const & peer_endpoint);
70 
75  void receive(Socket::endpoint_type const & endpoint);
76 
78  void close();
79 
81  std::string read(std::size_t length);
82 
84  void write(std::string const & data);
85 
86 private:
87  boost::asio::io_service _service;
88  std::shared_ptr<Socket> _socket;
89  duration_type _timeout;
90  boost::asio::deadline_timer _deadline;
91 
92  std::shared_ptr<boost::asio::ip::tcp::acceptor> _acceptor;
93 
94  enum class Source
95  {
96  NONE,
97  TIMER,
98  OPERATION,
99  };
100 
101  void _start_deadline(Source & source, boost::system::error_code & error);
102  void _stop_deadline();
103 
104  void _run(Source & source, boost::system::error_code & error);
105 };
106 
107 }
108 
109 }
110 
111 #endif // _1619bae8_acba_4bf8_8205_aa8dd0085c66
odil::dul::Transport::duration_type
boost::asio::deadline_timer::duration_type duration_type
Duration of the timeout.
Definition: Transport.h:57
odil
Definition: Association.h:24
ODIL_API
#define ODIL_API
Definition: odil.h:28
odil.h
odil::dul::Transport
TCP transport for the DICOM Upper Layer.
Definition: Transport.h:45