Ice 3.7 C++11 API Reference
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
Ice::Application Class Referenceabstract

Singleton helper class that simplifies Ice initialization, finalization and signal handling. More...

#include <Ice/Ice.h>

Inheritance diagram for Ice::Application:
Inheritance graph
[legend]
Collaboration diagram for Ice::Application:
Collaboration graph
[legend]

Public Member Functions

 Application (SignalPolicy policy=SignalPolicy ::HandleSignals)
 The constructor configures the signal handling behavior. More...
 
virtual void interruptCallback (int signal)
 Override this method to provide a custom application interrupt hook. More...
 
int main (const StringSeq &args, const InitializationData &initData=InitializationData(), int version=30710)
 Call this main() from the global main(). More...
 
int main (const StringSeq &args, const std::string &configFile, int version=30710)
 Call this main() from the global main(). More...
 
int main (int argc, const char *const argv[], const InitializationData &initData=InitializationData(), int version=30710)
 Call this main() from the global main(). More...
 
int main (int argc, const char *const argv[], const std::string &configFile, int version=30710)
 Call this main() from the global main(). More...
 
virtual int run (int argc, char *argv[])=0
 run is given a copy of the remaining argc/argv arguments, after the communicator initialization in the caller (main) has removed all Ice-related arguments. More...
 
virtual ~Application ()
 

Static Public Member Functions

static const char * appName ()
 Obtains the application name, i.e., argv[0]. More...
 
static void callbackOnInterrupt ()
 Configures the application to invoke interruptCallback when a signal occurs, thereby giving the subclass responsibility for handling the signal. More...
 
static CommunicatorPtr communicator ()
 Obtains the application's Communicator instance. More...
 
static void destroyOnInterrupt ()
 Configures the application to destroy the communicator when one of the monitored signals is raised. More...
 
static void holdInterrupt ()
 Configures the application to ignore (but remember) a signal. More...
 
static void ignoreInterrupt ()
 Configures the application to ignore signals. More...
 
static bool interrupted ()
 Indicates whether a signal handler was triggered. More...
 
static void releaseInterrupt ()
 Processes a stored signal (if any) using the current signal handling configuration. More...
 
static void shutdownOnInterrupt ()
 Configures the application to shut down the communicator when one of the monitored signals is raised. More...
 

Protected Member Functions

virtual int doMain (int, char *[], const InitializationData &, Int)
 Helper function that implements the application logic. More...
 

Static Protected Attributes

static Application_application
 The singleton instance. More...
 
static std::string _appName
 The application's name. More...
 
static bool _callbackInProgress
 True if a signal handling callback is currently executing. More...
 
static CommunicatorPtr _communicator
 The application's communicator. More...
 
static IceUtil::Cond _condVar
 Used to synchronize the main thread and the CtrlCHandler thread. More...
 
static bool _destroyed
 True if the communicator has been destroyed. More...
 
static bool _interrupted
 True if an interrupt signal was received. More...
 
static IceUtil::Mutex _mutex
 Used to synchronize the main thread and the CtrlCHandler thread. More...
 
static SignalPolicy _signalPolicy
 The signal-handling policy specified at construction. More...
 

Detailed Description

Singleton helper class that simplifies Ice initialization, finalization and signal handling.

An application uses this class by writing a subclass and implementing the run method.

Constructor & Destructor Documentation

◆ Application()

Ice::Application::Application ( SignalPolicy  policy = SignalPolicy ::HandleSignals)

The constructor configures the signal handling behavior.

Parameters
policySpecifies whether to handle signals. If not specified, the default behavior is to handle signals.

◆ ~Application()

virtual Ice::Application::~Application ( )
virtual

Member Function Documentation

◆ appName()

static const char* Ice::Application::appName ( )
static

Obtains the application name, i.e., argv[0].

Returns
The application's name.

◆ callbackOnInterrupt()

static void Ice::Application::callbackOnInterrupt ( )
static

Configures the application to invoke interruptCallback when a signal occurs, thereby giving the subclass responsibility for handling the signal.

◆ communicator()

static CommunicatorPtr Ice::Application::communicator ( )
static

Obtains the application's Communicator instance.

One limitation of this class is that there can only be one Application instance, with one global Communicator, accessible with this communicator() operation. This limitation is due to how the signal handling functions below operate. If you require multiple Communicators, then you cannot use this Application framework class.

Returns
The application's communicator.

◆ destroyOnInterrupt()

static void Ice::Application::destroyOnInterrupt ( )
static

Configures the application to destroy the communicator when one of the monitored signals is raised.

This is the default behavior.

◆ doMain()

virtual int Ice::Application::doMain ( int  ,
char *  [],
const InitializationData ,
Int   
)
protectedvirtual

Helper function that implements the application logic.

Reimplemented in Glacier2::Application.

◆ holdInterrupt()

static void Ice::Application::holdInterrupt ( )
static

Configures the application to ignore (but remember) a signal.

A stored signal (if any) can be handled later by calling releaseInterrupt.

◆ ignoreInterrupt()

static void Ice::Application::ignoreInterrupt ( )
static

Configures the application to ignore signals.

◆ interruptCallback()

virtual void Ice::Application::interruptCallback ( int  signal)
virtual

Override this method to provide a custom application interrupt hook.

You must call callbackOnInterrupt for this method to be called. Note that the interruptCallback can be called concurrently with any other thread (including main) in your application and thus must take appropriate concurrency precautions.

Parameters
signalThe signal identifier.

