1*6a6c8299Sjmmv // Copyright 2012 Google Inc.
2*6a6c8299Sjmmv // All rights reserved.
3*6a6c8299Sjmmv //
4*6a6c8299Sjmmv // Redistribution and use in source and binary forms, with or without
5*6a6c8299Sjmmv // modification, are permitted provided that the following conditions are
6*6a6c8299Sjmmv // met:
7*6a6c8299Sjmmv //
8*6a6c8299Sjmmv // * Redistributions of source code must retain the above copyright
9*6a6c8299Sjmmv //   notice, this list of conditions and the following disclaimer.
10*6a6c8299Sjmmv // * Redistributions in binary form must reproduce the above copyright
11*6a6c8299Sjmmv //   notice, this list of conditions and the following disclaimer in the
12*6a6c8299Sjmmv //   documentation and/or other materials provided with the distribution.
13*6a6c8299Sjmmv // * Neither the name of Google Inc. nor the names of its contributors
14*6a6c8299Sjmmv //   may be used to endorse or promote products derived from this software
15*6a6c8299Sjmmv //   without specific prior written permission.
16*6a6c8299Sjmmv //
17*6a6c8299Sjmmv // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*6a6c8299Sjmmv // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*6a6c8299Sjmmv // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*6a6c8299Sjmmv // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*6a6c8299Sjmmv // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*6a6c8299Sjmmv // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*6a6c8299Sjmmv // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*6a6c8299Sjmmv // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*6a6c8299Sjmmv // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*6a6c8299Sjmmv // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*6a6c8299Sjmmv // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*6a6c8299Sjmmv 
29*6a6c8299Sjmmv /// \file utils/signals/interrupts.hpp
30*6a6c8299Sjmmv /// Handling of interrupts.
31*6a6c8299Sjmmv 
32*6a6c8299Sjmmv #if !defined(UTILS_SIGNALS_INTERRUPTS_HPP)
33*6a6c8299Sjmmv #define UTILS_SIGNALS_INTERRUPTS_HPP
34*6a6c8299Sjmmv 
35*6a6c8299Sjmmv #include <unistd.h>
36*6a6c8299Sjmmv 
37*6a6c8299Sjmmv #include "utils/noncopyable.hpp"
38*6a6c8299Sjmmv 
39*6a6c8299Sjmmv namespace utils {
40*6a6c8299Sjmmv namespace signals {
41*6a6c8299Sjmmv 
42*6a6c8299Sjmmv 
43*6a6c8299Sjmmv /// Provides a scope in which interrupts can be detected and handled.
44*6a6c8299Sjmmv ///
45*6a6c8299Sjmmv /// This RAII-modeled object installs signal handler when instantiated and
46*6a6c8299Sjmmv /// removes them upon destruction.  While this object is active, the
47*6a6c8299Sjmmv /// check_interrupt() free function can be used to determine if an interrupt has
48*6a6c8299Sjmmv /// happened.
49*6a6c8299Sjmmv class interrupts_handler : noncopyable {
50*6a6c8299Sjmmv public:
51*6a6c8299Sjmmv     interrupts_handler(void);
52*6a6c8299Sjmmv     ~interrupts_handler(void);
53*6a6c8299Sjmmv };
54*6a6c8299Sjmmv 
55*6a6c8299Sjmmv 
56*6a6c8299Sjmmv /// Disables interrupts while the object is alive.
57*6a6c8299Sjmmv class interrupts_inhibiter : noncopyable {
58*6a6c8299Sjmmv public:
59*6a6c8299Sjmmv     interrupts_inhibiter(void);
60*6a6c8299Sjmmv     ~interrupts_inhibiter(void);
61*6a6c8299Sjmmv };
62*6a6c8299Sjmmv 
63*6a6c8299Sjmmv 
64*6a6c8299Sjmmv void check_interrupt(void);
65*6a6c8299Sjmmv 
66*6a6c8299Sjmmv void add_pid_to_kill(const pid_t);
67*6a6c8299Sjmmv void remove_pid_to_kill(const pid_t);
68*6a6c8299Sjmmv 
69*6a6c8299Sjmmv 
70*6a6c8299Sjmmv } // namespace signals
71*6a6c8299Sjmmv } // namespace utils
72*6a6c8299Sjmmv 
73*6a6c8299Sjmmv #endif // !defined(UTILS_SIGNALS_INTERRUPTS_HPP)
74