PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/asio/detail/handler_tracking.hpp

http://hadesmem.googlecode.com/
C++ Header | 161 lines | 95 code | 40 blank | 26 comment | 1 complexity | bcc31529bef30990343df11c5df2c1a3 MD5 | raw file
  1//
  2// detail/handler_tracking.hpp
  3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4//
  5// Copyright (c) 2003-2011 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 BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
 12#define BOOST_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 <boost/asio/detail/config.hpp>
 19
 20#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
 21# include <boost/cstdint.hpp>
 22# include <boost/system/error_code.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)
 26
 27#include <boost/asio/detail/push_options.hpp>
 28
 29namespace boost {
 30namespace asio {
 31namespace detail {
 32
 33#if defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
 34
 35class handler_tracking
 36{
 37public:
 38  class completion;
 39
 40  // Base class for objects containing tracked handlers.
 41  class tracked_handler
 42  {
 43  private:
 44    // Only the handler_tracking class will have access to the id.
 45    friend class handler_tracking;
 46    friend class completion;
 47    boost::uint64_t id_;
 48
 49  protected:
 50    // Constructor initialises with no id.
 51    tracked_handler() : id_(0) {}
 52
 53    // Prevent deletion through this type.
 54    ~tracked_handler() {}
 55  };
 56
 57  // Initialise the tracking system.
 58  BOOST_ASIO_DECL static void init();
 59
 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);
 63
 64  class completion
 65  {
 66  public:
 67    // Constructor records that handler is to be invoked with no arguments.
 68    BOOST_ASIO_DECL explicit completion(tracked_handler* h);
 69
 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();
 73
 74    // Records that handler is to be invoked with no arguments.
 75    BOOST_ASIO_DECL void invocation_begin();
 76
 77    // Records that handler is to be invoked with one arguments.
 78    BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec);
 79
 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);
 83
 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);
 87
 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);
 91
 92    // Record that handler invocation has ended.
 93    BOOST_ASIO_DECL void invocation_end();
 94
 95  private:
 96    friend class handler_tracking;
 97    boost::uint64_t id_;
 98    bool invoked_;
 99    completion* next_;
100  };
101
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);
105
106  // Write a line of output.
107  BOOST_ASIO_DECL static void write_line(const char* format, ...);
108
109private:
110  struct tracking_state;
111  BOOST_ASIO_DECL static tracking_state* get_state();
112};
113
114# define BOOST_ASIO_INHERIT_TRACKED_HANDLER \
115  : public boost::asio::detail::handler_tracking::tracked_handler
116
117# define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \
118  , public boost::asio::detail::handler_tracking::tracked_handler
119
120# define BOOST_ASIO_HANDLER_TRACKING_INIT \
121  boost::asio::detail::handler_tracking::init()
122
123# define BOOST_ASIO_HANDLER_CREATION(args) \
124  boost::asio::detail::handler_tracking::creation args
125
126# define BOOST_ASIO_HANDLER_COMPLETION(args) \
127  boost::asio::detail::handler_tracking::completion tracked_completion args
128
129# define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \
130  tracked_completion.invocation_begin args
131
132# define BOOST_ASIO_HANDLER_INVOCATION_END \
133  tracked_completion.invocation_end()
134
135# define BOOST_ASIO_HANDLER_OPERATION(args) \
136  boost::asio::detail::handler_tracking::operation args
137
138#else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
139
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
148
149#endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
150
151} // namespace detail
152} // namespace asio
153} // namespace boost
154
155#include <boost/asio/detail/pop_options.hpp>
156
157#if defined(BOOST_ASIO_HEADER_ONLY)
158# include <boost/asio/detail/impl/handler_tracking.ipp>
159#endif // defined(BOOST_ASIO_HEADER_ONLY)
160
161#endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP