Base Framework
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Application Class Referenceabstract

Application. More...

#include <base/Application.h>

Inherits Object.

Classes

class  Stub
 

Public Types

enum  ExitCode {
  EXIT_CODE_INVALID = -1, EXIT_CODE_NORMAL = 0, EXIT_CODE_USER = 1, EXIT_CODE_ERROR = 123,
  EXIT_CODE_CONFLICT = 124, EXIT_CODE_INTERNAL_ERROR = 125, EXIT_CODE_INITIALIZATION = 126, EXIT_CODE_EXTERNAL = 127
}
 

Public Member Functions

 Application (const String &name)
 
const StringgetFormalName () const noexcept
 
const StringgetName () const noexcept
 
const Array< String > & getArguments () const noexcept
 
const Map< String, String > & getEnvironment () const noexcept
 
virtual int exceptionHandler (const Exception &e) noexcept
 
virtual int exceptionHandler () noexcept
 
void hangup () noexcept
 
void terminate () noexcept
 
bool isHangingup () noexcept
 
int getExitCode () const noexcept
 
void setExitCode (int value) noexcept
 
void error (const String &text, int exitCode=EXIT_CODE_INVALID)
 
bool isTerminated () const noexcept
 
virtual void onTermination () noexcept
 
virtual void main ()=0
 
virtual ~Application () noexcept
 

Static Public Member Functions

static ApplicationgetApplication () noexcept
 
static MutualExclusiongetLock () noexcept
 
template<class APPLICATION >
static int stub (int numberOfArguments, const char *arguments[], const char *environment[]) noexcept
 
static void setArgumentsAndEnvironment (int numberOfArguments, const char *arguments[], const char *environment[]=nullptr)
 

Detailed Description

Application.

This is a singleton object for the context of the application. User-defined exit codes should start from EXIT_CODE_USER.

Example:

class MyApplication : public Application {
public:
MyApplication()
: Application("MyApplication")
{
}
void main()
{
// ...
}
};
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.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ Application()

Application::Application ( const String name)

Initializes application with no arguments and no environment variables.

Parameters
nameThe formal name.

◆ ~Application()

virtual Application::~Application ( )
virtualnoexcept

Destroys the application object.

Member Function Documentation

◆ error()

void Application::error ( const String text,
int  exitCode = EXIT_CODE_INVALID 
)

Writes error to stderr. Only intended for console apps. Only sets exit code is not equal to EXIT_CODE_INVALID.

Parameters
textThe error message.
exitCodeThe 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()

static Application* Application::getApplication ( )
staticnoexcept

Returns the application object.

Examples
testsuite/IEEE1394.cpp.

◆ getArguments()

const Array<String>& Application::getArguments ( ) const
inlinenoexcept

Returns the arguments passed to the application.

◆ getEnvironment()

const Map<String, String>& Application::getEnvironment ( ) const
inlinenoexcept

Returns the environment variables.

◆ getExitCode()

int Application::getExitCode ( ) const
inlinenoexcept

Returns the exit code.

◆ getFormalName()

const String& Application::getFormalName ( ) const
inlinenoexcept

Returns the formal name of the application.

◆ getLock()

static MutualExclusion& Application::getLock ( )
staticnoexcept

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
valueThe 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

Application stub.

◆ terminate()

void Application::terminate ( )
noexcept

Signals the application to terminate itself.

Application::main
virtual void main()=0
Application
Application.
Definition: Application.h:53