◆ interrupted()

static bool Ice::Application::interrupted ( )
static

Indicates whether a signal handler was triggered.

This can be used once Communicator::waitForShutdown() returns to test whether the shutdown was due to an interrupt (returns true) or because Communicator::shutdown() was called (returns false).

Returns
True if a signal handler was triggered, false otherwise.

◆ main() [1/4]

int Ice::Application::main ( const StringSeq args,
const InitializationData initData = InitializationData(),
int  version = 30710 
)

Call this main() from the global main().

main() initializes the Communicator, calls run() and destroys the the Communicator upon return from run(). It handles all exceptions properly, i.e., error message are printed if exceptions propagate to main(), and the Communicator is always destroyed, regardless of exceptions.

Parameters
argsThe command-line arguments.
initDataConfiguration data for the new Communicator.
versionIndicates the Ice version with which the application is compatible. If not specified, the version of the Ice installation is used.
Returns
The application's exit status.

◆ main() [2/4]

int Ice::Application::main ( const StringSeq args,
const std::string &  configFile,
int  version = 30710 
)

Call this main() from the global main().

main() initializes the Communicator, calls run() and destroys the the Communicator upon return from run(). It handles all exceptions properly, i.e., error message are printed if exceptions propagate to main(), and the Communicator is always destroyed, regardless of exceptions.

Parameters
argsThe command-line arguments.
configFileThe name of an Ice configuration file.
versionIndicates the Ice version with which the application is compatible. If not specified, the version of the Ice installation is used.
Returns
The application's exit status.

◆ main() [3/4]

int Ice::Application::main ( int  argc,
const char *const  argv[],
const InitializationData initData = InitializationData(),
int  version = 30710 
)

Call this main() from the global main().

main() initializes the Communicator, calls run() and destroys the the Communicator upon return from run(). It handles all exceptions properly, i.e., error message are printed if exceptions propagate to main(), and the Communicator is always destroyed, regardless of exceptions.

Parameters
argcSpecifies the number of arguments in argv.
argvThe command-line arguments.
initDataConfiguration data for the new Communicator.
versionIndicates the Ice version with which the application is compatible. If not specified, the version of the Ice installation is used.
Returns
The application's exit status.

◆ main() [4/4]

int Ice::Application::main ( int  argc,
const char *const  argv[],
const std::string &  configFile,
int  version = 30710 
)

Call this main() from the global main().

main() initializes the Communicator, calls run() and destroys the the Communicator upon return from run(). It handles all exceptions properly, i.e., error message are printed if exceptions propagate to main(), and the Communicator is always destroyed, regardless of exceptions.

Parameters
argcSpecifies the number of arguments in argv.
argvThe command-line arguments.
configFileThe name of an Ice configuration file.
versionIndicates the Ice version with which the application is compatible. If not specified, the version of the Ice installation is used.
Returns
The application's exit status.

◆ releaseInterrupt()

static void Ice::Application::releaseInterrupt ( )
static

Processes a stored signal (if any) using the current signal handling configuration.

◆ run()

virtual int Ice::Application::run ( int  argc,
char *  argv[] 
)
pure virtual

run is given a copy of the remaining argc/argv arguments, after the communicator initialization in the caller (main) has removed all Ice-related arguments.

Parameters
argcSpecifies the number of arguments in argv.
argvThe command-line arguments.
Returns
The application's exit status.

◆ shutdownOnInterrupt()

static void Ice::Application::shutdownOnInterrupt ( )
static

Configures the application to shut down the communicator when one of the monitored signals is raised.

Member Data Documentation

◆ _application

Application* Ice::Application::_application
staticprotected

The singleton instance.

Immutable during run() and until communicator->destroy() has returned. Before and after run(), and once communicator->destroy() has returned, we assume that only the main thread and CtrlCHandler threads are running.

◆ _appName

std::string Ice::Application::_appName
staticprotected

The application's name.

Immutable during run() and until communicator->destroy() has returned. Before and after run(), and once communicator->destroy() has returned, we assume that only the main thread and CtrlCHandler threads are running.

◆ _callbackInProgress

bool Ice::Application::_callbackInProgress
staticprotected

True if a signal handling callback is currently executing.

Can change while run() and communicator->destroy() are running!

◆ _communicator

CommunicatorPtr Ice::Application::_communicator
staticprotected

The application's communicator.

Immutable during run() and until communicator->destroy() has returned. Before and after run(), and once communicator->destroy() has returned, we assume that only the main thread and CtrlCHandler threads are running.

◆ _condVar

IceUtil::Cond Ice::Application::_condVar
staticprotected

Used to synchronize the main thread and the CtrlCHandler thread.

◆ _destroyed

bool Ice::Application::_destroyed
staticprotected

True if the communicator has been destroyed.

Can change while run() and communicator->destroy() are running!

◆ _interrupted

bool Ice::Application::_interrupted
staticprotected

True if an interrupt signal was received.

Can change while run() and communicator->destroy() are running!

◆ _mutex

IceUtil::Mutex Ice::Application::_mutex
staticprotected

Used to synchronize the main thread and the CtrlCHandler thread.

◆ _signalPolicy

SignalPolicy Ice::Application::_signalPolicy
staticprotected

The signal-handling policy specified at construction.

Immutable during run() and until communicator->destroy() has returned. Before and after run(), and once communicator->destroy() has returned, we assume that only the main thread and CtrlCHandler threads are running.


The documentation for this class was generated from the following file: