Table of Contents
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 )
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 $STUDENT_SRC/ports/sidl/function.sidlfunctions.LinearFunction.
In this step, we will define the
function.CubeFunction SIDL class and
build its XML repository representation
Edit the file
, and add
the definition of the class
$STUDENT_SRC/components/sidl/functions.sidlCubeFunction 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
{
}
}
Edit the file
to add a new component description in the
$STUDENT_SRC/components/MakeIncl.componentsCOMPONENTS 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.
In the
directory, run $STUDENT_SRC/componentsmake .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
directory so that all references can be easily resolved.
$STUDENT_SRC/xml_repository
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