Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

handler_tracking.hpp 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // detail/handler_tracking.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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. #ifndef ASIO_DETAIL_HANDLER_TRACKING_HPP
  11. #define ASIO_DETAIL_HANDLER_TRACKING_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. namespace asio {
  17. class execution_context;
  18. } // namespace asio
  19. #if defined(ASIO_CUSTOM_HANDLER_TRACKING)
  20. # include ASIO_CUSTOM_HANDLER_TRACKING
  21. #elif defined(ASIO_ENABLE_HANDLER_TRACKING)
  22. # include "asio/error_code.hpp"
  23. # include "asio/detail/cstdint.hpp"
  24. # include "asio/detail/static_mutex.hpp"
  25. # include "asio/detail/tss_ptr.hpp"
  26. #endif // defined(ASIO_ENABLE_HANDLER_TRACKING)
  27. #include "asio/detail/push_options.hpp"
  28. namespace asio {
  29. namespace detail {
  30. #if defined(ASIO_CUSTOM_HANDLER_TRACKING)
  31. // The user-specified header must define the following macros:
  32. // - ASIO_INHERIT_TRACKED_HANDLER
  33. // - ASIO_ALSO_INHERIT_TRACKED_HANDLER
  34. // - ASIO_HANDLER_TRACKING_INIT
  35. // - ASIO_HANDLER_CREATION(args)
  36. // - ASIO_HANDLER_COMPLETION(args)
  37. // - ASIO_HANDLER_INVOCATION_BEGIN(args)
  38. // - ASIO_HANDLER_INVOCATION_END
  39. // - ASIO_HANDLER_OPERATION(args)
  40. // - ASIO_HANDLER_REACTOR_REGISTRATION(args)
  41. // - ASIO_HANDLER_REACTOR_DEREGISTRATION(args)
  42. // - ASIO_HANDLER_REACTOR_READ_EVENT
  43. // - ASIO_HANDLER_REACTOR_WRITE_EVENT
  44. // - ASIO_HANDLER_REACTOR_ERROR_EVENT
  45. // - ASIO_HANDLER_REACTOR_EVENTS(args)
  46. // - ASIO_HANDLER_REACTOR_OPERATION(args)
  47. # if !defined(ASIO_ENABLE_HANDLER_TRACKING)
  48. # define ASIO_ENABLE_HANDLER_TRACKING 1
  49. # endif /// !defined(ASIO_ENABLE_HANDLER_TRACKING)
  50. #elif defined(ASIO_ENABLE_HANDLER_TRACKING)
  51. class handler_tracking
  52. {
  53. public:
  54. class completion;
  55. // Base class for objects containing tracked handlers.
  56. class tracked_handler
  57. {
  58. private:
  59. // Only the handler_tracking class will have access to the id.
  60. friend class handler_tracking;
  61. friend class completion;
  62. uint64_t id_;
  63. protected:
  64. // Constructor initialises with no id.
  65. tracked_handler() : id_(0) {}
  66. // Prevent deletion through this type.
  67. ~tracked_handler() {}
  68. };
  69. // Initialise the tracking system.
  70. ASIO_DECL static void init();
  71. // Record the creation of a tracked handler.
  72. ASIO_DECL static void creation(
  73. execution_context& context, tracked_handler& h,
  74. const char* object_type, void* object,
  75. uintmax_t native_handle, const char* op_name);
  76. class completion
  77. {
  78. public:
  79. // Constructor records that handler is to be invoked with no arguments.
  80. ASIO_DECL explicit completion(const tracked_handler& h);
  81. // Destructor records only when an exception is thrown from the handler, or
  82. // if the memory is being freed without the handler having been invoked.
  83. ASIO_DECL ~completion();
  84. // Records that handler is to be invoked with no arguments.
  85. ASIO_DECL void invocation_begin();
  86. // Records that handler is to be invoked with one arguments.
  87. ASIO_DECL void invocation_begin(const asio::error_code& ec);
  88. // Constructor records that handler is to be invoked with two arguments.
  89. ASIO_DECL void invocation_begin(
  90. const asio::error_code& ec, std::size_t bytes_transferred);
  91. // Constructor records that handler is to be invoked with two arguments.
  92. ASIO_DECL void invocation_begin(
  93. const asio::error_code& ec, int signal_number);
  94. // Constructor records that handler is to be invoked with two arguments.
  95. ASIO_DECL void invocation_begin(
  96. const asio::error_code& ec, const char* arg);
  97. // Record that handler invocation has ended.
  98. ASIO_DECL void invocation_end();
  99. private:
  100. friend class handler_tracking;
  101. uint64_t id_;
  102. bool invoked_;
  103. completion* next_;
  104. };
  105. // Record an operation that is not directly associated with a handler.
  106. ASIO_DECL static void operation(execution_context& context,
  107. const char* object_type, void* object,
  108. uintmax_t native_handle, const char* op_name);
  109. // Record that a descriptor has been registered with the reactor.
  110. ASIO_DECL static void reactor_registration(execution_context& context,
  111. uintmax_t native_handle, uintmax_t registration);
  112. // Record that a descriptor has been deregistered from the reactor.
  113. ASIO_DECL static void reactor_deregistration(execution_context& context,
  114. uintmax_t native_handle, uintmax_t registration);
  115. // Record a reactor-based operation that is associated with a handler.
  116. ASIO_DECL static void reactor_events(execution_context& context,
  117. uintmax_t registration, unsigned events);
  118. // Record a reactor-based operation that is associated with a handler.
  119. ASIO_DECL static void reactor_operation(
  120. const tracked_handler& h, const char* op_name,
  121. const asio::error_code& ec);
  122. // Record a reactor-based operation that is associated with a handler.
  123. ASIO_DECL static void reactor_operation(
  124. const tracked_handler& h, const char* op_name,
  125. const asio::error_code& ec, std::size_t bytes_transferred);
  126. // Write a line of output.
  127. ASIO_DECL static void write_line(const char* format, ...);
  128. private:
  129. struct tracking_state;
  130. ASIO_DECL static tracking_state* get_state();
  131. };
  132. # define ASIO_INHERIT_TRACKED_HANDLER \
  133. : public asio::detail::handler_tracking::tracked_handler
  134. # define ASIO_ALSO_INHERIT_TRACKED_HANDLER \
  135. , public asio::detail::handler_tracking::tracked_handler
  136. # define ASIO_HANDLER_TRACKING_INIT \
  137. asio::detail::handler_tracking::init()
  138. # define ASIO_HANDLER_CREATION(args) \
  139. asio::detail::handler_tracking::creation args
  140. # define ASIO_HANDLER_COMPLETION(args) \
  141. asio::detail::handler_tracking::completion tracked_completion args
  142. # define ASIO_HANDLER_INVOCATION_BEGIN(args) \
  143. tracked_completion.invocation_begin args
  144. # define ASIO_HANDLER_INVOCATION_END \
  145. tracked_completion.invocation_end()
  146. # define ASIO_HANDLER_OPERATION(args) \
  147. asio::detail::handler_tracking::operation args
  148. # define ASIO_HANDLER_REACTOR_REGISTRATION(args) \
  149. asio::detail::handler_tracking::reactor_registration args
  150. # define ASIO_HANDLER_REACTOR_DEREGISTRATION(args) \
  151. asio::detail::handler_tracking::reactor_deregistration args
  152. # define ASIO_HANDLER_REACTOR_READ_EVENT 1
  153. # define ASIO_HANDLER_REACTOR_WRITE_EVENT 2
  154. # define ASIO_HANDLER_REACTOR_ERROR_EVENT 4
  155. # define ASIO_HANDLER_REACTOR_EVENTS(args) \
  156. asio::detail::handler_tracking::reactor_events args
  157. # define ASIO_HANDLER_REACTOR_OPERATION(args) \
  158. asio::detail::handler_tracking::reactor_operation args
  159. #else // defined(ASIO_ENABLE_HANDLER_TRACKING)
  160. # define ASIO_INHERIT_TRACKED_HANDLER
  161. # define ASIO_ALSO_INHERIT_TRACKED_HANDLER
  162. # define ASIO_HANDLER_TRACKING_INIT (void)0
  163. # define ASIO_HANDLER_CREATION(args) (void)0
  164. # define ASIO_HANDLER_COMPLETION(args) (void)0
  165. # define ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
  166. # define ASIO_HANDLER_INVOCATION_END (void)0
  167. # define ASIO_HANDLER_OPERATION(args) (void)0
  168. # define ASIO_HANDLER_REACTOR_REGISTRATION(args) (void)0
  169. # define ASIO_HANDLER_REACTOR_DEREGISTRATION(args) (void)0
  170. # define ASIO_HANDLER_REACTOR_READ_EVENT 0
  171. # define ASIO_HANDLER_REACTOR_WRITE_EVENT 0
  172. # define ASIO_HANDLER_REACTOR_ERROR_EVENT 0
  173. # define ASIO_HANDLER_REACTOR_EVENTS(args) (void)0
  174. # define ASIO_HANDLER_REACTOR_OPERATION(args) (void)0
  175. #endif // defined(ASIO_ENABLE_HANDLER_TRACKING)
  176. } // namespace detail
  177. } // namespace asio
  178. #include "asio/detail/pop_options.hpp"
  179. #if defined(ASIO_HEADER_ONLY)
  180. # include "asio/detail/impl/handler_tracking.ipp"
  181. #endif // defined(ASIO_HEADER_ONLY)
  182. #endif // ASIO_DETAIL_HANDLER_TRACKING_HPP