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

A singleton class comparable to Ice::Application but also provides the low-level, platform-specific initialization and shutdown procedures common to system services. More...

#include <Ice/Ice.h>

Public Member Functions

bool checkSystem () const
 Determines whether the operating system supports running the program as a Win32 service or Unix daemon. More...
 
Ice::CommunicatorPtr communicator () const
 Obtains the communicator created by the service. More...
 
void configureDaemon (bool changeDirectory, bool closeFiles, const std::string &pidFile)
 Configures the program to run as a Unix daemon. More...
 
virtual void handleInterrupt (int sig)
 Invoked by the signal handler when it catches a signal. More...
 
virtual void interrupt ()
 Notify the service about a signal interrupt. More...
 
int main (const StringSeq &args, const InitializationData &initData=InitializationData(), int version=30710)
 The primary entry point for services. More...
 
int main (int argc, const char *const argv[], const InitializationData &initData=InitializationData(), int version=30710)
 The primary entry point for services. More...
 
std::string name () const
 Obtains the program name. More...
 
int run (int argc, const char *const argv[], const InitializationData &initData=InitializationData(), int version=30710)
 Alternative entry point for services that use their own command-line options. More...
 
 Service ()
 
bool service () const
 Indicates whether the program is running as a Win32 service or Unix daemon. More...
 
virtual bool shutdown ()
 Shutdown the service. More...
 
virtual ~Service ()
 

Static Public Member Functions

static Serviceinstance ()
 Obtains the Service singleton. More...
 

Protected Types

typedef LoggerOutput< Service, Service *, &Service::errorServiceError
 Logger utility class for an error. More...
 
typedef LoggerOutput< Service, Service *, &Service::printServicePrint
 Logger utility class for a literal message. More...
 
typedef LoggerOutput< Service, Service *, &Service::syserrorServiceSysError
 Logger utility class for a system error. More...
 
typedef LoggerOutput< Service, Service *, &Service::traceServiceTrace
 Logger utility class for a trace message. More...
 
typedef LoggerOutput< Service, Service *, &Service::warningServiceWarning
 Logger utility class for a warning. More...
 

Protected Member Functions

void disableInterrupt ()
 Ignore signals. More...
 
void enableInterrupt ()
 Enables the signal handler to invoke interrupt() when a signal occurs. More...
 
virtual void error (const std::string &msg)
 Logs an error. More...
 
virtual Ice::CommunicatorPtr initializeCommunicator (int &argc, char *argv[], const InitializationData &initData, int version)
 Initializes a communicator. More...
 
virtual void print (const std::string &msg)
 Logs a literal message. More...
 
virtual bool start (int argc, char *argv[], int &status)=0
 Prepares a service for execution, including the creation and activation of object adapters and servants. More...
 
virtual bool stop ()
 Cleans up resources after shutting down. More...
 
virtual void syserror (const std::string &msg)
 Logs a system error, which includes a description of the current system error code. More...
 
virtual void trace (const std::string &msg)
 Logs trace information. More...
 
virtual void waitForShutdown ()
 Blocks until the service shuts down. More...
 
virtual void warning (const std::string &msg)
 Logs a warning. More...
 

Detailed Description

A singleton class comparable to Ice::Application but also provides the low-level, platform-specific initialization and shutdown procedures common to system services.

Member Typedef Documentation

◆ ServiceError

Logger utility class for an error.

◆ ServicePrint

Logger utility class for a literal message.

◆ ServiceSysError

Logger utility class for a system error.

◆ ServiceTrace

Logger utility class for a trace message.

◆ ServiceWarning

Logger utility class for a warning.

Constructor & Destructor Documentation

◆ Service()

Ice::Service::Service ( )

◆ ~Service()

virtual Ice::Service::~Service ( )
virtual

Member Function Documentation

◆ checkSystem()

bool Ice::Service::checkSystem ( ) const

Determines whether the operating system supports running the program as a Win32 service or Unix daemon.

Returns
True if the system supports services, false otherwise.

◆ communicator()

Ice::CommunicatorPtr Ice::Service::communicator ( ) const

Obtains the communicator created by the service.

Returns
The service's communicator.

◆ configureDaemon()

void Ice::Service::configureDaemon ( bool  changeDirectory,
bool  closeFiles,
const std::string &  pidFile 
)

Configures the program to run as a Unix daemon.

The first argument indicates whether the daemon should change its working directory to the root directory. The second argument indicates whether extraneous file descriptors are closed. If the value of the last argument is not an empty string, the daemon writes its process ID to the given filename.

