From ecdd44e8f577e51e0208e9f421704a70041f1be8 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 12 Mar 2013 13:43:31 +0200 Subject: Use symbolic names instead of magic literal constants We use tons of plain C-style #defines to give symbolic names to constants all over the place already, in headers used from C++ code only. So why in this rare case where the symbolic names for some constants actually would be needed from a C source file, too, here then we define them inside a C++ class? Change-Id: I45726fe42687779724c45a1e2b118cc7a1debcf1 --- desktop/source/app/app.cxx | 8 +-- desktop/source/app/sofficemain.cxx | 4 +- desktop/source/inc/exithelper.h | 38 ++++++++++++++ desktop/source/inc/exithelper.hxx | 60 ---------------------- desktop/unx/source/officeloader/officeloader.cxx | 4 +- desktop/unx/source/start.c | 5 +- desktop/win32/source/officeloader/officeloader.cxx | 6 +-- 7 files changed, 53 insertions(+), 72 deletions(-) create mode 100644 desktop/source/inc/exithelper.h delete mode 100644 desktop/source/inc/exithelper.hxx (limited to 'desktop') diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index 9899b1a9a69c..3e03a57a8fa4 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -30,7 +30,7 @@ #include "lockfile.hxx" #include "userinstall.hxx" #include "desktopcontext.hxx" -#include "exithelper.hxx" +#include "exithelper.h" #include "migration.hxx" #include @@ -436,7 +436,7 @@ void FatalError(const ::rtl::OUString& sMessage) sTitle.appendAscii (" - Fatal Error"); Application::ShowNativeErrorBox (sTitle.makeStringAndClear (), sMessage); - _exit(ExitHelper::E_FATAL_ERROR); + _exit(EXITHELPER_FATAL_ERROR); } static bool ShouldSuppressUI(const CommandLineArgs& rCmdLine) @@ -1306,7 +1306,7 @@ sal_uInt16 Desktop::Exception(sal_uInt16 nError) if ( m_rSplashScreen.is() ) m_rSplashScreen->reset(); - _exit( ExitHelper::E_CRASH_WITH_RESTART ); + _exit( EXITHELPER_CRASH_WITH_RESTART ); } else { @@ -1764,7 +1764,7 @@ int Desktop::doShutdown() if ( m_rSplashScreen.is() ) m_rSplashScreen->reset(); - return ExitHelper::E_NORMAL_RESTART; + return EXITHELPER_NORMAL_RESTART; } return EXIT_SUCCESS; } diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx index 8a0f6985c47e..a8c091177171 100644 --- a/desktop/source/app/sofficemain.cxx +++ b/desktop/source/app/sofficemain.cxx @@ -22,6 +22,7 @@ #include "desktopdllapi.h" #include "app.hxx" +#include "exithelper.h" #include "cmdlineargs.hxx" #include "cmdlinehelp.hxx" @@ -100,7 +101,8 @@ Java_org_libreoffice_experimental_desktop_Desktop_runMain(JNIEnv* /* env */, do { nRet = soffice_main(); LOGI("soffice_main returned %d", nRet ); - } while (nRet == 81 || nRet == 79); // pretend to re-start. + } while (nRet == EXITHELPER_NORMAL_RESTART || + nRet == EXITHELPER_CRASH_WITH_RESTART); // pretend to re-start. } diff --git a/desktop/source/inc/exithelper.h b/desktop/source/inc/exithelper.h new file mode 100644 index 000000000000..e670da3bcab2 --- /dev/null +++ b/desktop/source/inc/exithelper.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef _DESKTOP_EXITHELPER_H_ +#define _DESKTOP_EXITHELPER_H_ + +enum EExitCodes { + /* e.g. used to force showing of the command line help */ + EXITHELPER_NO_ERROR = 0, + /* pipe was detected - second office must terminate itself */ + EXITHELPER_SECOND_OFFICE = 1, + /* an uno exception was catched during startup */ + EXITHELPER_FATAL_ERROR = 333, /* Only the low 8 bits are significant 333 % 256 = 77 */ + /* user force automatic restart after crash */ + EXITHELPER_CRASH_WITH_RESTART = 79, + /* the office restarts itself */ + EXITHELPER_NORMAL_RESTART = 81 +}; + +#endif /* #ifndef _DESKTOP_EXITHELPER_H_ */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/source/inc/exithelper.hxx b/desktop/source/inc/exithelper.hxx deleted file mode 100644 index 6343bfd6d872..000000000000 --- a/desktop/source/inc/exithelper.hxx +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef _DESKTOP_EXITHELPER_HXX_ -#define _DESKTOP_EXITHELPER_HXX_ - -namespace desktop -{ - -//============================================================================= -/** @short provide helper functions to handle a abnormal exit - and contain a list of all "well known" exit codes. - */ -class ExitHelper -{ - public: - - //--------------------------------------------------------------------- - /** @short list of all well known exit codes. - - @descr Its not allowed to use exit codes hard coded - inside office. All places must use these list to - be synchron. - */ - enum EExitCodes - { - /// e.g. used to force showing of the command line help - E_NO_ERROR = 0, - /// pipe was detected - second office must terminate itself - E_SECOND_OFFICE = 1, - /// an uno exception was catched during startup - E_FATAL_ERROR = 333, // Only the low 8 bits are significant 333 % 256 = 77 - /// user force automatic restart after crash - E_CRASH_WITH_RESTART = 79, - /// the office restarts itself - E_NORMAL_RESTART = 81 - }; -}; - -} // namespace desktop - -#endif // #ifndef _DESKTOP_EXITHELPER_HXX_ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/unx/source/officeloader/officeloader.cxx b/desktop/unx/source/officeloader/officeloader.cxx index 53ab5a2f41c0..621555b301bf 100644 --- a/desktop/unx/source/officeloader/officeloader.cxx +++ b/desktop/unx/source/officeloader/officeloader.cxx @@ -22,7 +22,7 @@ #include #include -#include "../../../source/inc/exithelper.hxx" +#include "../../../source/inc/exithelper.h" using namespace desktop; using ::rtl::OUString; @@ -83,7 +83,7 @@ SAL_IMPLEMENT_MAIN() if ( info.Fields & osl_Process_EXITCODE ) { exitcode = info.Code; - bRestart = (ExitHelper::E_CRASH_WITH_RESTART == exitcode || ExitHelper::E_NORMAL_RESTART == exitcode); + bRestart = (EXITHELPER_CRASH_WITH_RESTART == exitcode || EXITHELPER_NORMAL_RESTART == exitcode); } else break; diff --git a/desktop/unx/source/start.c b/desktop/unx/source/start.c index 9ec7341d7b9e..7366a9323a32 100644 --- a/desktop/unx/source/start.c +++ b/desktop/unx/source/start.c @@ -50,6 +50,7 @@ #include #include "args.h" +#include "exithelper.h" #include "splashx.h" #define PIPEDEFAULTPATH "/tmp" @@ -927,14 +928,14 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv ) status = child_get_exit_code(info); g_pProcess = 0; // reset switch (status) { - case 79: // re-start with just -env: parameters + case EXITHELPER_CRASH_WITH_RESTART: // re-start with just -env: parameters #if OSL_DEBUG_LEVEL > 0 fprintf (stderr, "oosplash: re-start with just -env: params !\n"); #endif bRestart = sal_True; bAllArgs = sal_False; break; - case 81: // re-start with all arguments + case EXITHELPER_NORMAL_RESTART: // re-start with all arguments #if OSL_DEBUG_LEVEL > 0 fprintf (stderr, "oosplash: re-start with all params !\n"); #endif diff --git a/desktop/win32/source/officeloader/officeloader.cxx b/desktop/win32/source/officeloader/officeloader.cxx index 527125f14a8a..69ec7f826e7b 100644 --- a/desktop/win32/source/officeloader/officeloader.cxx +++ b/desktop/win32/source/officeloader/officeloader.cxx @@ -43,7 +43,7 @@ #include "rtl/string.h" #include -#include "../../../source/inc/exithelper.hxx" +#include "../../../source/inc/exithelper.h" #include "../extendloaderenvironment.hxx" #define PIPE_PREFIX TEXT("\\\\.\\pipe\\OSL_PIPE_") @@ -340,7 +340,7 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) lpCommandLine, MY_STRING(L"\"")); p = desktop_win32::commandLineAppend(p, argv[0]); for (int i = 1; i < argc; ++i) { - if (bFirst || ::desktop::ExitHelper::E_NORMAL_RESTART == dwExitCode || wcsncmp(argv[i], MY_STRING(L"-env:")) == 0) { + if (bFirst || EXITHELPER_NORMAL_RESTART == dwExitCode || wcsncmp(argv[i], MY_STRING(L"-env:")) == 0) { p = desktop_win32::commandLineAppend(p, MY_STRING(L"\" \"")); p = desktop_win32::commandLineAppend(p, argv[i]); } @@ -427,7 +427,7 @@ int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int ) CloseHandle( aProcessInfo.hThread ); } } while ( fSuccess - && ( ::desktop::ExitHelper::E_CRASH_WITH_RESTART == dwExitCode || ::desktop::ExitHelper::E_NORMAL_RESTART == dwExitCode )); + && ( EXITHELPER_CRASH_WITH_RESTART == dwExitCode || EXITHELPER_NORMAL_RESTART == dwExitCode )); delete[] lpCommandLine; return fSuccess ? dwExitCode : -1; -- cgit