]>
vaikene.ee Git - evaf/blob - src/main/GUI/exithandler.cpp
2 * @file main/GUI/exithandler.cpp
3 * @brief Exit handlers for the eVaf main executable
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #include "exithandler.h"
22 #include <Common/iLogger>
23 #include <Common/iApp>
27 #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
39 #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
42 * Signal handler on Linux
44 * Handles TERM and HUP signals and either quits or restarts the application.
46 * @TODO According to the signal(7) documentation, only "safe" functions can be called from the
47 * signal handler. We don't know how safe it is to call iApp::quit() and iApp::restart() and
48 * probably have to implement "safe" versions of these functions.
50 static void signalHandler(int sig
)
52 eVaf::Common::iApp
* app
= eVaf::Common::iApp::instance();
73 * Signal handler on Windows
75 * Either quits or restarts the application.
77 * @TODO Is there a similar concept of "safe" functions for Windows signal handlers?
79 static BOOL WINAPI
signalHandler(DWORD sig
)
81 eVaf::Common::iApp
* app
= eVaf::Common::iApp::instance();
85 case CTRL_CLOSE_EVENT
:
86 case CTRL_LOGOFF_EVENT
:
87 case CTRL_SHUTDOWN_EVENT
:
94 case CTRL_BREAK_EVENT
:
106 } // namespace eVaf::GUI::Internal
107 } // namespace eVaf::GUI
111 bool eVaf::GUI::Internal::installExitHandler()
114 #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
116 memset(&sa
, 0, sizeof(sa
));
117 sa
.sa_handler
= signalHandler
;
118 if (sigaction(SIGTERM
, &sa
, NULL
) != 0) {
119 EVAF_FATAL_ERROR("sigaction() failed: %m");
122 if (sigaction(SIGHUP
, &sa
, NULL
) != 0) {
123 EVAF_FATAL_ERROR("sigaction() failed: %m");
129 if (SetConsoleCtrlHandler(signalHandler
, true) == 0) {
130 EVAF_FATAL_ERROR("SetConsoleCtrlHandler() failed");