Creating and binding servant objects

Why and when to perform this task

Use this task to add code to the source file for a CORBA server to create servant objects, and bind them into the appropriate naming context. This makes it possible for clients to find and use servant objects.

To add code to create and bind servant objects, edit the server source file, servantServer.cpp, and add the following code:

int bind_object ( 
   ::CORBA::Object_ptr objPtr,
   ::CosNaming::Name &name, 
   ::CosNaming::NamingContext_ptr servantNameContext
   )
{
   try
   {
      servantNameContext->bind ( name, objPtr );
   
      cout << "The servant object was bound successfully into the name space." << endl;
   }
   // catch exceptions

   return 0;
}

Next, modify the main() function so that it creates the servant object and calls the bind_object() function:

int main ( int argc, char *argv[] )
{
   .
   . initialization code
   .

   // Get the servant naming context.
   ::CosNaming::NamingContext_var servantNameContext = get_naming_context ( orbPtr );
   if ( servantNameContext == NULL )
   {
      return 4;
   }

   // Create the servant object.
   // This is the object that will be used by the client.
   servantImpl *servantObject = new servantImpl();

   // Create the CosNaming::Name for our object.
   ::CosNaming::Name name;
   name[0].kind = ::CORBA::string_dup("");
   name[0].id   = ::CORBA::string_dup("servantObject1");

   // Next, bind the servant object into the servant naming context.
   rc = bind_object ( servantObject, name, servantNameContext );
   if ( rc != 0 )
   {
      cerr << "Error: could not bind servant object into name space." << endl;
      return 5;
   }

   . 
   . 
   . 
} 

Results

This task adds code that enables a CORBA server to create and bind servant objects.

What to do next

Add code to the server source file to enable the server to create a server shut down object that can be used to help shut down the server as described in Adding code to create a server shutdown object.

Related tasks
Creating the CORBA server main code (server.cpp)



Searchable topic ID:   tcor_pgmse
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/tasks/tcor_pgms5e.html

Library | Support | Terms of Use | Feedback