Realistic 3D camera system
3D camera system components
service_registry.hpp
Go to the documentation of this file.
1 //
2 // detail/service_registry.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_DETAIL_SERVICE_REGISTRY_HPP
12 #define 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 "asio/detail/config.hpp"
19 #include <typeinfo>
20 #include "asio/detail/mutex.hpp"
22 #include "asio/io_service.hpp"
23 
25 
26 namespace asio {
27 namespace detail {
28 
29 template <typename T>
30 class typeid_wrapper {};
31 
33  : private noncopyable
34 {
35 public:
36  // Constructor. Adds the initial service.
37  template <typename Service, typename Arg>
39  Service* initial_service, Arg arg);
40 
41  // Destructor.
43 
44  // Notify all services of a fork event.
45  ASIO_DECL void notify_fork(asio::io_service::fork_event fork_ev);
46 
47  // Get the first service object cast to the specified type. Called during
48  // io_service construction and so performs no locking or type checking.
49  template <typename Service>
50  Service& first_service();
51 
52  // Get the service object corresponding to the specified service type. Will
53  // create a new service object automatically if no such object already
54  // exists. Ownership of the service object is not transferred to the caller.
55  template <typename Service>
56  Service& use_service();
57 
58  // Add a service object. Throws on error, in which case ownership of the
59  // object is retained by the caller.
60  template <typename Service>
61  void add_service(Service* new_service);
62 
63  // Check whether a service object of the specified type already exists.
64  template <typename Service>
65  bool has_service() const;
66 
67 private:
68  // Initialise a service's key based on its id.
69  ASIO_DECL static void init_key(
70  asio::io_service::service::key& key,
71  const asio::io_service::id& id);
72 
73 #if !defined(ASIO_NO_TYPEID)
74  // Initialise a service's key based on its id.
75  template <typename Service>
76  static void init_key(asio::io_service::service::key& key,
77  const asio::detail::service_id<Service>& /*id*/);
78 #endif // !defined(ASIO_NO_TYPEID)
79 
80  // Check if a service matches the given id.
81  ASIO_DECL static bool keys_match(
82  const asio::io_service::service::key& key1,
83  const asio::io_service::service::key& key2);
84 
85  // The type of a factory function used for creating a service instance.
87  (*factory_type)(asio::io_service&);
88 
89  // Factory function for creating a service instance.
90  template <typename Service>
91  static asio::io_service::service* create(
92  asio::io_service& owner);
93 
94  // Destroy a service instance.
95  ASIO_DECL static void destroy(
96  asio::io_service::service* service);
97 
98  // Helper class to manage service pointers.
99  struct auto_service_ptr;
100  friend struct auto_service_ptr;
101  struct auto_service_ptr
102  {
104  ~auto_service_ptr() { destroy(ptr_); }
105  };
106 
107  // Get the service object corresponding to the specified service key. Will
108  // create a new service object automatically if no such object already
109  // exists. Ownership of the service object is not transferred to the caller.
110  ASIO_DECL asio::io_service::service* do_use_service(
111  const asio::io_service::service::key& key,
112  factory_type factory);
113 
114  // Add a service object. Throws on error, in which case ownership of the
115  // object is retained by the caller.
116  ASIO_DECL void do_add_service(
117  const asio::io_service::service::key& key,
118  asio::io_service::service* new_service);
119 
120  // Check whether a service object with the specified key already exists.
121  ASIO_DECL bool do_has_service(
122  const asio::io_service::service::key& key) const;
123 
124  // Mutex to protect access to internal data.
125  mutable asio::detail::mutex mutex_;
126 
127  // The owner of this service registry and the services it contains.
128  asio::io_service& owner_;
129 
130  // The first service in the list of contained services.
131  asio::io_service::service* first_service_;
132 };
133 
134 } // namespace detail
135 } // namespace asio
136 
138 
140 #if defined(ASIO_HEADER_ONLY)
142 #endif // defined(ASIO_HEADER_ONLY)
143 
144 #endif // ASIO_DETAIL_SERVICE_REGISTRY_HPP
Class used to uniquely identify a service.
Definition: io_service.hpp:665
Provides core I/O functionality.
Definition: io_service.hpp:184
Service & use_service(io_service &ios)
Definition: io_service.hpp:26
void add_service(io_service &ios, Service *svc)
Definition: io_service.hpp:43
fork_event
Fork-related event notifications.
Definition: io_service.hpp:501
#define ASIO_DECL
Definition: config.hpp:43
bool has_service(io_service &ios)
Definition: io_service.hpp:53
Base class for all io_service services.
Definition: io_service.hpp:674