Parameters
changeDirectoryTrue if the daemon should change its working directory to the root directory, false otherwise.
closeFilesTrue if the daemon should close unnecessary file descriptors (i.e., stdin, stdout, etc.), false otherwise.
pidFileIf a non-empty string is provided, the daemon writes its process ID to the given file.

◆ disableInterrupt()

void Ice::Service::disableInterrupt ( )
protected

Ignore signals.

◆ enableInterrupt()

void Ice::Service::enableInterrupt ( )
protected

Enables the signal handler to invoke interrupt() when a signal occurs.

◆ error()

virtual void Ice::Service::error ( const std::string &  msg)
protectedvirtual

Logs an error.

Parameters
msgThe log message.

◆ handleInterrupt()

virtual void Ice::Service::handleInterrupt ( int  sig)
virtual

Invoked by the signal handler when it catches a signal.

Parameters
sigThe signal that was caught.

◆ initializeCommunicator()

virtual Ice::CommunicatorPtr Ice::Service::initializeCommunicator ( int &  argc,
char *  argv[],
const InitializationData initData,
int  version 
)
protectedvirtual

Initializes a communicator.

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 new communicator instance.

◆ instance()

static Service* Ice::Service::instance ( )
static

Obtains the Service singleton.

Returns
A pointer to this service.

◆ interrupt()

virtual void Ice::Service::interrupt ( )
virtual

Notify the service about a signal interrupt.

The default implementation invokes shutdown().

◆ main() [1/2]

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

The primary entry point for services.

This function examines the given argument vector for reserved options and takes the appropriate action. The reserved options are shown below.

Win32:

–service NAME

Unix:

–daemon [–nochdir] [–noclose]

If –service or –daemon are specified, the program runs as a service, otherwise the program runs as a regular foreground process. Any service-specific (and Ice-specific) options are stripped from argv (just as for Ice::initialize()).

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: EXIT_FAILURE or EXIT_SUCCESS.

◆ main() [2/2]

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

The primary entry point for services.

This function examines the given argument vector for reserved options and takes the appropriate action. The reserved options are shown below.

Win32:

–service NAME

Unix:

–daemon [–nochdir] [–noclose]

If –service or –daemon are specified, the program runs as a service, otherwise the program runs as a regular foreground process. Any service-specific (and Ice-specific) options are stripped from argv (just as for Ice::initialize()).

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: EXIT_FAILURE or EXIT_SUCCESS.

◆ name()

std::string Ice::Service::name ( ) const

Obtains the program name.

If the program is running as a Win32 service, the return value is the service name. Otherwise the return value is the executable name (i.e., argv[0]).

Returns
The service name.

◆ print()

virtual void Ice::Service::print ( const std::string &  msg)
protectedvirtual

Logs a literal message.

Parameters
msgThe log message.

◆ run()

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

Alternative entry point for services that use their own command-line options.

Instead of invoking main(), the program processes its command-line options and invokes run(). To run as a Win32 service or Unix daemon, the program must first invoke configureService() or configureDaemon(), respectively.

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: EXIT_FAILURE or EXIT_SUCCESS.

◆ service()

bool Ice::Service::service ( ) const

Indicates whether the program is running as a Win32 service or Unix daemon.

Returns
True if the program is running as a service, false otherwise.

◆ shutdown()

virtual bool Ice::Service::shutdown ( )
virtual

Shutdown the service.

The default implementation invokes shutdown() on the communicator.

◆ start()

virtual bool Ice::Service::start ( int  argc,
char *  argv[],
int &  status 
)
protectedpure virtual

Prepares a service for execution, including the creation and activation of object adapters and servants.

Parameters
argcSpecifies the number of arguments in argv.
argvThe command-line arguments.
statusThe exit status, which is returned by main
Returns
True if startup was successful, false otherwise.

◆ stop()

virtual bool Ice::Service::stop ( )
protectedvirtual

Cleans up resources after shutting down.

◆ syserror()

virtual void Ice::Service::syserror ( const std::string &  msg)
protectedvirtual

Logs a system error, which includes a description of the current system error code.

Parameters
msgThe log message.

◆ trace()

virtual void Ice::Service::trace ( const std::string &  msg)
protectedvirtual

Logs trace information.

Parameters
msgThe log message.

◆ waitForShutdown()

virtual void Ice::Service::waitForShutdown ( )
protectedvirtual

Blocks until the service shuts down.

The default implementation invokes waitForShutdown() on the communicator.

◆ warning()

virtual void Ice::Service::warning ( const std::string &  msg)
protectedvirtual

Logs a warning.

Parameters
msgThe log message.

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