Application.
More...
#include <base/Application.h>
Inherits Object.
Application.
This is a singleton object for the context of the application. User-defined exit codes should start from EXIT_CODE_USER.
Example:
public:
MyApplication()
{
}
{
}
};
APPLICATION_STUB(MyApplication);
- Version
- 1.3
- Examples
- testsuite/Array.cpp, testsuite/BitSet.cpp, testsuite/client.cpp, testsuite/digest.cpp, testsuite/dom.cpp, testsuite/du.cpp, testsuite/echod.cpp, testsuite/eval.cpp, testsuite/ftp.cpp, testsuite/HashSet.cpp, testsuite/HashTable.cpp, testsuite/http.cpp, testsuite/IEEE1394.cpp, testsuite/List.cpp, testsuite/ln.cpp, testsuite/ls.cpp, testsuite/Map.cpp, testsuite/ping.cpp, testsuite/Process.cpp, testsuite/Quota.cpp, testsuite/rm.cpp, testsuite/server.cpp, testsuite/Set.cpp, testsuite/Stack.cpp, testsuite/Thread.cpp, testsuite/validate.cpp, testsuite/Version.cpp, and testsuite/xsltprocessor.cpp.
◆ ExitCode
Application exit code. Exit codes should always be in the range [0; 127].
Enumerator |
---|
EXIT_CODE_INVALID | This value specifies an invalid exit code which is used when the true exit code isn't available.
|
EXIT_CODE_NORMAL | The normal exit code of the application (indicating no errors).
|
EXIT_CODE_USER | The first user defined exit code.
|
EXIT_CODE_ERROR | The default exit code indicating an unspecified error.
|
EXIT_CODE_CONFLICT | This value specifies that the true exit code conflicts with a reserved exit code in the current context.
|
EXIT_CODE_INTERNAL_ERROR | The exit code indicating an internal error (e.g. uncaught exception and violations of exception specification).
|
EXIT_CODE_INITIALIZATION | The exit code returned by the application on initialization error.
|
EXIT_CODE_EXTERNAL | The exit code used when the application exit code is determined externally.
|
◆ Application()
Application::Application |
( |
const String & |
name | ) |
|
Initializes application with no arguments and no environment variables.
- Parameters
-
◆ ~Application()
virtual Application::~Application |
( |
| ) |
|
|
virtualnoexcept |
Destroys the application object.
◆ error()
Writes error to stderr. Only intended for console apps. Only sets exit code is not equal to EXIT_CODE_INVALID.
- Parameters
-
text | The error message. |
exitCode | The exit code. Not set by default. |
◆ exceptionHandler() [1/2]
virtual int Application::exceptionHandler |
( |
| ) |
|
|
virtualnoexcept |
Handler of uncaught unknown exceptions. By default this handler writes an error message to stderr and sets the error code to EXIT_CODE_ERROR.
◆ exceptionHandler() [2/2]
virtual int Application::exceptionHandler |
( |
const Exception & |
e | ) |
|
|
virtualnoexcept |
Handler of uncaught exceptions. By default this handler writes the exception to stderr and sets the error code to EXIT_CODE_ERROR.
◆ getApplication()
◆ getArguments()
const Array<String>& Application::getArguments |
( |
| ) |
const |
|
inlinenoexcept |
Returns the arguments passed to the application.
◆ getEnvironment()
Returns the environment variables.
◆ getExitCode()
int Application::getExitCode |
( |
| ) |
const |
|
inlinenoexcept |
◆ getFormalName()
const String& Application::getFormalName |
( |
| ) |
const |
|
inlinenoexcept |
Returns the formal name of the application.
◆ getLock()
Returns the application lock. Do NOT abuse.
◆ getName()
const String& Application::getName |
( |
| ) |
const |
|
inlinenoexcept |
Returns the name/path of the application (argument 0).
◆ hangup()
void Application::hangup |
( |
| ) |
|
|
noexcept |
Signals the application to reload its configuration.
◆ isHangingup()
bool Application::isHangingup |
( |
| ) |
|
|
noexcept |
Returns true if the application has been signaled to hangup. The hangup flag is automatically reset.
◆ isTerminated()
bool Application::isTerminated |
( |
| ) |
const |
|
inlinenoexcept |
Returns true if the application has been signaled to terminate.
◆ main()
virtual void Application::main |
( |
| ) |
|
|
pure virtual |
Entry function for application.
◆ onTermination()
virtual void Application::onTermination |
( |
| ) |
|
|
virtualnoexcept |
Invoked on application termination. Exits the application immediately by default (i.e. does not return).
◆ setArgumentsAndEnvironment()
static void Application::setArgumentsAndEnvironment |
( |
int |
numberOfArguments, |
|
|
const char * |
arguments[], |
|
|
const char * |
environment[] = nullptr |
|
) |
| |
|
static |
Sets arguments and environment.
◆ setExitCode()
void Application::setExitCode |
( |
int |
value | ) |
|
|
inlinenoexcept |
Sets the exit code (the default is EXIT_CODE_NORMAL).
- Parameters
-
value | The desired exit code. The value should be in the range from 0 to 127. |
- Examples
- testsuite/IEEE1394.cpp.
◆ stub()
template<class APPLICATION >
static int Application::stub |
( |
int |
numberOfArguments, |
|
|
const char * |
arguments[], |
|
|
const char * |
environment[] |
|
) |
| |
|
inlinestaticnoexcept |
◆ terminate()
void Application::terminate |
( |
| ) |
|
|
noexcept |
Signals the application to terminate itself.