![]() |
|
Use this task to add code to the source file for a CORBA client, to get access to the servant object that has already been created by the CORBA server and bound into the name space. The client code gets access to the servant object by creating a ::CosNaming::Name that specifies the full name of the object from the root naming context.
For the example code in this task, the CORBA server created the servant object called servantObject1 in a new context, servantContext, that is bound to the domain naming context, which in turn is bound to the root naming context. Therefore the full name for the servant object, from the root naming context, is domain.servantContext.servantObject1.
This task is one step of the parent task to create the CORBA client main code, as described in Creating a CORBA client main code (client.cpp).
To enable the client to get access to the servant object, edit the client source file, client.cpp, and add the following code:
// Get the root naming context. rootNameContext = get_naming_context(); if ( ::CORBA::is_nil( rootNameContext ) ) exit( -1 ); // Find the servant_Impl created by the server. Look up the // object using the complex name of domain.servantContext.servantObject1, // which is its full name from the root naming context, as created // by the server. try { // Create a new ::CosNaming::Name to pass to resolve(). // Construct it as the full three-part complex name. ::CosNaming::Name *servantName = new ::CosNaming::Name; servantName->length( 3 ); (*servantName)[0].id = ::CORBA::string_dup( "domain" ); (*servantName)[0].kind = ""; (*servantName)[1].id = ::CORBA::string_dup( "servantContext" ); (*servantName)[1].kind = ::CORBA::string_dup( "" ); (*servantName)[2].id = ::CORBA::string_dup( "servantObject1" ); (*servantName)[2].kind = ::CORBA::string_dup( "" ); ::CORBA::Object_ptr objPtr = rootNameContext->resolve( *servantName ); liptr = servant::_narrow( objPtr); cout << "After narrow, liptr = " << liptr << endl; } // catch exceptions ...
This task adds code that enables a CORBA client to find the specified servant object (created by a CORBA server) in the system name space.
You need to add code to the client source file to enable the client to call methods on the servant object, as described in Creating CORBA client main code (client.cpp), adding code to call methods on the servant object.
![]() |