2 // detail/handler_tracking.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
12 #define BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
23 class execution_context;
28 #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING)
29 # include BOOST_ASIO_CUSTOM_HANDLER_TRACKING
30 #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
31 # include <boost/system/error_code.hpp>
32 # include <boost/asio/detail/cstdint.hpp>
33 # include <boost/asio/detail/static_mutex.hpp>
34 # include <boost/asio/detail/tss_ptr.hpp>
35 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
37 #include <boost/asio/detail/push_options.hpp>
43 #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING)
45 // The user-specified header must define the following macros:
46 // - BOOST_ASIO_INHERIT_TRACKED_HANDLER
47 // - BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
48 // - BOOST_ASIO_HANDLER_TRACKING_INIT
49 // - BOOST_ASIO_HANDLER_CREATION(args)
50 // - BOOST_ASIO_HANDLER_COMPLETION(args)
51 // - BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args)
52 // - BOOST_ASIO_HANDLER_INVOCATION_END
53 // - BOOST_ASIO_HANDLER_OPERATION(args)
54 // - BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args)
55 // - BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args)
56 // - BOOST_ASIO_HANDLER_REACTOR_READ_EVENT
57 // - BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT
58 // - BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT
59 // - BOOST_ASIO_HANDLER_REACTOR_EVENTS(args)
60 // - BOOST_ASIO_HANDLER_REACTOR_OPERATION(args)
62 # if !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
63 # define BOOST_ASIO_ENABLE_HANDLER_TRACKING 1
64 # endif /// !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
66 #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
68 class handler_tracking
73 // Base class for objects containing tracked handlers.
77 // Only the handler_tracking class will have access to the id.
78 friend class handler_tracking;
79 friend class completion;
83 // Constructor initialises with no id.
84 tracked_handler() : id_(0) {}
86 // Prevent deletion through this type.
90 // Initialise the tracking system.
91 BOOST_ASIO_DECL static void init();
93 // Record the creation of a tracked handler.
94 BOOST_ASIO_DECL static void creation(
95 execution_context& context, tracked_handler& h,
96 const char* object_type, void* object,
97 uintmax_t native_handle, const char* op_name);
102 // Constructor records that handler is to be invoked with no arguments.
103 BOOST_ASIO_DECL explicit completion(const tracked_handler& h);
105 // Destructor records only when an exception is thrown from the handler, or
106 // if the memory is being freed without the handler having been invoked.
107 BOOST_ASIO_DECL ~completion();
109 // Records that handler is to be invoked with no arguments.
110 BOOST_ASIO_DECL void invocation_begin();
112 // Records that handler is to be invoked with one arguments.
113 BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec);
115 // Constructor records that handler is to be invoked with two arguments.
116 BOOST_ASIO_DECL void invocation_begin(
117 const boost::system::error_code& ec, std::size_t bytes_transferred);
119 // Constructor records that handler is to be invoked with two arguments.
120 BOOST_ASIO_DECL void invocation_begin(
121 const boost::system::error_code& ec, int signal_number);
123 // Constructor records that handler is to be invoked with two arguments.
124 BOOST_ASIO_DECL void invocation_begin(
125 const boost::system::error_code& ec, const char* arg);
127 // Record that handler invocation has ended.
128 BOOST_ASIO_DECL void invocation_end();
131 friend class handler_tracking;
137 // Record an operation that is not directly associated with a handler.
138 BOOST_ASIO_DECL static void operation(execution_context& context,
139 const char* object_type, void* object,
140 uintmax_t native_handle, const char* op_name);
142 // Record that a descriptor has been registered with the reactor.
143 BOOST_ASIO_DECL static void reactor_registration(execution_context& context,
144 uintmax_t native_handle, uintmax_t registration);
146 // Record that a descriptor has been deregistered from the reactor.
147 BOOST_ASIO_DECL static void reactor_deregistration(execution_context& context,
148 uintmax_t native_handle, uintmax_t registration);
150 // Record a reactor-based operation that is associated with a handler.
151 BOOST_ASIO_DECL static void reactor_events(execution_context& context,
152 uintmax_t registration, unsigned events);
154 // Record a reactor-based operation that is associated with a handler.
155 BOOST_ASIO_DECL static void reactor_operation(
156 const tracked_handler& h, const char* op_name,
157 const boost::system::error_code& ec);
159 // Record a reactor-based operation that is associated with a handler.
160 BOOST_ASIO_DECL static void reactor_operation(
161 const tracked_handler& h, const char* op_name,
162 const boost::system::error_code& ec, std::size_t bytes_transferred);
164 // Write a line of output.
165 BOOST_ASIO_DECL static void write_line(const char* format, ...);
168 struct tracking_state;
169 BOOST_ASIO_DECL static tracking_state* get_state();
172 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER \
173 : public boost::asio::detail::handler_tracking::tracked_handler
175 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \
176 , public boost::asio::detail::handler_tracking::tracked_handler
178 # define BOOST_ASIO_HANDLER_TRACKING_INIT \
179 boost::asio::detail::handler_tracking::init()
181 # define BOOST_ASIO_HANDLER_CREATION(args) \
182 boost::asio::detail::handler_tracking::creation args
184 # define BOOST_ASIO_HANDLER_COMPLETION(args) \
185 boost::asio::detail::handler_tracking::completion tracked_completion args
187 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \
188 tracked_completion.invocation_begin args
190 # define BOOST_ASIO_HANDLER_INVOCATION_END \
191 tracked_completion.invocation_end()
193 # define BOOST_ASIO_HANDLER_OPERATION(args) \
194 boost::asio::detail::handler_tracking::operation args
196 # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) \
197 boost::asio::detail::handler_tracking::reactor_registration args
199 # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) \
200 boost::asio::detail::handler_tracking::reactor_deregistration args
202 # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 1
203 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 2
204 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 4
206 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) \
207 boost::asio::detail::handler_tracking::reactor_events args
209 # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) \
210 boost::asio::detail::handler_tracking::reactor_operation args
212 #else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
214 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER
215 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
216 # define BOOST_ASIO_HANDLER_TRACKING_INIT (void)0
217 # define BOOST_ASIO_HANDLER_CREATION(args) (void)0
218 # define BOOST_ASIO_HANDLER_COMPLETION(args) (void)0
219 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
220 # define BOOST_ASIO_HANDLER_INVOCATION_END (void)0
221 # define BOOST_ASIO_HANDLER_OPERATION(args) (void)0
222 # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) (void)0
223 # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) (void)0
224 # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 0
225 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 0
226 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 0
227 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) (void)0
228 # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) (void)0
230 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
232 } // namespace detail
236 #include <boost/asio/detail/pop_options.hpp>
238 #if defined(BOOST_ASIO_HEADER_ONLY)
239 # include <boost/asio/detail/impl/handler_tracking.ipp>
240 #endif // defined(BOOST_ASIO_HEADER_ONLY)
242 #endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP