2 // detail/handler_tracking.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 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>
20 #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
21 # include <boost/system/error_code.hpp>
22 # include <boost/asio/detail/cstdint.hpp>
23 # include <boost/asio/detail/static_mutex.hpp>
24 # include <boost/asio/detail/tss_ptr.hpp>
25 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
27 #include <boost/asio/detail/push_options.hpp>
33 #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
35 class handler_tracking
40 // Base class for objects containing tracked handlers.
44 // Only the handler_tracking class will have access to the id.
45 friend class handler_tracking;
46 friend class completion;
50 // Constructor initialises with no id.
51 tracked_handler() : id_(0) {}
53 // Prevent deletion through this type.
57 // Initialise the tracking system.
58 BOOST_ASIO_DECL static void init();
60 // Record the creation of a tracked handler.
61 BOOST_ASIO_DECL static void creation(tracked_handler* h,
62 const char* object_type, void* object, const char* op_name);
67 // Constructor records that handler is to be invoked with no arguments.
68 BOOST_ASIO_DECL explicit completion(tracked_handler* h);
70 // Destructor records only when an exception is thrown from the handler, or
71 // if the memory is being freed without the handler having been invoked.
72 BOOST_ASIO_DECL ~completion();
74 // Records that handler is to be invoked with no arguments.
75 BOOST_ASIO_DECL void invocation_begin();
77 // Records that handler is to be invoked with one arguments.
78 BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec);
80 // Constructor records that handler is to be invoked with two arguments.
81 BOOST_ASIO_DECL void invocation_begin(
82 const boost::system::error_code& ec, std::size_t bytes_transferred);
84 // Constructor records that handler is to be invoked with two arguments.
85 BOOST_ASIO_DECL void invocation_begin(
86 const boost::system::error_code& ec, int signal_number);
88 // Constructor records that handler is to be invoked with two arguments.
89 BOOST_ASIO_DECL void invocation_begin(
90 const boost::system::error_code& ec, const char* arg);
92 // Record that handler invocation has ended.
93 BOOST_ASIO_DECL void invocation_end();
96 friend class handler_tracking;
102 // Record an operation that affects pending handlers.
103 BOOST_ASIO_DECL static void operation(const char* object_type,
104 void* object, const char* op_name);
106 // Write a line of output.
107 BOOST_ASIO_DECL static void write_line(const char* format, ...);
110 struct tracking_state;
111 BOOST_ASIO_DECL static tracking_state* get_state();
114 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER \
115 : public boost::asio::detail::handler_tracking::tracked_handler
117 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \
118 , public boost::asio::detail::handler_tracking::tracked_handler
120 # define BOOST_ASIO_HANDLER_TRACKING_INIT \
121 boost::asio::detail::handler_tracking::init()
123 # define BOOST_ASIO_HANDLER_CREATION(args) \
124 boost::asio::detail::handler_tracking::creation args
126 # define BOOST_ASIO_HANDLER_COMPLETION(args) \
127 boost::asio::detail::handler_tracking::completion tracked_completion args
129 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \
130 tracked_completion.invocation_begin args
132 # define BOOST_ASIO_HANDLER_INVOCATION_END \
133 tracked_completion.invocation_end()
135 # define BOOST_ASIO_HANDLER_OPERATION(args) \
136 boost::asio::detail::handler_tracking::operation args
138 #else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
140 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER
141 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
142 # define BOOST_ASIO_HANDLER_TRACKING_INIT (void)0
143 # define BOOST_ASIO_HANDLER_CREATION(args) (void)0
144 # define BOOST_ASIO_HANDLER_COMPLETION(args) (void)0
145 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
146 # define BOOST_ASIO_HANDLER_INVOCATION_END (void)0
147 # define BOOST_ASIO_HANDLER_OPERATION(args) (void)0
149 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
151 } // namespace detail
155 #include <boost/asio/detail/pop_options.hpp>
157 #if defined(BOOST_ASIO_HEADER_ONLY)
158 # include <boost/asio/detail/impl/handler_tracking.ipp>
159 #endif // defined(BOOST_ASIO_HEADER_ONLY)
161 #endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP