Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / service_registry.hpp @ 2486

History | View | Annotate | Download (4.8 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/service_registry.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <typeinfo>
20 2486 sjacqu01
#include <boost/asio/detail/mutex.hpp>
21 2486 sjacqu01
#include <boost/asio/detail/noncopyable.hpp>
22 2486 sjacqu01
#include <boost/asio/io_service.hpp>
23 2486 sjacqu01
24 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
25 2486 sjacqu01
26 2486 sjacqu01
namespace boost {
27 2486 sjacqu01
namespace asio {
28 2486 sjacqu01
namespace detail {
29 2486 sjacqu01
30 2486 sjacqu01
template <typename T>
31 2486 sjacqu01
class typeid_wrapper {};
32 2486 sjacqu01
33 2486 sjacqu01
class service_registry
34 2486 sjacqu01
  : private noncopyable
35 2486 sjacqu01
{
36 2486 sjacqu01
public:
37 2486 sjacqu01
  // Constructor. Adds the initial service.
38 2486 sjacqu01
  template <typename Service, typename Arg>
39 2486 sjacqu01
  service_registry(boost::asio::io_service& o,
40 2486 sjacqu01
      Service* initial_service, Arg arg);
41 2486 sjacqu01
42 2486 sjacqu01
  // Destructor.
43 2486 sjacqu01
  BOOST_ASIO_DECL ~service_registry();
44 2486 sjacqu01
45 2486 sjacqu01
  // Notify all services of a fork event.
46 2486 sjacqu01
  BOOST_ASIO_DECL void notify_fork(boost::asio::io_service::fork_event fork_ev);
47 2486 sjacqu01
48 2486 sjacqu01
  // Get the first service object cast to the specified type. Called during
49 2486 sjacqu01
  // io_service construction and so performs no locking or type checking.
50 2486 sjacqu01
  template <typename Service>
51 2486 sjacqu01
  Service& first_service();
52 2486 sjacqu01
53 2486 sjacqu01
  // Get the service object corresponding to the specified service type. Will
54 2486 sjacqu01
  // create a new service object automatically if no such object already
55 2486 sjacqu01
  // exists. Ownership of the service object is not transferred to the caller.
56 2486 sjacqu01
  template <typename Service>
57 2486 sjacqu01
  Service& use_service();
58 2486 sjacqu01
59 2486 sjacqu01
  // Add a service object. Throws on error, in which case ownership of the
60 2486 sjacqu01
  // object is retained by the caller.
61 2486 sjacqu01
  template <typename Service>
62 2486 sjacqu01
  void add_service(Service* new_service);
63 2486 sjacqu01
64 2486 sjacqu01
  // Check whether a service object of the specified type already exists.
65 2486 sjacqu01
  template <typename Service>
66 2486 sjacqu01
  bool has_service() const;
67 2486 sjacqu01
68 2486 sjacqu01
private:
69 2486 sjacqu01
  // Initialise a service's key based on its id.
70 2486 sjacqu01
  BOOST_ASIO_DECL static void init_key(
71 2486 sjacqu01
      boost::asio::io_service::service::key& key,
72 2486 sjacqu01
      const boost::asio::io_service::id& id);
73 2486 sjacqu01
74 2486 sjacqu01
#if !defined(BOOST_ASIO_NO_TYPEID)
75 2486 sjacqu01
  // Initialise a service's key based on its id.
76 2486 sjacqu01
  template <typename Service>
77 2486 sjacqu01
  static void init_key(boost::asio::io_service::service::key& key,
78 2486 sjacqu01
      const boost::asio::detail::service_id<Service>& /*id*/);
79 2486 sjacqu01
#endif // !defined(BOOST_ASIO_NO_TYPEID)
80 2486 sjacqu01
81 2486 sjacqu01
  // Check if a service matches the given id.
82 2486 sjacqu01
  BOOST_ASIO_DECL static bool keys_match(
83 2486 sjacqu01
      const boost::asio::io_service::service::key& key1,
84 2486 sjacqu01
      const boost::asio::io_service::service::key& key2);
85 2486 sjacqu01
86 2486 sjacqu01
  // The type of a factory function used for creating a service instance.
87 2486 sjacqu01
  typedef boost::asio::io_service::service*
88 2486 sjacqu01
    (*factory_type)(boost::asio::io_service&);
89 2486 sjacqu01
90 2486 sjacqu01
  // Factory function for creating a service instance.
91 2486 sjacqu01
  template <typename Service>
92 2486 sjacqu01
  static boost::asio::io_service::service* create(
93 2486 sjacqu01
      boost::asio::io_service& owner);
94 2486 sjacqu01
95 2486 sjacqu01
  // Destroy a service instance.
96 2486 sjacqu01
  BOOST_ASIO_DECL static void destroy(
97 2486 sjacqu01
      boost::asio::io_service::service* service);
98 2486 sjacqu01
99 2486 sjacqu01
  // Helper class to manage service pointers.
100 2486 sjacqu01
  struct auto_service_ptr;
101 2486 sjacqu01
  friend struct auto_service_ptr;
102 2486 sjacqu01
  struct auto_service_ptr
103 2486 sjacqu01
  {
104 2486 sjacqu01
    boost::asio::io_service::service* ptr_;
105 2486 sjacqu01
    ~auto_service_ptr() { destroy(ptr_); }
106 2486 sjacqu01
  };
107 2486 sjacqu01
108 2486 sjacqu01
  // Get the service object corresponding to the specified service key. Will
109 2486 sjacqu01
  // create a new service object automatically if no such object already
110 2486 sjacqu01
  // exists. Ownership of the service object is not transferred to the caller.
111 2486 sjacqu01
  BOOST_ASIO_DECL boost::asio::io_service::service* do_use_service(
112 2486 sjacqu01
      const boost::asio::io_service::service::key& key,
113 2486 sjacqu01
      factory_type factory);
114 2486 sjacqu01
115 2486 sjacqu01
  // Add a service object. Throws on error, in which case ownership of the
116 2486 sjacqu01
  // object is retained by the caller.
117 2486 sjacqu01
  BOOST_ASIO_DECL void do_add_service(
118 2486 sjacqu01
      const boost::asio::io_service::service::key& key,
119 2486 sjacqu01
      boost::asio::io_service::service* new_service);
120 2486 sjacqu01
121 2486 sjacqu01
  // Check whether a service object with the specified key already exists.
122 2486 sjacqu01
  BOOST_ASIO_DECL bool do_has_service(
123 2486 sjacqu01
      const boost::asio::io_service::service::key& key) const;
124 2486 sjacqu01
125 2486 sjacqu01
  // Mutex to protect access to internal data.
126 2486 sjacqu01
  mutable boost::asio::detail::mutex mutex_;
127 2486 sjacqu01
128 2486 sjacqu01
  // The owner of this service registry and the services it contains.
129 2486 sjacqu01
  boost::asio::io_service& owner_;
130 2486 sjacqu01
131 2486 sjacqu01
  // The first service in the list of contained services.
132 2486 sjacqu01
  boost::asio::io_service::service* first_service_;
133 2486 sjacqu01
};
134 2486 sjacqu01
135 2486 sjacqu01
} // namespace detail
136 2486 sjacqu01
} // namespace asio
137 2486 sjacqu01
} // namespace boost
138 2486 sjacqu01
139 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
140 2486 sjacqu01
141 2486 sjacqu01
#include <boost/asio/detail/impl/service_registry.hpp>
142 2486 sjacqu01
#if defined(BOOST_ASIO_HEADER_ONLY)
143 2486 sjacqu01
# include <boost/asio/detail/impl/service_registry.ipp>
144 2486 sjacqu01
#endif // defined(BOOST_ASIO_HEADER_ONLY)
145 2486 sjacqu01
146 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_SERVICE_REGISTRY_HPP