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
{
private:
EventManager& eventManager;
/**
* Mapping of signal numbers to functions.
*/
std::map<int, std::function<void()>> handlersMappedBySignalNum;
/**
* Fetches all signals currently of interest to the application.
*
* Currently this just returns a set of all signals (using sigfillset())
*
* @return
*/
sigset_t getRegisteredSignalSet() const;
/**
* We keep record of the number of shutdown signals received. See definition of triggerApplicationShutdown()
* for more on this.
*/
int shutdownSignalsReceived = 0;
public:
2021-04-06 02:10:14 +01:00
SignalHandler(EventManager& eventManager): eventManager(eventManager) {};
2021-04-04 21:04:12 +01:00
/**
* Entry point for SignalHandler thread.
*/
void run();
/**
* Initiates the SignalHandler thread.
*/
void startup();
/**
* Triggers the shutdown of the SignalHandler thread.
*/
void triggerShutdown() {
this->setThreadState(ThreadState::SHUTDOWN_INITIATED);
2021-04-04 21:04:12 +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.
*/
void triggerApplicationShutdown();
};
}