1 //
2 // signal_set_service.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 BOOST_ASIO_SIGNAL_SET_SERVICE_HPP
12 #define BOOST_ASIO_SIGNAL_SET_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/asio/async_result.hpp>
20 #include <boost/asio/detail/signal_set_service.hpp>
21 #include <boost/asio/error.hpp>
22 #include <boost/asio/io_service.hpp>
23 
24 #include <boost/asio/detail/push_options.hpp>
25 
26 namespace boost {
27 namespace asio {
28 
29 /// Default service implementation for a signal set.
30 class signal_set_service
31 #if defined(GENERATING_DOCUMENTATION)
32   : public boost::asio::io_service::service
33 #else
34   : public boost::asio::detail::service_base<signal_set_service>
35 #endif
36 {
37 public:
38 #if defined(GENERATING_DOCUMENTATION)
39   /// The unique service identifier.
40   static boost::asio::io_service::id id;
41 #endif
42 
43 public:
44   /// The type of a signal set implementation.
45 #if defined(GENERATING_DOCUMENTATION)
46   typedef implementation_defined implementation_type;
47 #else
48   typedef detail::signal_set_service::implementation_type implementation_type;
49 #endif
50 
51   /// Construct a new signal set service for the specified io_service.
signal_set_service(boost::asio::io_service & io_service)52   explicit signal_set_service(boost::asio::io_service& io_service)
53     : boost::asio::detail::service_base<signal_set_service>(io_service),
54       service_impl_(io_service)
55   {
56   }
57 
58   /// Construct a new signal set implementation.
construct(implementation_type & impl)59   void construct(implementation_type& impl)
60   {
61     service_impl_.construct(impl);
62   }
63 
64   /// Destroy a signal set implementation.
destroy(implementation_type & impl)65   void destroy(implementation_type& impl)
66   {
67     service_impl_.destroy(impl);
68   }
69 
70   /// Add a signal to a signal_set.
add(implementation_type & impl,int signal_number,boost::system::error_code & ec)71   boost::system::error_code add(implementation_type& impl,
72       int signal_number, boost::system::error_code& ec)
73   {
74     return service_impl_.add(impl, signal_number, ec);
75   }
76 
77   /// Remove a signal to a signal_set.
remove(implementation_type & impl,int signal_number,boost::system::error_code & ec)78   boost::system::error_code remove(implementation_type& impl,
79       int signal_number, boost::system::error_code& ec)
80   {
81     return service_impl_.remove(impl, signal_number, ec);
82   }
83 
84   /// Remove all signals from a signal_set.
clear(implementation_type & impl,boost::system::error_code & ec)85   boost::system::error_code clear(implementation_type& impl,
86       boost::system::error_code& ec)
87   {
88     return service_impl_.clear(impl, ec);
89   }
90 
91   /// Cancel all operations associated with the signal set.
cancel(implementation_type & impl,boost::system::error_code & ec)92   boost::system::error_code cancel(implementation_type& impl,
93       boost::system::error_code& ec)
94   {
95     return service_impl_.cancel(impl, ec);
96   }
97 
98   // Start an asynchronous operation to wait for a signal to be delivered.
99   template <typename SignalHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler,void (boost::system::error_code,int))100   BOOST_ASIO_INITFN_RESULT_TYPE(SignalHandler,
101       void (boost::system::error_code, int))
102   async_wait(implementation_type& impl,
103       BOOST_ASIO_MOVE_ARG(SignalHandler) handler)
104   {
105     detail::async_result_init<
106       SignalHandler, void (boost::system::error_code, int)> init(
107         BOOST_ASIO_MOVE_CAST(SignalHandler)(handler));
108 
109     service_impl_.async_wait(impl, init.handler);
110 
111     return init.result.get();
112   }
113 
114 private:
115   // Destroy all user-defined handler objects owned by the service.
shutdown_service()116   void shutdown_service()
117   {
118     service_impl_.shutdown_service();
119   }
120 
121   // Perform any fork-related housekeeping.
fork_service(boost::asio::io_service::fork_event event)122   void fork_service(boost::asio::io_service::fork_event event)
123   {
124     service_impl_.fork_service(event);
125   }
126 
127   // The platform-specific implementation.
128   detail::signal_set_service service_impl_;
129 };
130 
131 } // namespace asio
132 } // namespace boost
133 
134 #include <boost/asio/detail/pop_options.hpp>
135 
136 #endif // BOOST_ASIO_SIGNAL_SET_SERVICE_HPP
137