Chris@16
|
1 //
|
Chris@16
|
2 // detail/handler_tracking.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
|
Chris@16
|
12 #define BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
|
Chris@16
|
21 # include <boost/system/error_code.hpp>
|
Chris@16
|
22 # include <boost/asio/detail/cstdint.hpp>
|
Chris@16
|
23 # include <boost/asio/detail/static_mutex.hpp>
|
Chris@16
|
24 # include <boost/asio/detail/tss_ptr.hpp>
|
Chris@16
|
25 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost {
|
Chris@16
|
30 namespace asio {
|
Chris@16
|
31 namespace detail {
|
Chris@16
|
32
|
Chris@16
|
33 #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
|
Chris@16
|
34
|
Chris@16
|
35 class handler_tracking
|
Chris@16
|
36 {
|
Chris@16
|
37 public:
|
Chris@16
|
38 class completion;
|
Chris@16
|
39
|
Chris@16
|
40 // Base class for objects containing tracked handlers.
|
Chris@16
|
41 class tracked_handler
|
Chris@16
|
42 {
|
Chris@16
|
43 private:
|
Chris@16
|
44 // Only the handler_tracking class will have access to the id.
|
Chris@16
|
45 friend class handler_tracking;
|
Chris@16
|
46 friend class completion;
|
Chris@16
|
47 uint64_t id_;
|
Chris@16
|
48
|
Chris@16
|
49 protected:
|
Chris@16
|
50 // Constructor initialises with no id.
|
Chris@16
|
51 tracked_handler() : id_(0) {}
|
Chris@16
|
52
|
Chris@16
|
53 // Prevent deletion through this type.
|
Chris@16
|
54 ~tracked_handler() {}
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 // Initialise the tracking system.
|
Chris@16
|
58 BOOST_ASIO_DECL static void init();
|
Chris@16
|
59
|
Chris@16
|
60 // Record the creation of a tracked handler.
|
Chris@16
|
61 BOOST_ASIO_DECL static void creation(tracked_handler* h,
|
Chris@16
|
62 const char* object_type, void* object, const char* op_name);
|
Chris@16
|
63
|
Chris@16
|
64 class completion
|
Chris@16
|
65 {
|
Chris@16
|
66 public:
|
Chris@16
|
67 // Constructor records that handler is to be invoked with no arguments.
|
Chris@16
|
68 BOOST_ASIO_DECL explicit completion(tracked_handler* h);
|
Chris@16
|
69
|
Chris@16
|
70 // Destructor records only when an exception is thrown from the handler, or
|
Chris@16
|
71 // if the memory is being freed without the handler having been invoked.
|
Chris@16
|
72 BOOST_ASIO_DECL ~completion();
|
Chris@16
|
73
|
Chris@16
|
74 // Records that handler is to be invoked with no arguments.
|
Chris@16
|
75 BOOST_ASIO_DECL void invocation_begin();
|
Chris@16
|
76
|
Chris@16
|
77 // Records that handler is to be invoked with one arguments.
|
Chris@16
|
78 BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec);
|
Chris@16
|
79
|
Chris@16
|
80 // Constructor records that handler is to be invoked with two arguments.
|
Chris@16
|
81 BOOST_ASIO_DECL void invocation_begin(
|
Chris@16
|
82 const boost::system::error_code& ec, std::size_t bytes_transferred);
|
Chris@16
|
83
|
Chris@16
|
84 // Constructor records that handler is to be invoked with two arguments.
|
Chris@16
|
85 BOOST_ASIO_DECL void invocation_begin(
|
Chris@16
|
86 const boost::system::error_code& ec, int signal_number);
|
Chris@16
|
87
|
Chris@16
|
88 // Constructor records that handler is to be invoked with two arguments.
|
Chris@16
|
89 BOOST_ASIO_DECL void invocation_begin(
|
Chris@16
|
90 const boost::system::error_code& ec, const char* arg);
|
Chris@16
|
91
|
Chris@16
|
92 // Record that handler invocation has ended.
|
Chris@16
|
93 BOOST_ASIO_DECL void invocation_end();
|
Chris@16
|
94
|
Chris@16
|
95 private:
|
Chris@16
|
96 friend class handler_tracking;
|
Chris@16
|
97 uint64_t id_;
|
Chris@16
|
98 bool invoked_;
|
Chris@16
|
99 completion* next_;
|
Chris@16
|
100 };
|
Chris@16
|
101
|
Chris@16
|
102 // Record an operation that affects pending handlers.
|
Chris@16
|
103 BOOST_ASIO_DECL static void operation(const char* object_type,
|
Chris@16
|
104 void* object, const char* op_name);
|
Chris@16
|
105
|
Chris@16
|
106 // Write a line of output.
|
Chris@16
|
107 BOOST_ASIO_DECL static void write_line(const char* format, ...);
|
Chris@16
|
108
|
Chris@16
|
109 private:
|
Chris@16
|
110 struct tracking_state;
|
Chris@16
|
111 BOOST_ASIO_DECL static tracking_state* get_state();
|
Chris@16
|
112 };
|
Chris@16
|
113
|
Chris@16
|
114 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER \
|
Chris@16
|
115 : public boost::asio::detail::handler_tracking::tracked_handler
|
Chris@16
|
116
|
Chris@16
|
117 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \
|
Chris@16
|
118 , public boost::asio::detail::handler_tracking::tracked_handler
|
Chris@16
|
119
|
Chris@16
|
120 # define BOOST_ASIO_HANDLER_TRACKING_INIT \
|
Chris@16
|
121 boost::asio::detail::handler_tracking::init()
|
Chris@16
|
122
|
Chris@16
|
123 # define BOOST_ASIO_HANDLER_CREATION(args) \
|
Chris@16
|
124 boost::asio::detail::handler_tracking::creation args
|
Chris@16
|
125
|
Chris@16
|
126 # define BOOST_ASIO_HANDLER_COMPLETION(args) \
|
Chris@16
|
127 boost::asio::detail::handler_tracking::completion tracked_completion args
|
Chris@16
|
128
|
Chris@16
|
129 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \
|
Chris@16
|
130 tracked_completion.invocation_begin args
|
Chris@16
|
131
|
Chris@16
|
132 # define BOOST_ASIO_HANDLER_INVOCATION_END \
|
Chris@16
|
133 tracked_completion.invocation_end()
|
Chris@16
|
134
|
Chris@16
|
135 # define BOOST_ASIO_HANDLER_OPERATION(args) \
|
Chris@16
|
136 boost::asio::detail::handler_tracking::operation args
|
Chris@16
|
137
|
Chris@16
|
138 #else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
|
Chris@16
|
139
|
Chris@16
|
140 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER
|
Chris@16
|
141 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
|
Chris@16
|
142 # define BOOST_ASIO_HANDLER_TRACKING_INIT (void)0
|
Chris@16
|
143 # define BOOST_ASIO_HANDLER_CREATION(args) (void)0
|
Chris@16
|
144 # define BOOST_ASIO_HANDLER_COMPLETION(args) (void)0
|
Chris@16
|
145 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
|
Chris@16
|
146 # define BOOST_ASIO_HANDLER_INVOCATION_END (void)0
|
Chris@16
|
147 # define BOOST_ASIO_HANDLER_OPERATION(args) (void)0
|
Chris@16
|
148
|
Chris@16
|
149 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
|
Chris@16
|
150
|
Chris@16
|
151 } // namespace detail
|
Chris@16
|
152 } // namespace asio
|
Chris@16
|
153 } // namespace boost
|
Chris@16
|
154
|
Chris@16
|
155 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
156
|
Chris@16
|
157 #if defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
158 # include <boost/asio/detail/impl/handler_tracking.ipp>
|
Chris@16
|
159 #endif // defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
160
|
Chris@16
|
161 #endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
|