Chapter 5. Creating a New Component from Scratch

$Revision: 1.26 $

$Date: 2006/08/23 16:21:28 $

Table of Contents

5.1. SIDL Component Class Specification
5.2. Generating Babel Server Code for the New Component
5.3. Implementing the New Component
5.4. Using Your New Component

In this exercise, you will put together what you've learned in the previous tasks to create a complete component from scratch. We will add to the list of function components by creating one that returns the cube of the argument. The new component class will be named functions.CubeFunction, and it will implement the function.FunctionPort interface (defined in $STUDENT_SRC/ports/sidl/function.sidl) just as the other function components do. The following procedures will guide you through writing the component in C++, though very little would change for if you wanted to implement it in another Babel-supported language. If you're looking for a C language example, try the functions.LinearFunction.

5.1.  SIDL Component Class Specification

In this step, we will define the function.CubeFunction SIDL class and build its XML repository representation

  1. Edit the file $STUDENT_SRC/components/sidl/functions.sidl, and add the definition of the class CubeFunction to the package functions

    package functions version 1.0 {
    
      class LinearFunction implements function.FunctionPort, 
                                      gov.cca.Component
      {
        // function.FunctionPort methods:
        double evaluate(in double x);
    
        // gov.cca.Component methods:
        void setServices(in gov.cca.Services servicesHandle) 
                                throws gov.cca.CCAException;
      }
    
    ... some definitions skipped ...
    
      class PiFunction implements-all function.FunctionPort, 
                                      gov.cca.Component
      {
      }
      class CubeFunction implements-all function.FunctionPort, 
                                        gov.cca.Component
      {
      }
    
    }
    

  2. Edit the file $STUDENT_SRC/components/MakeIncl.components to add a new component description in the COMPONENTS variable, which contains the list of components in this directory. Each value consists of the fully-qualified name of the component (including packages), to which we append "-language", where language is one of c, cxx, or f90. In this case, the name is functions.CubeFunction, and the language is cxx. The updated value of COMPONENTS should look like this:

    COMPONENTS = functions.PiFunction-cxx \
            integrators.MonteCarlo-f90 randomgens.RandNumGenerator-cxx \
            drivers.CXXDriver-cxx integrators.Midpoint-f90 \
            functions.CubeFunction-cxx
    

    Note the backslash (“\”) that has to be added in order to extend the entry to the next line.

  3. In the $STUDENT_SRC/components directory, run make .repository. This will re-generate the XML representation of the SIDL component class definitions (including the newly added class CubeFunction and store them in the $STUDENT_SRC/xml_repository directory so that all references can be easily resolved.

    The output from this step should look something like this:

    touch .sidl
    
    ### Generate XML for SIDL packages containing component declarations
    babel -t xml -R../xml_repository -R/san/cca/cca-tools_gcc_intelF90_PIC/share/cca-spec-babel-0_7_8-babel-0.10.10/xml -o ../xml_repository sidl/drivers.sidl sidl/functions.sidl sidl/integrators.sidl sidl/randomgens.sidl 
    Babel: Parsing URL "file:/san/homedirs/bernhold/student-src/components/sidl/drivers.sidl"...
    Babel: Warning: Symbol exists in XML repository: drivers.F90Driver-v1.0
    Babel: Warning: Symbol exists in XML repository: drivers.CXXDriver-v1.0
    Babel: Parsing URL "file:/san/homedirs/bernhold/student-src/components/sidl/functions.sidl"...
    Babel: Warning: Symbol exists in XML repository: functions.LinearFunction-v1.0
    Babel: Warning: Symbol exists in XML repository: functions.NonlinearFunction-v1.0
    Babel: Warning: Symbol exists in XML repository: functions.PiFunction-v1.0
    Babel: Parsing URL "file:/san/homedirs/bernhold/student-src/components/sidl/integrators.sidl"...
    Babel: Warning: Symbol exists in XML repository: integrators.MonteCarlo-v1.0
    Babel: Warning: Symbol exists in XML repository: integrators.Midpoint-v1.0
    Babel: Warning: Symbol exists in XML repository: integrators.ParallelMid-v1.0
    Babel: Parsing URL "file:/san/homedirs/bernhold/student-src/components/sidl/randomgens.sidl"...
    Babel: Warning: Symbol exists in XML repository: randomgens.RandNumGenerator-v1.0
    touch .repository