[Enterprise Extensions only]
  Previous topic

Creating CORBA client main code (client.cpp), adding code to check input parameters

Use this task to add code to the source file for a CORBA client, to check input parameters. This code is used to check the parameters that a user specifies when starting the CORBA client.

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).

This examples in this task are based on a CORBA client that is started by the following command:

client log_file_name iterations
Where:
client
is the name of the client program.
log_file_name
is the the full pathname of a log file used to record actions by the client.
iterations
is the number of times that the client code should be run when the client program is started.

The code checks that the command used to start the CORBA client specifies two arguments required.

To add code to check the input parameters to the source file for a CORBA client main code, complete the following steps::

  1. Edit the client source file, client.cpp, and add the following code:
    main(int argc, char *argv[])
    {
      int rc;
      ::CORBA::Object_ptr objPtr;
      ::CosNaming::NamingContext_var rootNameContext = NULL;
      servant_var liptr = NULL;
    
      if ( argc != 3 )
      {
        cerr << "Usage: client <log_file_name> <iterations>" << endl;
        exit( -1 );
      }
      else
      {
        cout << "Entered client with log file name = " << argv[1];
        cout << " and iteration count = " << argv[2] << endl;
      }
    
      if ( ( rc = perform_initialization( argc, argv ) ) != 0 )
        exit( rc );
    

    Where the client program name and arguments are as specified above.

This task adds code to check input parameters to the main method in the source file for a CORBA client.

You need to add code to the client source file to initialize the client environment, as described in Creating a CORBA client main code (client.cpp), adding code to initialize the client environment.

  Previous topic