process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
signal.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef CORE_POSIX_SIGNAL_H_
20 #define CORE_POSIX_SIGNAL_H_
21 
22 #include <core/posix/visibility.h>
23 
24 #include <core/signal.h>
25 
26 #include <signal.h>
27 
28 #include <initializer_list>
29 #include <memory>
30 
31 namespace core
32 {
33 namespace posix
34 {
38 enum class Signal
39 {
40  unknown = 0,
41  sig_hup = SIGHUP,
42  sig_int = SIGINT,
43  sig_quit = SIGQUIT,
44  sig_ill = SIGILL,
45  sig_abrt = SIGABRT,
46  sig_fpe = SIGFPE,
47  sig_kill = SIGKILL,
48  sig_segv = SIGSEGV,
49  sig_pipe = SIGPIPE,
50  sig_alrm = SIGALRM,
51  sig_term = SIGTERM,
52  sig_usr1 = SIGUSR1,
53  sig_usr2 = SIGUSR2,
54  sig_chld = SIGCHLD,
55  sig_cont = SIGCONT,
56  sig_stop = SIGSTOP,
57  sig_tstp = SIGTSTP,
58  sig_ttin = SIGTTIN,
59  sig_ttou = SIGTTOU
60 };
61 
66 {
67 public:
68  SignalTrap(const SignalTrap&) = delete;
69  virtual ~SignalTrap() = default;
70 
71  SignalTrap& operator=(const SignalTrap&) = delete;
72  bool operator==(const SignalTrap&) const = delete;
73 
77  virtual bool has(Signal signal) = 0;
78 
83  virtual void run() = 0;
84 
88  virtual void stop() = 0;
89 
93  virtual core::Signal<Signal>& signal_raised() = 0;
94 
95 protected:
96  SignalTrap() = default;
97 };
98 
103 std::shared_ptr<SignalTrap> trap_signals_for_process(
104  std::initializer_list<core::posix::Signal> blocked_signals);
105 
111 std::shared_ptr<SignalTrap> trap_signals_for_all_subsequent_threads(
112  std::initializer_list<core::posix::Signal> blocked_signals);
113 
114 }
115 }
116 
117 #endif
#define CORE_POSIX_DLL_PUBLIC
Definition: visibility.h:26
CORE_POSIX_DLL_PUBLIC std::shared_ptr< SignalTrap > trap_signals_for_process(std::initializer_list< core::posix::Signal > blocked_signals)
Traps the specified signals for the entire process.
Definition: signal.cpp:202
Signal
The Signal enum collects the most common POSIX signals.
Definition: signal.h:38
The SignalTrap class encapsulates functionality to trap and handle signals.
Definition: signal.h:65
CORE_POSIX_DLL_PUBLIC std::shared_ptr< SignalTrap > trap_signals_for_all_subsequent_threads(std::initializer_list< core::posix::Signal > blocked_signals)
Traps the specified signals for the current thread, and inherits the respective signal mask to all ch...
Definition: signal.cpp:210