Completing the CORBA servant implementation (servant_I.cpp)

Why and when to perform this task

Use this task to add code for a CORBA server implementation class to its skeleton implementation file, servant_I.cpp. The code defines the methods that implement the business logic for the server implementation class, servant.

This task follows the task to add declarations for class variables, constructors, and destructors to the servant implementation header file, servant.ih. For more information about adding declarations to an implementation header, see Adding declarations to a CORBA servant implementation header (servant.ih).

Steps for this task

  1. At a command line, change to the directory that contains the servant_I.cpp file, where servant is the name of the server implementation class.
  2. Edit the implementation file, servant_I.cpp, to add appropriate code to implement the business logic methods.
    For example, the idlc command, idlc -ehh:ih:ic:uc:sc -mdllname=WSLogger WSLogger.idl, converts the following interface declaration to the skeleton methods in the implementation file, WSLogger_I.cpp. The WSLogger_I.cpp file was edited to add the code to implement the methods. The code added for the WSLogger_Impl::writeLogMessage method is shown in bold in the following example:
    ::CORBA::Void WSLogger_Impl::setFileName (const char* newFileName)
    {
    }
    
    char*  WSLogger_Impl::getFileName ()
    {
    }
    
    ::CORBA::Void WSLogger_Impl::setMethodName (const char* newMethodName)
    {
    }
    
    char*  WSLogger_Impl::getMethodName ()
    {
    }
    
    ::CORBA::Short WSLogger_Impl::openLogFile ()
    {
    }
    
    ::CORBA::Short WSLogger_Impl::closeLogFile ()
    {
    }
    
    // This method writes one line of message text to the log file. The line
    // prefaced with the current date and time in the currently specified
    // format, the current method name (if any), the severity level, and
    // the message text.
    
    ::CORBA::Short WSLogger_Impl::writeLogMessage (const char* newMessage, ::CORBA::Short newSeverity)
    {
      ::CORBA::String_var timeString;
    
      if ( logFileOpen == FALSE )
        return( -1 );
      // Get the date and time string.
      time_t tp;
      time_t tp2;
      if ( ( tp = time(&tp2) ) != -1 )
      {
        struct tm *x = gmtime( &tp2 );
        timeString = ::CORBA::string_dup( ctime( &tp2 ) );
      }
    
      // Determine the day and month.
      ::CORBA::String_var day = ::CORBA::string_alloc( 3 );
      ::CORBA::String_var month = ::CORBA::string_alloc( 4 );
      day[0] = timeString[8];
      day[1] = timeString[9];
      day[2] = 0;
      month[0] = timeString[4];
      month[1] = timeString[5];
      month[2] = timeString[6];
      month[3] = 0;
    
      // Copy the time and year.
      ::CORBA::String_var time = ::CORBA::string_alloc( 14 );
      strncpy( time, (const char *) &timeString[11], 13 );
      time[13] = 0;
    
      // Output the time of the log message.
      if ( dateFormat == DMY_DATE_FORMAT )
        logFile << day << " " << month;
      else if ( dateFormat == MDY_DATE_FORMAT )
        logFile << month << " " << day;
      logFile << " " << time << ", ";
    
      if ( getMethodName() != NULL )
        logFile << getMethodName() << ", ";
    
      logFile << "severity " << newSeverity << ": ";
    
      // Output the log message.
      logFile << newMessage << endl;
    
      return 0;
    }
    
    ::CORBA::Void WSLogger_Impl::setDateFormat (::CORBA::UShort newDateFormat)
    {
    }
    
    ::CORBA::UShort WSLogger_Impl::getDateFormat ()
    {
    }
    

What to do next

Create the server main code (server.cpp), to implement the server as described in Creating a CORBA server main code (server.cpp).

Related tasks
Developing a CORBA C++ server
Adding declarations to a CORBA servant class definition (servant.ih)
Creating the CORBA server main code (server.cpp)



Searchable topic ID:   tcor_pgms4
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_pgms4.html

Library | Support | Terms of Use | Feedback