SigFn
Loading...
Searching...
No Matches
sigfn.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 Maxtek Consulting
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#ifndef SIGFN_HPP
24#define SIGFN_HPP
25
32#include <csignal>
33#include <algorithm>
34#include <chrono>
35#include <functional>
36#include <initializer_list>
37#include <optional>
38#include <stdexcept>
39#include <string>
40#include <unordered_map>
41#include <thread>
42
43#ifdef _WIN32
44#define DLL_EXPORT __declspec(dllexport)
45#else
46#define DLL_EXPORT
47#endif
48
49namespace sigfn
50{
56 typedef std::function<void(int)> handler_function;
57
65
73
79 DLL_EXPORT void ignore(int signum);
80
86 DLL_EXPORT void reset(int signum);
87
94 DLL_EXPORT int wait(std::initializer_list<int> signums);
95
103 DLL_EXPORT std::optional<int> wait_for(std::initializer_list<int> signums, const std::chrono::system_clock::duration &timeout);
104
112 DLL_EXPORT std::optional<int> wait_until(std::initializer_list<int> signums, const std::chrono::system_clock::time_point &deadline);
113}
114
115#endif
Definition sigfn.hpp:50
DLL_EXPORT std::optional< int > wait_until(std::initializer_list< int > signums, const std::chrono::system_clock::time_point &deadline)
wait for any signal in the list until a deadline
std::function< void(int)> handler_function
signal handler function object type
Definition sigfn.hpp:56
DLL_EXPORT std::optional< int > wait_for(std::initializer_list< int > signums, const std::chrono::system_clock::duration &timeout)
wait for any signal in the list with a timeout
DLL_EXPORT void handle(int signum, const handler_function &handler_function)
attach handler to specific signal using copy semantics
DLL_EXPORT void ignore(int signum)
ignore a specific signal
DLL_EXPORT int wait(std::initializer_list< int > signums)
wait for any signal in the list
DLL_EXPORT void reset(int signum)
reset a specific signal to its default behavior
#define DLL_EXPORT
Definition sigfn.h:49