11#include <condition_variable>
14#if !__linux__ && !__APPLE__ && !__CYGWIN__ && !__QNXNTO__
25bool usr_interrupt =
false;
27std::condition_variable cv;
31void handler(
int signum)
46 LOG_DEBUG(
"Unexpected signal caught: {}", signum);
52 std::lock_guard lk(cv_m);
64 usr_interrupt =
false;
65 static_cast<void>(signal(SIGUSR1, handler));
66 static_cast<void>(signal(SIGINT, handler));
67 static_cast<void>(signal(SIGTERM, handler));
71 LOG_INFO(
"Programm waits for one of the signals: -SIGUSR1 / -SIGINT (Ctrl + c) / -SIGTERM");
74 std::unique_lock lk(cv_m);
75 cv.wait(lk, [] {
return usr_interrupt; });
78 static_cast<void>(signal(SIGUSR1, SIG_DFL));
79 static_cast<void>(signal(SIGINT, SIG_DFL));
80 static_cast<void>(signal(SIGTERM, SIG_DFL));
82 LOG_ERROR(
"Waiting for Sigterm is not supported in Windows");
88 LOG_TRACE(
"called with seconds={}", seconds);
90 static_cast<void>(signal(SIGINT, handler));
91 static_cast<void>(signal(SIGTERM, handler));
93 for (
size_t i = 0; i < seconds && !usr_interrupt; i++)
95 LOG_INFO(
"{} seconds till program finishes", seconds - i);
98#if __linux__ || __APPLE__ || __CYGWIN__ || __QNXNTO__
101 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
105 static_cast<void>(signal(SIGINT, SIG_DFL));
106 static_cast<void>(signal(SIGTERM, SIG_DFL));
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
#define LOG_INFO
Info to the user on the state of the program.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Class to catch system signals and sleep.
void countDownSeconds(size_t seconds)
Wait the thread till time passes.
void waitForSignal(bool showText=false)
Wait the thread till sigusr signal is send.