Realistic 3D camera system
3D camera system components
serial_port_service.hpp
Go to the documentation of this file.
1 //
2 // serial_port_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_SERIAL_PORT_SERVICE_HPP
12 #define ASIO_SERIAL_PORT_SERVICE_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if defined(ASIO_HAS_SERIAL_PORT) \
21  || defined(GENERATING_DOCUMENTATION)
22 
23 #include <cstddef>
24 #include <string>
25 #include "asio/async_result.hpp"
28 #include "asio/error.hpp"
29 #include "asio/io_service.hpp"
31 
33 
34 namespace asio {
35 
37 class serial_port_service
38 #if defined(GENERATING_DOCUMENTATION)
40 #else
41  : public asio::detail::service_base<serial_port_service>
42 #endif
43 {
44 public:
45 #if defined(GENERATING_DOCUMENTATION)
46  static asio::io_service::id id;
48 #endif
49 
50 private:
51  // The type of the platform-specific implementation.
52 #if defined(ASIO_HAS_IOCP)
53  typedef detail::win_iocp_serial_port_service service_impl_type;
54 #else
55  typedef detail::reactive_serial_port_service service_impl_type;
56 #endif
57 
58 public:
60 #if defined(GENERATING_DOCUMENTATION)
61  typedef implementation_defined implementation_type;
62 #else
63  typedef service_impl_type::implementation_type implementation_type;
64 #endif
65 
67 #if defined(GENERATING_DOCUMENTATION)
68  typedef implementation_defined native_type;
69 #else
70  typedef service_impl_type::native_handle_type native_type;
71 #endif
72 
74 #if defined(GENERATING_DOCUMENTATION)
75  typedef implementation_defined native_handle_type;
76 #else
77  typedef service_impl_type::native_handle_type native_handle_type;
78 #endif
79 
81  explicit serial_port_service(asio::io_service& io_service)
82  : asio::detail::service_base<serial_port_service>(io_service),
83  service_impl_(io_service)
84  {
85  }
86 
88  void construct(implementation_type& impl)
89  {
90  service_impl_.construct(impl);
91  }
92 
93 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
94  void move_construct(implementation_type& impl,
96  implementation_type& other_impl)
97  {
98  service_impl_.move_construct(impl, other_impl);
99  }
100 
102  void move_assign(implementation_type& impl,
103  serial_port_service& other_service,
104  implementation_type& other_impl)
105  {
106  service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
107  }
108 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
109 
111  void destroy(implementation_type& impl)
112  {
113  service_impl_.destroy(impl);
114  }
115 
117  asio::error_code open(implementation_type& impl,
118  const std::string& device, asio::error_code& ec)
119  {
120  return service_impl_.open(impl, device, ec);
121  }
122 
124  asio::error_code assign(implementation_type& impl,
125  const native_handle_type& handle, asio::error_code& ec)
126  {
127  return service_impl_.assign(impl, handle, ec);
128  }
129 
131  bool is_open(const implementation_type& impl) const
132  {
133  return service_impl_.is_open(impl);
134  }
135 
137  asio::error_code close(implementation_type& impl,
138  asio::error_code& ec)
139  {
140  return service_impl_.close(impl, ec);
141  }
142 
144  native_type native(implementation_type& impl)
145  {
146  return service_impl_.native_handle(impl);
147  }
148 
150  native_handle_type native_handle(implementation_type& impl)
151  {
152  return service_impl_.native_handle(impl);
153  }
154 
156  asio::error_code cancel(implementation_type& impl,
157  asio::error_code& ec)
158  {
159  return service_impl_.cancel(impl, ec);
160  }
161 
163  template <typename SettableSerialPortOption>
164  asio::error_code set_option(implementation_type& impl,
165  const SettableSerialPortOption& option, asio::error_code& ec)
166  {
167  return service_impl_.set_option(impl, option, ec);
168  }
169 
171  template <typename GettableSerialPortOption>
172  asio::error_code get_option(const implementation_type& impl,
173  GettableSerialPortOption& option, asio::error_code& ec) const
174  {
175  return service_impl_.get_option(impl, option, ec);
176  }
177 
179  asio::error_code send_break(implementation_type& impl,
180  asio::error_code& ec)
181  {
182  return service_impl_.send_break(impl, ec);
183  }
184 
186  template <typename ConstBufferSequence>
187  std::size_t write_some(implementation_type& impl,
188  const ConstBufferSequence& buffers, asio::error_code& ec)
189  {
190  return service_impl_.write_some(impl, buffers, ec);
191  }
192 
194  template <typename ConstBufferSequence, typename WriteHandler>
195  ASIO_INITFN_RESULT_TYPE(WriteHandler,
196  void (asio::error_code, std::size_t))
197  async_write_some(implementation_type& impl,
198  const ConstBufferSequence& buffers,
199  ASIO_MOVE_ARG(WriteHandler) handler)
200  {
201  detail::async_result_init<
202  WriteHandler, void (asio::error_code, std::size_t)> init(
203  ASIO_MOVE_CAST(WriteHandler)(handler));
204 
205  service_impl_.async_write_some(impl, buffers, init.handler);
206 
207  return init.result.get();
208  }
209 
211  template <typename MutableBufferSequence>
212  std::size_t read_some(implementation_type& impl,
213  const MutableBufferSequence& buffers, asio::error_code& ec)
214  {
215  return service_impl_.read_some(impl, buffers, ec);
216  }
217 
219  template <typename MutableBufferSequence, typename ReadHandler>
220  ASIO_INITFN_RESULT_TYPE(ReadHandler,
221  void (asio::error_code, std::size_t))
222  async_read_some(implementation_type& impl,
223  const MutableBufferSequence& buffers,
224  ASIO_MOVE_ARG(ReadHandler) handler)
225  {
226  detail::async_result_init<
227  ReadHandler, void (asio::error_code, std::size_t)> init(
228  ASIO_MOVE_CAST(ReadHandler)(handler));
229 
230  service_impl_.async_read_some(impl, buffers, init.handler);
231 
232  return init.result.get();
233  }
234 
235 private:
236  // Destroy all user-defined handler objects owned by the service.
237  void shutdown_service()
238  {
239  service_impl_.shutdown_service();
240  }
241 
242  // The platform-specific implementation.
243  service_impl_type service_impl_;
244 };
245 
246 } // namespace asio
247 
249 
250 #endif // defined(ASIO_HAS_SERIAL_PORT)
251  // || defined(GENERATING_DOCUMENTATION)
252 
253 #endif // ASIO_SERIAL_PORT_SERVICE_HPP
Class used to uniquely identify a service.
Definition: io_service.hpp:665
Provides core I/O functionality.
Definition: io_service.hpp:184
asio::basic_streambuf< Allocator > MatchCondition enable_if< is_match_condition< MatchCondition >::value >::type *detail::async_result_init< ReadHandler, void(asio::error_code, std::size_t)> init(ASIO_MOVE_CAST(ReadHandler)(handler))
ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler, void(asio::error_code, Iterator)) async_connect(basic_socket< Protocol
const MutableBufferSequence & buffers
Definition: read.hpp:521
asio::basic_streambuf< Allocator > CompletionCondition ASIO_MOVE_ARG(ReadHandler) handler)
Definition: read.hpp:704
Class to represent an error code value.
Definition: error_code.hpp:80
ASIO_DECL int close(int d, state_type &state, asio::error_code &ec)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
Base class for all io_service services.
Definition: io_service.hpp:674
ASIO_DECL int open(const char *path, int flags, asio::error_code &ec)