Files
BloomPatched/src/SignalHandler/SignalHandler.hpp

65 lines
1.7 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#pragma once
#include <csignal>
2021-04-06 02:10:14 +01:00
#include "src/Helpers/Thread.hpp"
#include "src/EventManager/EventManager.hpp"
#include "src/Helpers/SyncSafe.hpp"
2021-04-04 21:04:12 +01:00
namespace Bloom
{
class SignalHandler: public Thread
{
public:
explicit SignalHandler(EventManager& eventManager): eventManager(eventManager) {};
/**
* Entry point for SignalHandler thread.
*/
void run();
/**
* Triggers the shutdown of the SignalHandler thread.
*/
void triggerShutdown() {
this->setThreadState(ThreadState::SHUTDOWN_INITIATED);
};
2021-04-04 21:04:12 +01:00
private:
EventManager& eventManager;
/**
* Mapping of signal numbers to functions.
*/
std::map<int, std::function<void()>> handlersMappedBySignalNum;
2021-05-31 00:03:57 +01:00
/**
* We keep record of the number of shutdown signals received. See definition of triggerApplicationShutdown()
* for more on this.
*/
int shutdownSignalsReceived = 0;
/**
* Initiates the SignalHandler thread.
*/
void startup();
2021-04-04 21:04:12 +01:00
/**
* Fetches all signals currently of interest to the application.
*
* Currently this just returns a set of all signals (using sigfillset())
*
* @return
*/
[[nodiscard]] sigset_t getRegisteredSignalSet() const;
2021-04-04 21:04:12 +01:00
/**
2021-05-31 00:03:57 +01:00
* Handler for SIGINT, SIGTERM, etc signals.
*
* Will trigger a ShutdownApplication event to kick-off a clean shutdown or it will terminate the
* program immediately if numerous SIGINT signals have been received.
2021-04-04 21:04:12 +01:00
*/
2021-05-31 00:03:57 +01:00
void triggerApplicationShutdown();
2021-04-04 21:04:12 +01:00
};
}