OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
python_signal.h
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include <csignal>
24#include <functional>
25#include <iostream>
26
27// Signal handler type
28using SignalHandler = std::function<void(int)>;
29
30// Global pointer to store the custom handler
32
33// Wrapper to call the custom handler
34void signal_dispatcher(int signum) {
36 (*custom_handler_ptr)(signum);
37 }
38}
39
40// Activate signal catching
41void activate_signal_handling(SignalHandler handler, int signal = SIGINT) {
42 static SignalHandler custom_handler; // Keep the handler alive
43 custom_handler = std::move(handler);
44 custom_handler_ptr = &custom_handler;
45 std::signal(signal, signal_dispatcher);
46}
47
48
49void restore_default_signal_handling(int signal = SIGINT) {
50 std::signal(signal, SIG_DFL);
51}
static SignalHandler * custom_handler_ptr
std::function< void(int)> SignalHandler
void signal_dispatcher(int signum)
void activate_signal_handling(SignalHandler handler, int signal=SIGINT)
void restore_default_signal_handling(int signal=SIGINT)