iceoryx_hoofs 2.0.5
Loading...
Searching...
No Matches
signal_handler.hpp
1// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16#ifndef IOX_HOOFS_POSIX_WRAPPER_SIGNAL_HANDLER_HPP
17#define IOX_HOOFS_POSIX_WRAPPER_SIGNAL_HANDLER_HPP
18
19#include "iceoryx_hoofs/platform/signal.hpp"
20
21namespace iox
22{
23namespace posix
24{
25using SignalHandlerCallback_t = void (*)(int);
26
29enum class Signal : int
30{
31 BUS = SIGBUS,
32 INT = SIGINT,
33 TERM = SIGTERM,
34 HUP = SIGHUP,
35 ABORT = SIGABRT,
38};
39
55{
56 public:
57 SignalGuard(SignalGuard&& rhs) noexcept;
58 SignalGuard(const SignalGuard&) = delete;
59 ~SignalGuard() noexcept;
60
61 SignalGuard& operator=(const SignalGuard& rhs) = delete;
62 SignalGuard& operator=(SignalGuard&& rhs) = delete;
63
64 friend SignalGuard registerSignalHandler(const Signal, const SignalHandlerCallback_t) noexcept;
65
66 private:
67 void restorePreviousAction() noexcept;
68 SignalGuard() noexcept = default;
69 SignalGuard(const Signal signal, const struct sigaction& previousAction) noexcept;
70
71 private:
72 Signal m_signal;
73 struct sigaction m_previousAction = {};
74 bool m_doRestorePreviousAction{false};
75};
76
86SignalGuard registerSignalHandler(const Signal signal, const SignalHandlerCallback_t callback) noexcept;
87} // namespace posix
88} // namespace iox
89#endif
The SignalGuard is a class returned by registerSignalHandler. When it goes out of scope it restores t...
Definition signal_handler.hpp:55
friend SignalGuard registerSignalHandler(const Signal, const SignalHandlerCallback_t) noexcept
Register a callback for a specific posix signal (SIG***).
building block to easily create free function for logging in a library context
Definition lockfree_queue.hpp:29