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 
34 {
36  typedef boost::asio::ip::tcp::socket Socket;
37 
39  typedef boost::asio::deadline_timer::duration_type duration_type;
40 
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 
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
Definition: Association.h:25
#define ODIL_API
Definition: odil.h:28
TCP transport for the DICOM Upper Layer.
Definition: Transport.h:34
boost::asio::deadline_timer::duration_type duration_type
Duration of the timeout.
Definition: Transport.h:39
~Transport()
Destructor.
boost::asio::io_service & get_service()
Return the io_service.
std::shared_ptr< Socket > get_socket()
Return the socket.
duration_type get_timeout() const
Return the timeout, default to infinity.
boost::asio::io_service const & get_service() const
Return the io_service.
bool is_open() const
Test whether the transport is open.
void receive(Socket::endpoint_type const &endpoint)
Receive a connection on the specified endpoint, raise an exception upon error.
std::string read(std::size_t length)
Read data, raise an exception on error.
void close()
Close the connection.
Transport()
Constructor.
boost::asio::ip::tcp::socket Socket
Socket type.
Definition: Transport.h:36
void connect(Socket::endpoint_type const &peer_endpoint)
Connect to the specified endpoint, raise an exception upon error.
std::shared_ptr< Socket const > get_socket() const
Return the socket.
void write(std::string const &data)
Write data, raise an exception on error.
void set_timeout(duration_type timeout)
Set the timeout.