3.5.1 Writing the Methods That Implement the Operations for Each Interface

After you compile the OMG IDL file, you require to write methods that implement the operations for each interface in the file. An implementation file contains the following:

  • Method declarations for each operation specified in the OMG IDL file
  • Your application’s business logic
  • Constructors for each interface implementation (implementing these is optional)
  • The activate_object() and deactivate_object() methods (optional)

    Within the activate_object() and deactivate_object() methods, you write code that performs any particular steps related to activating or deactivating the object. For more information, see Creating CORBA Server Applications in the Oracle Tuxedo online documentation.

You can write the implementation file manually. The idl command provides an option for generating a template for implementation files.

The following code snippet illustrates the C++ implementation of the Simple and SimpleFactory interfaces in the Simpapp sample application.

// Implementation of the Simple_i::to_lower method which converts
// a string to lower case.

char * Simple_i::to_lower(const char * value) {
  CORBA::String_var var_lower = CORBA::string_dup(value);
  for (char * ptr = var_lower; ptr && * ptr; ptr++) {
    * ptr = tolower( * ptr);
  }
  return var_lower._retn();
}
// Implementation of the Simple_i::to_upper method which converts
// a string to upper case.

void Simple_i::to_upper(char * & valuel) {
  CORBA::String_var var_upper = value1;
  var_upper = CORBA::string_dup(var_upper.in());
  for (char * ptr = var_upper; ptr && * ptr; ptr++) {
    * ptr = toupper( * ptr);
  }
  value = var_upper._retn();
}
// Implementation of the SimpleFactory_i::find_simple method which
// creates an object reference to a Simple object.

Simple_ptr SimpleFactory_i::find_simple() {
  CORBA::Object_var var_simple_oref =
    TP::create_object_reference(
      _tc_Simple - > id(),
      "simple",
      CORBA::NVList::_nil()
    );
}