Implement signal handling: SIGINT, SIGTERM
This commit is contained in:
@@ -75,7 +75,7 @@ namespace Inferno {
|
||||
Settings::destroy();
|
||||
}
|
||||
|
||||
void Application::run()
|
||||
int Application::run()
|
||||
{
|
||||
dbg() << "Application startup";
|
||||
|
||||
@@ -159,6 +159,8 @@ namespace Inferno {
|
||||
}
|
||||
|
||||
dbg() << "Application shutdown";
|
||||
|
||||
return m_status;
|
||||
}
|
||||
|
||||
void Application::onEvent(Event& e)
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Inferno {
|
||||
Application();
|
||||
virtual ~Application();
|
||||
|
||||
void run();
|
||||
int run();
|
||||
|
||||
void onEvent(Event& e);
|
||||
bool onWindowClose(WindowCloseEvent& e);
|
||||
@@ -36,6 +36,8 @@ namespace Inferno {
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
inline void setStatus(int status) { m_status = status; }
|
||||
|
||||
inline Window& getWindow() const { return *m_window; }
|
||||
|
||||
static inline Application& the() { return *s_instance; }
|
||||
@@ -50,6 +52,8 @@ namespace Inferno {
|
||||
std::shared_ptr<Font> m_font;
|
||||
//
|
||||
|
||||
int m_status = 0;
|
||||
|
||||
static Application* s_instance;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,12 +15,13 @@ int main(int argc, char* argv[])
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
// Start application
|
||||
auto app = Inferno::createApplication();
|
||||
app->run();
|
||||
|
||||
int status = app->run();
|
||||
|
||||
delete app;
|
||||
|
||||
return 0;
|
||||
return status;
|
||||
}
|
||||
|
||||
#endif // ENTRYPOINT_H
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include <csignal> // signal
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
#include "inferno/application.h"
|
||||
#include "inferno/assert.h"
|
||||
#include "inferno/core.h"
|
||||
#include "inferno/event/applicationevent.h"
|
||||
@@ -74,6 +77,10 @@ namespace Inferno {
|
||||
setVSync(vsync);
|
||||
RenderCommand::setViewport(0, 0, width, height);
|
||||
|
||||
// Signal callbacks
|
||||
signal(SIGINT, Window::signalCallback);
|
||||
signal(SIGTERM, Window::signalCallback);
|
||||
|
||||
// Error callback
|
||||
glfwSetErrorCallback([](int error, const char* description) {
|
||||
dbgln("GLFW Error {}: {}", error, description);
|
||||
@@ -195,6 +202,16 @@ namespace Inferno {
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void Window::signalCallback(int signal)
|
||||
{
|
||||
Application::the().setStatus(signal);
|
||||
|
||||
if (signal == SIGINT || signal == SIGTERM) {
|
||||
WindowCloseEvent e;
|
||||
Application::the().getWindow().m_eventCallback(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setWindowMonitor() const
|
||||
{
|
||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Inferno {
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
static void signalCallback(int signal);
|
||||
|
||||
void setWindowMonitor() const;
|
||||
void setVSync(bool enabled);
|
||||
void setShouldClose(bool close) const;
|
||||
|
||||
Reference in New Issue
Block a user