summaryrefslogtreecommitdiff
path: root/boost/asio/detail/service_registry.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/asio/detail/service_registry.hpp')
-rw-r--r--boost/asio/detail/service_registry.hpp86
1 files changed, 53 insertions, 33 deletions
diff --git a/boost/asio/detail/service_registry.hpp b/boost/asio/detail/service_registry.hpp
index b5fa85bd01..7218848e4c 100644
--- a/boost/asio/detail/service_registry.hpp
+++ b/boost/asio/detail/service_registry.hpp
@@ -19,12 +19,16 @@
#include <typeinfo>
#include <boost/asio/detail/mutex.hpp>
#include <boost/asio/detail/noncopyable.hpp>
-#include <boost/asio/io_service.hpp>
+#include <boost/asio/detail/type_traits.hpp>
+#include <boost/asio/execution_context.hpp>
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
+
+class io_context;
+
namespace detail {
template <typename T>
@@ -34,27 +38,34 @@ class service_registry
: private noncopyable
{
public:
- // Constructor. Adds the initial service.
- template <typename Service, typename Arg>
- service_registry(boost::asio::io_service& o,
- Service* initial_service, Arg arg);
+ // Constructor.
+ BOOST_ASIO_DECL service_registry(execution_context& owner);
// Destructor.
BOOST_ASIO_DECL ~service_registry();
+ // Shutdown all services.
+ BOOST_ASIO_DECL void shutdown_services();
+
+ // Destroy all services.
+ BOOST_ASIO_DECL void destroy_services();
+
// Notify all services of a fork event.
- BOOST_ASIO_DECL void notify_fork(boost::asio::io_service::fork_event fork_ev);
+ BOOST_ASIO_DECL void notify_fork(execution_context::fork_event fork_ev);
- // Get the first service object cast to the specified type. Called during
- // io_service construction and so performs no locking or type checking.
+ // Get the service object corresponding to the specified service type. Will
+ // create a new service object automatically if no such object already
+ // exists. Ownership of the service object is not transferred to the caller.
template <typename Service>
- Service& first_service();
+ Service& use_service();
// Get the service object corresponding to the specified service type. Will
// create a new service object automatically if no such object already
// exists. Ownership of the service object is not transferred to the caller.
+ // This overload is used for backwards compatibility with services that
+ // inherit from io_context::service.
template <typename Service>
- Service& use_service();
+ Service& use_service(io_context& owner);
// Add a service object. Throws on error, in which case ownership of the
// object is retained by the caller.
@@ -66,70 +77,79 @@ public:
bool has_service() const;
private:
+ // Initalise a service's key when the key_type typedef is not available.
+ template <typename Service>
+ static void init_key(execution_context::service::key& key, ...);
+
+#if !defined(BOOST_ASIO_NO_TYPEID)
+ // Initalise a service's key when the key_type typedef is available.
+ template <typename Service>
+ static void init_key(execution_context::service::key& key,
+ typename enable_if<
+ is_base_of<typename Service::key_type, Service>::value>::type*);
+#endif // !defined(BOOST_ASIO_NO_TYPEID)
+
// Initialise a service's key based on its id.
- BOOST_ASIO_DECL static void init_key(
- boost::asio::io_service::service::key& key,
- const boost::asio::io_service::id& id);
+ BOOST_ASIO_DECL static void init_key_from_id(
+ execution_context::service::key& key,
+ const execution_context::id& id);
#if !defined(BOOST_ASIO_NO_TYPEID)
// Initialise a service's key based on its id.
template <typename Service>
- static void init_key(boost::asio::io_service::service::key& key,
- const boost::asio::detail::service_id<Service>& /*id*/);
+ static void init_key_from_id(execution_context::service::key& key,
+ const service_id<Service>& /*id*/);
#endif // !defined(BOOST_ASIO_NO_TYPEID)
// Check if a service matches the given id.
BOOST_ASIO_DECL static bool keys_match(
- const boost::asio::io_service::service::key& key1,
- const boost::asio::io_service::service::key& key2);
+ const execution_context::service::key& key1,
+ const execution_context::service::key& key2);
// The type of a factory function used for creating a service instance.
- typedef boost::asio::io_service::service*
- (*factory_type)(boost::asio::io_service&);
+ typedef execution_context::service*(*factory_type)(void*);
// Factory function for creating a service instance.
- template <typename Service>
- static boost::asio::io_service::service* create(
- boost::asio::io_service& owner);
+ template <typename Service, typename Owner>
+ static execution_context::service* create(void* owner);
// Destroy a service instance.
- BOOST_ASIO_DECL static void destroy(
- boost::asio::io_service::service* service);
+ BOOST_ASIO_DECL static void destroy(execution_context::service* service);
// Helper class to manage service pointers.
struct auto_service_ptr;
friend struct auto_service_ptr;
struct auto_service_ptr
{
- boost::asio::io_service::service* ptr_;
+ execution_context::service* ptr_;
~auto_service_ptr() { destroy(ptr_); }
};
// Get the service object corresponding to the specified service key. Will
// create a new service object automatically if no such object already
// exists. Ownership of the service object is not transferred to the caller.
- BOOST_ASIO_DECL boost::asio::io_service::service* do_use_service(
- const boost::asio::io_service::service::key& key,
- factory_type factory);
+ BOOST_ASIO_DECL execution_context::service* do_use_service(
+ const execution_context::service::key& key,
+ factory_type factory, void* owner);
// Add a service object. Throws on error, in which case ownership of the
// object is retained by the caller.
BOOST_ASIO_DECL void do_add_service(
- const boost::asio::io_service::service::key& key,
- boost::asio::io_service::service* new_service);
+ const execution_context::service::key& key,
+ execution_context::service* new_service);
// Check whether a service object with the specified key already exists.
BOOST_ASIO_DECL bool do_has_service(
- const boost::asio::io_service::service::key& key) const;
+ const execution_context::service::key& key) const;
// Mutex to protect access to internal data.
mutable boost::asio::detail::mutex mutex_;
// The owner of this service registry and the services it contains.
- boost::asio::io_service& owner_;
+ execution_context& owner_;
// The first service in the list of contained services.
- boost::asio::io_service::service* first_service_;
+ execution_context::service* first_service_;
};
} // namespace detail