Imported Upstream version 1.49.0
[platform/upstream/boost.git] / boost / asio / ip / resolver_service.hpp
1 //
2 // ip/resolver_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2012 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_IP_RESOLVER_SERVICE_HPP
12 #define BOOST_ASIO_IP_RESOLVER_SERVICE_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 <boost/system/error_code.hpp>
20 #include <boost/asio/detail/resolver_service.hpp>
21 #include <boost/asio/io_service.hpp>
22 #include <boost/asio/ip/basic_resolver_iterator.hpp>
23 #include <boost/asio/ip/basic_resolver_query.hpp>
24
25 #include <boost/asio/detail/push_options.hpp>
26
27 namespace boost {
28 namespace asio {
29 namespace ip {
30
31 /// Default service implementation for a resolver.
32 template <typename InternetProtocol>
33 class resolver_service
34 #if defined(GENERATING_DOCUMENTATION)
35   : public boost::asio::io_service::service
36 #else
37   : public boost::asio::detail::service_base<
38       resolver_service<InternetProtocol> >
39 #endif
40 {
41 public:
42 #if defined(GENERATING_DOCUMENTATION)
43   /// The unique service identifier.
44   static boost::asio::io_service::id id;
45 #endif
46
47   /// The protocol type.
48   typedef InternetProtocol protocol_type;
49
50   /// The endpoint type.
51   typedef typename InternetProtocol::endpoint endpoint_type;
52
53   /// The query type.
54   typedef basic_resolver_query<InternetProtocol> query_type;
55
56   /// The iterator type.
57   typedef basic_resolver_iterator<InternetProtocol> iterator_type;
58
59 private:
60   // The type of the platform-specific implementation.
61   typedef boost::asio::detail::resolver_service<InternetProtocol>
62     service_impl_type;
63
64 public:
65   /// The type of a resolver implementation.
66 #if defined(GENERATING_DOCUMENTATION)
67   typedef implementation_defined implementation_type;
68 #else
69   typedef typename service_impl_type::implementation_type implementation_type;
70 #endif
71
72   /// Construct a new resolver service for the specified io_service.
73   explicit resolver_service(boost::asio::io_service& io_service)
74     : boost::asio::detail::service_base<
75         resolver_service<InternetProtocol> >(io_service),
76       service_impl_(io_service)
77   {
78   }
79
80   /// Construct a new resolver implementation.
81   void construct(implementation_type& impl)
82   {
83     service_impl_.construct(impl);
84   }
85
86   /// Destroy a resolver implementation.
87   void destroy(implementation_type& impl)
88   {
89     service_impl_.destroy(impl);
90   }
91
92   /// Cancel pending asynchronous operations.
93   void cancel(implementation_type& impl)
94   {
95     service_impl_.cancel(impl);
96   }
97
98   /// Resolve a query to a list of entries.
99   iterator_type resolve(implementation_type& impl, const query_type& query,
100       boost::system::error_code& ec)
101   {
102     return service_impl_.resolve(impl, query, ec);
103   }
104
105   /// Asynchronously resolve a query to a list of entries.
106   template <typename ResolveHandler>
107   void async_resolve(implementation_type& impl, const query_type& query,
108       BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
109   {
110     service_impl_.async_resolve(impl, query,
111         BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
112   }
113
114   /// Resolve an endpoint to a list of entries.
115   iterator_type resolve(implementation_type& impl,
116       const endpoint_type& endpoint, boost::system::error_code& ec)
117   {
118     return service_impl_.resolve(impl, endpoint, ec);
119   }
120
121   /// Asynchronously resolve an endpoint to a list of entries.
122   template <typename ResolveHandler>
123   void async_resolve(implementation_type& impl, const endpoint_type& endpoint,
124       BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
125   {
126     return service_impl_.async_resolve(impl, endpoint,
127         BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
128   }
129
130 private:
131   // Destroy all user-defined handler objects owned by the service.
132   void shutdown_service()
133   {
134     service_impl_.shutdown_service();
135   }
136
137   // Perform any fork-related housekeeping.
138   void fork_service(boost::asio::io_service::fork_event event)
139   {
140     service_impl_.fork_service(event);
141   }
142
143   // The platform-specific implementation.
144   service_impl_type service_impl_;
145 };
146
147 } // namespace ip
148 } // namespace asio
149 } // namespace boost
150
151 #include <boost/asio/detail/pop_options.hpp>
152
153 #endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP