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, 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.
In this step, we will define the function.CubeFunction SIDL class and build its xml repository representation
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
{
}
}
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, c++, or f90. In this case, the name is functions.CubeFunction, and the language is c++. The updated value of COMPONENTS should look like this:
COMPONENTS = functions.PiFunction-c++ \
integrators.MonteCarlo-f90 randomgens.RandNumGenerator-c++ \
drivers.CXXDriver-c++ integrators.Midpoint-f90 \
functions.CubeFunction-c++
Note the backslash (“\”) that has to be added in order to extend the entry to the next line.
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.
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/shared/cca/tutorial/share/cca-spec-babel-0_7_0-babel-0.9.5/xml -o ../xml_repository sidl/drivers.sidl sidl/functions.sidl sidl/integrators.sidl sidl/randomgens.sidl Babel: Parsing URL "file:/.automount/whale/root/san/r1a0l0/elwasifw/handson/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:/.automount/whale/root/san/r1a0l0/elwasifw/handson/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:/.automount/whale/root/san/r1a0l0/elwasifw/handson/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:/.automount/whale/root/san/r1a0l0/elwasifw/handson/components/sidl/randomgens.sidl"... Babel: Warning: Symbol exists in XML repository: randomgens.RandNumGenerator-v1.0 touch .repository