Realistic 3D camera system
3D camera system components
completion_handler.hpp
Go to the documentation of this file.
1 //
2 // detail/completion_handler.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_DETAIL_COMPLETION_HANDLER_HPP
12 #define ASIO_DETAIL_COMPLETION_HANDLER_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
19 #include "asio/detail/config.hpp"
24 
26 
27 namespace asio {
28 namespace detail {
29 
30 template <typename Handler>
32 {
33 public:
35 
36  completion_handler(Handler& h)
38  handler_(ASIO_MOVE_CAST(Handler)(h))
39  {
40  }
41 
42  static void do_complete(io_service_impl* owner, operation* base,
43  const asio::error_code& /*ec*/,
44  std::size_t /*bytes_transferred*/)
45  {
46  // Take ownership of the handler object.
47  completion_handler* h(static_cast<completion_handler*>(base));
48  ptr p = { asio::detail::addressof(h->handler_), h, h };
49 
51 
52  // Make a copy of the handler so that the memory can be deallocated before
53  // the upcall is made. Even if we're not about to make an upcall, a
54  // sub-object of the handler may be the true owner of the memory associated
55  // with the handler. Consequently, a local copy of the handler is required
56  // to ensure that any owning sub-object remains valid until after we have
57  // deallocated the memory here.
58  Handler handler(ASIO_MOVE_CAST(Handler)(h->handler_));
59  p.h = asio::detail::addressof(handler);
60  p.reset();
61 
62  // Make the upcall if required.
63  if (owner)
64  {
67  asio_handler_invoke_helpers::invoke(handler, handler);
69  }
70  }
71 
72 private:
73  Handler handler_;
74 };
75 
76 } // namespace detail
77 } // namespace asio
78 
80 
81 #endif // ASIO_DETAIL_COMPLETION_HANDLER_HPP
#define ASIO_HANDLER_INVOCATION_END
static void do_complete(io_service_impl *owner, operation *base, const asio::error_code &, std::size_t)
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
class task_io_service io_service_impl
Definition: io_service.hpp:48
void invoke(Function &function, Context &context)
#define ASIO_HANDLER_INVOCATION_BEGIN(args)
Class to represent an error code value.
Definition: error_code.hpp:80
task_io_service_operation operation
Definition: operation.hpp:32
#define ASIO_HANDLER_COMPLETION(args)
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
ASIO_DEFINE_HANDLER_PTR(completion_handler)