Browse Source

Implement signal handling: SIGINT, SIGTERM

master
Riyyi 3 years ago
parent
commit
a1372b971e
  1. 4
      inferno/src/inferno/application.cpp
  2. 6
      inferno/src/inferno/application.h
  3. 7
      inferno/src/inferno/entrypoint.h
  4. 17
      inferno/src/inferno/window.cpp
  5. 2
      inferno/src/inferno/window.h

4
inferno/src/inferno/application.cpp

@ -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)

6
inferno/src/inferno/application.h

@ -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;
};

7
inferno/src/inferno/entrypoint.h

@ -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

17
inferno/src/inferno/window.cpp

@ -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();

2
inferno/src/inferno/window.h

@ -34,6 +34,8 @@ namespace Inferno {
// -----------------------------------------
static void signalCallback(int signal);
void setWindowMonitor() const;
void setVSync(bool enabled);
void setShouldClose(bool close) const;

Loading…
Cancel
Save