comparison DEPENDENCIES/generic/include/boost/asio/detail/service_registry.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 //
2 // detail/service_registry.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2013 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_SERVICE_REGISTRY_HPP
12 #define BOOST_ASIO_DETAIL_SERVICE_REGISTRY_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 #include <typeinfo>
20 #include <boost/asio/detail/mutex.hpp>
21 #include <boost/asio/detail/noncopyable.hpp>
22 #include <boost/asio/io_service.hpp>
23
24 #include <boost/asio/detail/push_options.hpp>
25
26 namespace boost {
27 namespace asio {
28 namespace detail {
29
30 #if defined(__GNUC__)
31 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
32 # pragma GCC visibility push (default)
33 # endif // (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
34 #endif // defined(__GNUC__)
35
36 template <typename T>
37 class typeid_wrapper {};
38
39 #if defined(__GNUC__)
40 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
41 # pragma GCC visibility pop
42 # endif // (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
43 #endif // defined(__GNUC__)
44
45 class service_registry
46 : private noncopyable
47 {
48 public:
49 // Constructor. Adds the initial service.
50 template <typename Service, typename Arg>
51 service_registry(boost::asio::io_service& o,
52 Service* initial_service, Arg arg);
53
54 // Destructor.
55 BOOST_ASIO_DECL ~service_registry();
56
57 // Notify all services of a fork event.
58 BOOST_ASIO_DECL void notify_fork(boost::asio::io_service::fork_event fork_ev);
59
60 // Get the first service object cast to the specified type. Called during
61 // io_service construction and so performs no locking or type checking.
62 template <typename Service>
63 Service& first_service();
64
65 // Get the service object corresponding to the specified service type. Will
66 // create a new service object automatically if no such object already
67 // exists. Ownership of the service object is not transferred to the caller.
68 template <typename Service>
69 Service& use_service();
70
71 // Add a service object. Throws on error, in which case ownership of the
72 // object is retained by the caller.
73 template <typename Service>
74 void add_service(Service* new_service);
75
76 // Check whether a service object of the specified type already exists.
77 template <typename Service>
78 bool has_service() const;
79
80 private:
81 // Initialise a service's key based on its id.
82 BOOST_ASIO_DECL static void init_key(
83 boost::asio::io_service::service::key& key,
84 const boost::asio::io_service::id& id);
85
86 #if !defined(BOOST_ASIO_NO_TYPEID)
87 // Initialise a service's key based on its id.
88 template <typename Service>
89 static void init_key(boost::asio::io_service::service::key& key,
90 const boost::asio::detail::service_id<Service>& /*id*/);
91 #endif // !defined(BOOST_ASIO_NO_TYPEID)
92
93 // Check if a service matches the given id.
94 BOOST_ASIO_DECL static bool keys_match(
95 const boost::asio::io_service::service::key& key1,
96 const boost::asio::io_service::service::key& key2);
97
98 // The type of a factory function used for creating a service instance.
99 typedef boost::asio::io_service::service*
100 (*factory_type)(boost::asio::io_service&);
101
102 // Factory function for creating a service instance.
103 template <typename Service>
104 static boost::asio::io_service::service* create(
105 boost::asio::io_service& owner);
106
107 // Destroy a service instance.
108 BOOST_ASIO_DECL static void destroy(
109 boost::asio::io_service::service* service);
110
111 // Helper class to manage service pointers.
112 struct auto_service_ptr;
113 friend struct auto_service_ptr;
114 struct auto_service_ptr
115 {
116 boost::asio::io_service::service* ptr_;
117 ~auto_service_ptr() { destroy(ptr_); }
118 };
119
120 // Get the service object corresponding to the specified service key. Will
121 // create a new service object automatically if no such object already
122 // exists. Ownership of the service object is not transferred to the caller.
123 BOOST_ASIO_DECL boost::asio::io_service::service* do_use_service(
124 const boost::asio::io_service::service::key& key,
125 factory_type factory);
126
127 // Add a service object. Throws on error, in which case ownership of the
128 // object is retained by the caller.
129 BOOST_ASIO_DECL void do_add_service(
130 const boost::asio::io_service::service::key& key,
131 boost::asio::io_service::service* new_service);
132
133 // Check whether a service object with the specified key already exists.
134 BOOST_ASIO_DECL bool do_has_service(
135 const boost::asio::io_service::service::key& key) const;
136
137 // Mutex to protect access to internal data.
138 mutable boost::asio::detail::mutex mutex_;
139
140 // The owner of this service registry and the services it contains.
141 boost::asio::io_service& owner_;
142
143 // The first service in the list of contained services.
144 boost::asio::io_service::service* first_service_;
145 };
146
147 } // namespace detail
148 } // namespace asio
149 } // namespace boost
150
151 #include <boost/asio/detail/pop_options.hpp>
152
153 #include <boost/asio/detail/impl/service_registry.hpp>
154 #if defined(BOOST_ASIO_HEADER_ONLY)
155 # include <boost/asio/detail/impl/service_registry.ipp>
156 #endif // defined(BOOST_ASIO_HEADER_ONLY)
157
158 #endif // BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP