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
23
24#include <core/signal.h>
25
26#include <signal.h>
27
28#include <initializer_list>
29#include <memory>
30
31namespace core
32{
33namespace posix
34{
38enum class Signal
39{
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{
67public:
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
95protected:
96 SignalTrap() = default;
97};
98
103std::shared_ptr<SignalTrap> trap_signals_for_process(
104 std::initializer_list<core::posix::Signal> blocked_signals);
105
111std::shared_ptr<SignalTrap> trap_signals_for_all_subsequent_threads(
112 std::initializer_list<core::posix::Signal> blocked_signals);
113
114}
115}
116
117#endif
virtual bool has(Signal signal)=0
Returns true if the given signal is trapped by this instance.
virtual ~SignalTrap()=default
SignalTrap & operator=(const SignalTrap &)=delete
SignalTrap(const SignalTrap &)=delete
virtual void run()=0
Starts observation of incoming signals, relaying them via signal_raised(). The call blocks until stop...
bool operator==(const SignalTrap &) const =delete
virtual void stop()=0
Stops execution of the signal trap.
virtual core::Signal< Signal > & signal_raised()=0
Emitted whenever a trapped signal is raised by the operating system.
Signal
The Signal enum collects the most common POSIX signals.
Definition signal.h:39
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
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
#define CORE_POSIX_DLL_PUBLIC
Definition visibility.h:26