![]() |
|
Use this task to add a server initialization method to the source file for a CORBA server. This code is used to perform the initialization tasks needed when the server is started.
The aim of the server initialization method is to complete the following tasks to initialize the server environment:
This task is one step of the parent task to create the CORBA server main code, as described in Creating a CORBA server main code (server.cpp).
To add a server initialization method to the source file for a CORBA server main code, edit the server source file, servantServer.cpp, and add the following code:
// This function performs general initializtion, including retrieval // of the appropriate ImplementationDef, setting the communications // protocol, and initalization of the ORB and BOA. int perform_initialization( int argc, char *argv[] ) { return( 0 ); } void main( int argc, char *argv[] ) { ::CORBA::Object_ptr objPtr; ::CORBA::Status stat; int rc = 0; // Validate the input parameters. if ( argc != 2 ) { cerr << "Usage: WSLoggerServer <server_alias>" << endl; exit( -1 ); } if ( ( rc = perform_initialization( argc, argv ) ) != 0 ) exit( rc ); ... }
Where:
int perform_initialization( int argc, char *argv[] ) { // Initialize the server's Implementation Repository. ::CORBA::ImplRepository_ptr implrep = new ::CORBA::ImplRepository(); // Retrieve the appropriate ImplementationDef by using the server alias. try { imp = implrep->find_impldef_by_alias( argv[1] ); } // catch exceptions ... cout << "Retrieved ImplementationDef" << endl; ... }
int perform_initialization( int argc, char *argv[] ) { ... cout << "Retrieved ImplementationDef" << endl; // Set the server's communication protocol. imp->set_protocols("SOMD_TCPIP"); cout << "Set communication protocol" << endl; ... }
int perform_initialization( int argc, char *argv[] ) { ... cout << "Set communication protocol" << endl; ... // Initialize the ORB. op = ::CORBA::ORB_init(argc, argv, "DSOM"); // Initialize the BOA. try { bp = op->BOA_init(argc, argv, "DSOM_BOA"); } // catch exceptions ... cout << "Initialized ORB" << endl; ... }
int perform_initialization( int argc, char *argv[] ) { ... cout << "Initialized ORB" << endl; // Initialize this application as a server, allow it to accept // incoming request messages, and register it with the somorbd // daemon. try { bp->impl_is_ready( imp, 0 ); } // catch exceptions ... cout << "Finished initialization of implementation" << endl; return( 0 ); }
This enables the server to accept incoming request messages, and registers it with the somorbd daemon.
This task adds code to initialize the server environment for a CORBA server.
You need to add code to the server source file to enable the server to access naming contexts, as described in Adding code to access naming contexts to a CORBA server main code (server.cpp).
![]() |