Realistic 3D camera system
3D camera system components
handler_tracking.hpp
Go to the documentation of this file.
1 //
2 // detail/handler_tracking.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_HANDLER_TRACKING_HPP
12 #define ASIO_DETAIL_HANDLER_TRACKING_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_ENABLE_HANDLER_TRACKING)
21 # include "asio/error_code.hpp"
22 # include "asio/detail/cstdint.hpp"
24 # include "asio/detail/tss_ptr.hpp"
25 #endif // defined(ASIO_ENABLE_HANDLER_TRACKING)
26 
28 
29 namespace asio {
30 namespace detail {
31 
32 #if defined(ASIO_ENABLE_HANDLER_TRACKING)
33 
34 class handler_tracking
35 {
36 public:
37  class completion;
38 
39  // Base class for objects containing tracked handlers.
40  class tracked_handler
41  {
42  private:
43  // Only the handler_tracking class will have access to the id.
44  friend class handler_tracking;
45  friend class completion;
46  uint64_t id_;
47 
48  protected:
49  // Constructor initialises with no id.
50  tracked_handler() : id_(0) {}
51 
52  // Prevent deletion through this type.
53  ~tracked_handler() {}
54  };
55 
56  // Initialise the tracking system.
57  ASIO_DECL static void init();
58 
59  // Record the creation of a tracked handler.
60  ASIO_DECL static void creation(tracked_handler* h,
61  const char* object_type, void* object, const char* op_name);
62 
63  class completion
64  {
65  public:
66  // Constructor records that handler is to be invoked with no arguments.
67  ASIO_DECL explicit completion(tracked_handler* h);
68 
69  // Destructor records only when an exception is thrown from the handler, or
70  // if the memory is being freed without the handler having been invoked.
71  ASIO_DECL ~completion();
72 
73  // Records that handler is to be invoked with no arguments.
74  ASIO_DECL void invocation_begin();
75 
76  // Records that handler is to be invoked with one arguments.
77  ASIO_DECL void invocation_begin(const asio::error_code& ec);
78 
79  // Constructor records that handler is to be invoked with two arguments.
80  ASIO_DECL void invocation_begin(
81  const asio::error_code& ec, std::size_t bytes_transferred);
82 
83  // Constructor records that handler is to be invoked with two arguments.
84  ASIO_DECL void invocation_begin(
85  const asio::error_code& ec, int signal_number);
86 
87  // Constructor records that handler is to be invoked with two arguments.
88  ASIO_DECL void invocation_begin(
89  const asio::error_code& ec, const char* arg);
90 
91  // Record that handler invocation has ended.
92  ASIO_DECL void invocation_end();
93 
94  private:
95  friend class handler_tracking;
96  uint64_t id_;
97  bool invoked_;
98  completion* next_;
99  };
100 
101  // Record an operation that affects pending handlers.
102  ASIO_DECL static void operation(const char* object_type,
103  void* object, const char* op_name);
104 
105  // Write a line of output.
106  ASIO_DECL static void write_line(const char* format, ...);
107 
108 private:
109  struct tracking_state;
110  ASIO_DECL static tracking_state* get_state();
111 };
112 
113 # define ASIO_INHERIT_TRACKED_HANDLER \
114  : public asio::detail::handler_tracking::tracked_handler
115 
116 # define ASIO_ALSO_INHERIT_TRACKED_HANDLER \
117  , public asio::detail::handler_tracking::tracked_handler
118 
119 # define ASIO_HANDLER_TRACKING_INIT \
120  asio::detail::handler_tracking::init()
121 
122 # define ASIO_HANDLER_CREATION(args) \
123  asio::detail::handler_tracking::creation args
124 
125 # define ASIO_HANDLER_COMPLETION(args) \
126  asio::detail::handler_tracking::completion tracked_completion args
127 
128 # define ASIO_HANDLER_INVOCATION_BEGIN(args) \
129  tracked_completion.invocation_begin args
130 
131 # define ASIO_HANDLER_INVOCATION_END \
132  tracked_completion.invocation_end()
133 
134 # define ASIO_HANDLER_OPERATION(args) \
135  asio::detail::handler_tracking::operation args
136 
137 #else // defined(ASIO_ENABLE_HANDLER_TRACKING)
138 
139 # define ASIO_INHERIT_TRACKED_HANDLER
140 # define ASIO_ALSO_INHERIT_TRACKED_HANDLER
141 # define ASIO_HANDLER_TRACKING_INIT (void)0
142 # define ASIO_HANDLER_CREATION(args) (void)0
143 # define ASIO_HANDLER_COMPLETION(args) (void)0
144 # define ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
145 # define ASIO_HANDLER_INVOCATION_END (void)0
146 # define ASIO_HANDLER_OPERATION(args) (void)0
147 
148 #endif // defined(ASIO_ENABLE_HANDLER_TRACKING)
149 
150 } // namespace detail
151 } // namespace asio
152 
154 
155 #if defined(ASIO_HEADER_ONLY)
157 #endif // defined(ASIO_HEADER_ONLY)
158 
159 #endif // ASIO_DETAIL_HANDLER_TRACKING_HPP
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))
Class to represent an error code value.
Definition: error_code.hpp:80
#define ASIO_DECL
Definition: config.hpp:43
task_io_service_operation operation
Definition: operation.hpp:32