File indexing completed on 2025-01-18 09:28:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP
0012 #define BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <typeinfo>
0020 #include <boost/asio/detail/mutex.hpp>
0021 #include <boost/asio/detail/noncopyable.hpp>
0022 #include <boost/asio/detail/type_traits.hpp>
0023 #include <boost/asio/execution_context.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029
0030 class io_context;
0031
0032 namespace detail {
0033
0034 template <typename T>
0035 class typeid_wrapper {};
0036
0037 class service_registry
0038 : private noncopyable
0039 {
0040 public:
0041
0042 BOOST_ASIO_DECL service_registry(execution_context& owner);
0043
0044
0045 BOOST_ASIO_DECL ~service_registry();
0046
0047
0048 BOOST_ASIO_DECL void shutdown_services();
0049
0050
0051 BOOST_ASIO_DECL void destroy_services();
0052
0053
0054 BOOST_ASIO_DECL void notify_fork(execution_context::fork_event fork_ev);
0055
0056
0057
0058
0059 template <typename Service>
0060 Service& use_service();
0061
0062
0063
0064
0065
0066
0067 template <typename Service>
0068 Service& use_service(io_context& owner);
0069
0070
0071
0072 template <typename Service>
0073 void add_service(Service* new_service);
0074
0075
0076 template <typename Service>
0077 bool has_service() const;
0078
0079 private:
0080
0081 template <typename Service>
0082 static void init_key(execution_context::service::key& key, ...);
0083
0084 #if !defined(BOOST_ASIO_NO_TYPEID)
0085
0086 template <typename Service>
0087 static void init_key(execution_context::service::key& key,
0088 enable_if_t<is_base_of<typename Service::key_type, Service>::value>*);
0089 #endif
0090
0091
0092 BOOST_ASIO_DECL static void init_key_from_id(
0093 execution_context::service::key& key,
0094 const execution_context::id& id);
0095
0096 #if !defined(BOOST_ASIO_NO_TYPEID)
0097
0098 template <typename Service>
0099 static void init_key_from_id(execution_context::service::key& key,
0100 const service_id<Service>& );
0101 #endif
0102
0103
0104 BOOST_ASIO_DECL static bool keys_match(
0105 const execution_context::service::key& key1,
0106 const execution_context::service::key& key2);
0107
0108
0109 typedef execution_context::service*(*factory_type)(void*);
0110
0111
0112 template <typename Service, typename Owner>
0113 static execution_context::service* create(void* owner);
0114
0115
0116 BOOST_ASIO_DECL static void destroy(execution_context::service* service);
0117
0118
0119 struct auto_service_ptr;
0120 friend struct auto_service_ptr;
0121 struct auto_service_ptr
0122 {
0123 execution_context::service* ptr_;
0124 ~auto_service_ptr() { destroy(ptr_); }
0125 };
0126
0127
0128
0129
0130 BOOST_ASIO_DECL execution_context::service* do_use_service(
0131 const execution_context::service::key& key,
0132 factory_type factory, void* owner);
0133
0134
0135
0136 BOOST_ASIO_DECL void do_add_service(
0137 const execution_context::service::key& key,
0138 execution_context::service* new_service);
0139
0140
0141 BOOST_ASIO_DECL bool do_has_service(
0142 const execution_context::service::key& key) const;
0143
0144
0145 mutable boost::asio::detail::mutex mutex_;
0146
0147
0148 execution_context& owner_;
0149
0150
0151 execution_context::service* first_service_;
0152 };
0153
0154 }
0155 }
0156 }
0157
0158 #include <boost/asio/detail/pop_options.hpp>
0159
0160 #include <boost/asio/detail/impl/service_registry.hpp>
0161 #if defined(BOOST_ASIO_HEADER_ONLY)
0162 # include <boost/asio/detail/impl/service_registry.ipp>
0163 #endif
0164
0165 #endif