Chris@16: // Chris@16: // detail/handler_tracking.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP Chris@16: #define BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: Chris@16: #if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) Chris@16: Chris@16: class handler_tracking Chris@16: { Chris@16: public: Chris@16: class completion; Chris@16: Chris@16: // Base class for objects containing tracked handlers. Chris@16: class tracked_handler Chris@16: { Chris@16: private: Chris@16: // Only the handler_tracking class will have access to the id. Chris@16: friend class handler_tracking; Chris@16: friend class completion; Chris@16: uint64_t id_; Chris@16: Chris@16: protected: Chris@16: // Constructor initialises with no id. Chris@16: tracked_handler() : id_(0) {} Chris@16: Chris@16: // Prevent deletion through this type. Chris@16: ~tracked_handler() {} Chris@16: }; Chris@16: Chris@16: // Initialise the tracking system. Chris@16: BOOST_ASIO_DECL static void init(); Chris@16: Chris@16: // Record the creation of a tracked handler. Chris@16: BOOST_ASIO_DECL static void creation(tracked_handler* h, Chris@16: const char* object_type, void* object, const char* op_name); Chris@16: Chris@16: class completion Chris@16: { Chris@16: public: Chris@16: // Constructor records that handler is to be invoked with no arguments. Chris@16: BOOST_ASIO_DECL explicit completion(tracked_handler* h); Chris@16: Chris@16: // Destructor records only when an exception is thrown from the handler, or Chris@16: // if the memory is being freed without the handler having been invoked. Chris@16: BOOST_ASIO_DECL ~completion(); Chris@16: Chris@16: // Records that handler is to be invoked with no arguments. Chris@16: BOOST_ASIO_DECL void invocation_begin(); Chris@16: Chris@16: // Records that handler is to be invoked with one arguments. Chris@16: BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec); Chris@16: Chris@16: // Constructor records that handler is to be invoked with two arguments. Chris@16: BOOST_ASIO_DECL void invocation_begin( Chris@16: const boost::system::error_code& ec, std::size_t bytes_transferred); Chris@16: Chris@16: // Constructor records that handler is to be invoked with two arguments. Chris@16: BOOST_ASIO_DECL void invocation_begin( Chris@16: const boost::system::error_code& ec, int signal_number); Chris@16: Chris@16: // Constructor records that handler is to be invoked with two arguments. Chris@16: BOOST_ASIO_DECL void invocation_begin( Chris@16: const boost::system::error_code& ec, const char* arg); Chris@16: Chris@16: // Record that handler invocation has ended. Chris@16: BOOST_ASIO_DECL void invocation_end(); Chris@16: Chris@16: private: Chris@16: friend class handler_tracking; Chris@16: uint64_t id_; Chris@16: bool invoked_; Chris@16: completion* next_; Chris@16: }; Chris@16: Chris@16: // Record an operation that affects pending handlers. Chris@16: BOOST_ASIO_DECL static void operation(const char* object_type, Chris@16: void* object, const char* op_name); Chris@16: Chris@16: // Write a line of output. Chris@16: BOOST_ASIO_DECL static void write_line(const char* format, ...); Chris@16: Chris@16: private: Chris@16: struct tracking_state; Chris@16: BOOST_ASIO_DECL static tracking_state* get_state(); Chris@16: }; Chris@16: Chris@16: # define BOOST_ASIO_INHERIT_TRACKED_HANDLER \ Chris@16: : public boost::asio::detail::handler_tracking::tracked_handler Chris@16: Chris@16: # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \ Chris@16: , public boost::asio::detail::handler_tracking::tracked_handler Chris@16: Chris@16: # define BOOST_ASIO_HANDLER_TRACKING_INIT \ Chris@16: boost::asio::detail::handler_tracking::init() Chris@16: Chris@16: # define BOOST_ASIO_HANDLER_CREATION(args) \ Chris@16: boost::asio::detail::handler_tracking::creation args Chris@16: Chris@16: # define BOOST_ASIO_HANDLER_COMPLETION(args) \ Chris@16: boost::asio::detail::handler_tracking::completion tracked_completion args Chris@16: Chris@16: # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \ Chris@16: tracked_completion.invocation_begin args Chris@16: Chris@16: # define BOOST_ASIO_HANDLER_INVOCATION_END \ Chris@16: tracked_completion.invocation_end() Chris@16: Chris@16: # define BOOST_ASIO_HANDLER_OPERATION(args) \ Chris@16: boost::asio::detail::handler_tracking::operation args Chris@16: Chris@16: #else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) Chris@16: Chris@16: # define BOOST_ASIO_INHERIT_TRACKED_HANDLER Chris@16: # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER Chris@16: # define BOOST_ASIO_HANDLER_TRACKING_INIT (void)0 Chris@16: # define BOOST_ASIO_HANDLER_CREATION(args) (void)0 Chris@16: # define BOOST_ASIO_HANDLER_COMPLETION(args) (void)0 Chris@16: # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0 Chris@16: # define BOOST_ASIO_HANDLER_INVOCATION_END (void)0 Chris@16: # define BOOST_ASIO_HANDLER_OPERATION(args) (void)0 Chris@16: Chris@16: #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING) Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP