The main entry point to the Ice run time is represented by the local interface ICECommunicator. As for the client side, you must initialize the Ice run time by calling
createCommunicator (a class method of the
ICEUtil class) before you can do anything else in your server.
createCommunicator returns an instance of type
id<ICECommunicator>:
createCommunicator accepts a
pointer to
argc as well as
argv. The class method scans the argument vector for any command-line options that are relevant to the Ice run time; any such options are removed from the argument vector so, when
createCommunicator returns, the only options and arguments remaining are those that concern your application. If anything goes wrong during initialization,
createCommunicator throws an exception.
Before leaving your main function, you
must call
Communicator::destroy. The
destroy operation is responsible for finalizing the Ice run time. In particular,
destroy waits for any operation implementations that are still executing in the server to complete. In addition,
destroy ensures that any outstanding threads are joined with and reclaims a number of operating system resources, such as file descriptors and memory. Never allow your
main function to terminate without calling
destroy first; doing so has undefined behavior.
The general shape of our server-side main function is therefore as follows:
Note that the code places the call to createCommunicator into a
try block and takes care to return the correct exit status to the operating system. Also note that the code creates and releases an autorelease pool. This ensures that memory will be released before the program terminates.
The catch handler for
NSException ensures that the communicator is destroyed regardless of whether the program terminates normally or due to an exception.
You must not release the communicator that is returned by
createCommunicator. As for any operation that returns a pointer, the Ice run time calls
autorelease on the returned instance, so you do not have to release it yourself.
1
createCommunicator is provided in several versions that accept different arguments. Here is the complete list:
The initData argument is of type
ICEInitializationData. Even though it has no Slice definition, this class behaves as if it were a Slice structure with the following definition:
The properties member allows you to explicitly set property values for the communicator to be created. This is useful, for example, if you want to ensure that a particular property setting is always used by the communicator. (See
Chapter 30 for more information.)
The logger member sets the logger that the Ice run time uses to log messages. If you do not set a logger (leaving the
logger member as
nil), the run time installs a default logger that calls
NSLog to log messages. (See
Section 32.20 for more information on loggers.)