[Enterprise Extensions only]
Previous topic Next topic

Adding code to a CORBA servant implementation (servant_I.cpp)

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

To add code to an implementation file,servant_I.cpp, to add the business logic that the servant is to provide, complete the following steps:

  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 converted the following interface declaration to the skeleton methods in the implementation file, WSLogger_I.cpp. The WSLogger_I.cpp file was then edited to add the code to implement the methods, with the code added for the WSLogger_Impl::writeLogMessage method shown in bold.
    ::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 ()
    {
    }
    

You can next create the server main code (server.cpp), to implement the server, as described in Creating a CORBA server main code (server.cpp).

This task is one step of the parent task, Developing a CORBA server.

Previous topic Next topic