Kaydet (Commit) ecdd44e8 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 0950bb5e
......@@ -30,7 +30,7 @@
#include "lockfile.hxx"
#include "userinstall.hxx"
#include "desktopcontext.hxx"
#include "exithelper.hxx"
#include "exithelper.h"
#include "migration.hxx"
#include <svtools/javacontext.hxx>
......@@ -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;
}
......
......@@ -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.
}
......
......@@ -17,44 +17,22 @@
* 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
};
#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
};
} // namespace desktop
#endif // #ifndef _DESKTOP_EXITHELPER_HXX_
#endif /* #ifndef _DESKTOP_EXITHELPER_H_ */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -22,7 +22,7 @@
#include <osl/process.h>
#include <rtl/ustring.hxx>
#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;
......
......@@ -50,6 +50,7 @@
#include <sal/main.h>
#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
......
......@@ -43,7 +43,7 @@
#include "rtl/string.h"
#include <sal/macros.h>
#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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment