2 * Copyright © 2013 Canonical Ltd.
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.
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.
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/>.
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
19 #ifndef CORE_POSIX_SIGNAL_H_
20 #define CORE_POSIX_SIGNAL_H_
22 #include <core/posix/visibility.h>
24 #include <core/signal.h>
28 #include <initializer_list>
36 * @brief The Signal enum collects the most common POSIX signals.
63 * @brief The SignalTrap class encapsulates functionality to trap and handle signals.
65 class CORE_POSIX_DLL_PUBLIC SignalTrap
68 SignalTrap(const SignalTrap&) = delete;
69 virtual ~SignalTrap() = default;
71 SignalTrap& operator=(const SignalTrap&) = delete;
72 bool operator==(const SignalTrap&) const = delete;
75 * @brief Returns true if the given signal is trapped by this instance.
77 virtual bool has(Signal signal) = 0;
80 * @brief Starts observation of incoming signals, relaying them via
81 * signal_raised(). The call blocks until stop is called.
83 virtual void run() = 0;
86 * @brief Stops execution of the signal trap.
88 virtual void stop() = 0;
91 * @brief Emitted whenever a trapped signal is raised by the operating system.
93 virtual core::Signal<Signal>& signal_raised() = 0;
96 SignalTrap() = default;
100 * @brief Traps the specified signals for the entire process.
102 CORE_POSIX_DLL_PUBLIC
103 std::shared_ptr<SignalTrap> trap_signals_for_process(
104 std::initializer_list<core::posix::Signal> blocked_signals);
107 * @brief Traps the specified signals for the current thread, and inherits
108 * the respective signal mask to all child-threads.
110 CORE_POSIX_DLL_PUBLIC
111 std::shared_ptr<SignalTrap> trap_signals_for_all_subsequent_threads(
112 std::initializer_list<core::posix::Signal> blocked_signals);