3.5.2 Creating the CORBA server Object
The Server object performs the following tasks:
- Initializes the CORBA server application, including registering factories, allocating resources required by the CORBA server application, and, if necessary, opening an XA resource manager.
- Performs CORBA server application shutdown and cleanup procedures.
- Instantiates CORBA objects required to satisfy CORBA client requests.
In CORBA server applications, the Server object is already instantiated and a header file for the Server object is available. You implement methods that initialize and release the server application, and, if desired, create servant objects.
The following code snippet includes the C++ code from the Simpapp sample application for the Server object.
static CORBA::Object_var static_var_factory_reference;
// Method to start up the server
CORBA::Boolean
Server::initialize (int argc, char *argv[])
{
// Create the Factory Object Reference
static_var_factory_reference = TP::create_object_reference (
_tc_SimpleFactory->id (), "simple_factory", CORBA::NVList::_nil ());
// Register the factory reference with the FactoryFinder
TP::register_factory (static_var_factory_reference.in (),
_tc_SimpleFactory->id ());
return CORBA_TRUE;
}
// Method to shutdown the server
void
Server::release ()
{
// Unregister the factory.
try
{
TP::unregister_factory (static_var_factory_reference.in (),
_tc_SimpleFactory->id ());
}
catch (...)
{
TP::userlog ("Couldn't unregister the SimpleFactory");
}
}
// Method to create servants
Tobj_Servant
Server::create_servant (const char *interface_repository_id)
{
if (!strcmp (interface_repository_id, _tc_SimpleFactory->id ()))
{
return new SimpleFactory_i ();
}
if (!strcmp (interface_repository_id, _tc_Simple->id ()))
{
return new Simple_i ();
}
return 0;
}
Parent topic: Step 3: Write the CORBA Server Application