[Enterprise Extensions only]
  Previous topic

Creating CORBA server main code (server.cpp), adding code to put the server into a loop to service requests

Use this task to add code to the source file for a CORBA server, to put the server into an infinite loop during which the ORB can transmit requests to and from the servant object hosted by the server.

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 code to put the server into an infinite loop, edit the server source file, servantServer.cpp, and add the following code:

  1. Add code to the main method to call a method to start the loop. There are several ways to do this, including calling the execute_request_loop() execute_next_request methods.This method should be called only after CORBA::BOA::impl_is_ready has been called successfully. The following example code extract shows the use of the execute_request_loop() method; in this example, a block wait is specified by CORBA::BOA::SOMD_WAIT:
    void main( int argc, char *argv[] )
    {
    ...
      // Initialize this application as a server, ...
      try
      {
        bp->impl_is_ready( imp, 0 );
      }
    
    ...
      cout << "Created ServerShutdown object" << endl;
     
      cout << endl;
      cout << "server listening...." << endl << endl;
      cout.flush();
     
      // Go into an infinite loop, servicing ORB requests as they are
      // received. execute_request_loop() will return when an external command,
      // StopServer, is executed. 
    
      stat = bp-<;gt;execute_request_loop( ::CORBA::BOA::SOMD_WAIT );
    
    
      cout << "execute_request_loop has returned!" << endl;
    
      // Terminate the server.
    ...
    
    }

This task adds code that puts a CORBA server into a loop during which it can service requests for the servant object that it hosts.

You need to add code to the server source file to enable the server to complete the server shutdown when requested, as described in Creating CORBA server main code (server.cpp), adding code to shutdown the server and release resources used.

  Previous topic