PageRenderTime 103ms CodeModel.GetById 94ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

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