From dda7da0549233d54ada594ebf0771ad9a6841050 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Enar=20V=C3=A4ikene?= Date: Thu, 19 May 2011 15:16:53 +0300 Subject: [PATCH] Added eVaf Command Line Interface application. --- src/main/CLI/cli.rc | 0 src/main/CLI/exithandler.cpp | 136 +++++++++++++++++++++++++++++++++++ src/main/CLI/exithandler.h | 39 ++++++++++ src/main/CLI/version.h | 50 +++++++++++++ src/main/CLI/version.rc | 53 ++++++++++++++ 5 files changed, 278 insertions(+) create mode 100644 src/main/CLI/cli.rc create mode 100644 src/main/CLI/exithandler.cpp create mode 100644 src/main/CLI/exithandler.h create mode 100644 src/main/CLI/version.h create mode 100644 src/main/CLI/version.rc diff --git a/src/main/CLI/cli.rc b/src/main/CLI/cli.rc new file mode 100644 index 0000000..e69de29 diff --git a/src/main/CLI/exithandler.cpp b/src/main/CLI/exithandler.cpp new file mode 100644 index 0000000..a96842d --- /dev/null +++ b/src/main/CLI/exithandler.cpp @@ -0,0 +1,136 @@ +/** + * @file main/CLI/exithandler.cpp + * @brief Exit handlers for the eVaf main executable + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#include "exithandler.h" + +#include +#include + +#include + +#ifdef Q_OS_LINUX +# include +#endif + +#ifdef Q_OS_WIN32 +# include +#endif + +namespace eVaf { +namespace CLI { +namespace Internal { + +#ifdef Q_OS_LINUX + +/** + * Signal handler on Linux + * + * Handles TERM and HUP signals and either quits or restarts the application. + * + * @TODO According to the signal(7) documentation, only "safe" functions can be called from the + * signal handler. We don't know how safe it is to call iApp::quit() and iApp::restart() and + * probably have to implement "safe" versions of these functions. + */ +static void signalHandler(int sig) +{ + eVaf::Common::iApp * app = eVaf::Common::iApp::instance(); + + switch (sig) { + case SIGTERM: + if (app) + app->quit(); + else + exit(0); + break; + case SIGHUP: + if (app) + app->restart(); + break; + } +} + +#endif + +#ifdef Q_OS_WIN32 + +/** + * Signal handler on Windows + * + * Either quits or restarts the application. + * + * @TODO Is there a similar concept of "safe" functions for Windows signal handlers? + */ +static BOOL WINAPI signalHandler(DWORD sig) +{ + eVaf::Common::iApp * app = eVaf::Common::iApp::instance(); + + switch (sig) { + case CTRL_C_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + if (app) + app->quit(); + else + exit(0); + return true; + break; + case CTRL_BREAK_EVENT: + if (app) + app->restart(); + return true; + break; + } + + return false; +} + +#endif + +} // namespace eVaf::GUI::Internal +} // namespace eVaf::GUI +} // namespace eVaf + + +bool eVaf::CLI::Internal::installExitHandler() +{ + +#ifdef Q_OS_LINUX + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = signalHandler; + if (sigaction(SIGTERM, &sa, NULL) != 0) { + EVAF_FATAL_ERROR("sigaction() failed: %m"); + return false; + } + if (sigaction(SIGHUP, &sa, NULL) != 0) { + EVAF_FATAL_ERROR("sigaction() failed: %m"); + return false; + } +#endif + +#ifdef Q_OS_WIN32 + if (SetConsoleCtrlHandler(signalHandler, true) == 0) { + EVAF_FATAL_ERROR("SetConsoleCtrlHandler() failed"); + return false; + } +#endif + + return true; +} diff --git a/src/main/CLI/exithandler.h b/src/main/CLI/exithandler.h new file mode 100644 index 0000000..8b33938 --- /dev/null +++ b/src/main/CLI/exithandler.h @@ -0,0 +1,39 @@ +/** + * @file main/CLI/exithandler.h + * @brief Exit handlers for the eVaf main executable + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#ifndef __CLI_EXITHANDLER_H +# define __CLI_EXITHANDLER_H + +namespace eVaf { +namespace CLI { +namespace Internal { + +/** + * Installs an exit handler for the selected platform. + * + * Exit handler quits or restarts the application when a corresponding signal + * is received. + */ +bool installExitHandler(); + +} // namespace eVaf::CLI::Internal +} // namespace eVaf::CLI +} // namespace eVaf + +#endif // exithandler.h diff --git a/src/main/CLI/version.h b/src/main/CLI/version.h new file mode 100644 index 0000000..5d43974 --- /dev/null +++ b/src/main/CLI/version.h @@ -0,0 +1,50 @@ +/** + * @file main/CLI/version.h + * @brief Version information for eVaf modules + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#ifndef __CLI_VERSION_H +# define __CLI_VERSION_H + +#include + +/** + * Module/library version number in the form major,minor,release,build + */ +#define VER_FILE_VERSION 0,1,1,1 + +/** + * Module/library version number in the string format (shall end with \0) + */ +#define VER_FILE_VERSION_STR "0.1.1.1\0" + +/** + * Module/library name (shall end with \0) + */ +#define VER_MODULE_NAME_STR "eVafCLI\0" + +/** + * Original file name for windows (shall end with \0) + */ +#define VER_ORIGINAL_FILE_NAME_STR "eVafCLI.exe\0" + +/** + * Description of the module/library (shall end with \0) + */ +#define VER_FILE_DESCRIPTION_STR "Main eVaf CLI executable.\0" + +#endif // version.h diff --git a/src/main/CLI/version.rc b/src/main/CLI/version.rc new file mode 100644 index 0000000..a499b88 --- /dev/null +++ b/src/main/CLI/version.rc @@ -0,0 +1,53 @@ +/** + * @file main/CLI/version.rc + * @brief Windows resource file with module/library version information. + * @author Enar Vaikene + * + * Copyright (c) 2011 Enar Vaikene + * + * This file is part of the eVaf C++ cross-platform application development framework. + * + * This file can be used under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation and appearing in + * the file LICENSE included in the packaging of this file. Please review the + * the following information to ensure the GNU General Public License version + * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + * + * Alternatively, this file may be used in accordance with the Commercial License + * Agreement provided with the Software. + */ + +#include "version.h" +#include +#include + + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VER_FILE_VERSION + PRODUCTVERSION VER_PRODUCT_VERSION + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE 0x0L + BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904B0" + BEGIN + VALUE "CompanyName", VER_COMPANY_NAME_STR + VALUE "FileDescription", VER_FILE_DESCRIPTION_STR + VALUE "FileVersion", VER_FILE_VERSION_STR + VALUE "LegalCopyright", VER_LEGAL_COPYRIGHT_STR + VALUE "OriginalFilename", VER_ORIGINAL_FILE_NAME_STR + VALUE "ProductName", VER_PRODUCT_NAME_STR + VALUE "ProductVersion", VER_PRODUCT_VERSION_STR + VALUE "Build Date", VER_PRODUCT_DATE_STR + VALUE "Module Name", VER_MODULE_NAME_STR + END + END + END -- 2.45.2