3.2.  Creating Ports and Components

Let's create a component. First make sure that your current working directory is inside the project directory:


$  cd myProject
$  pwd


/home/me/tmp/bocca/myProject
$  

It is important to be in the project directory when you invoke bocca because it picks up all of the context for your project from there (sort of like CVS or Subversion). Go ahead and create the component now:


$   bocca create component emptyComponent


Bocca WARNING: Using default package myProject
$  
 

You will notice that this will take a little time and the WARNING is telling you that Bocca has selected your project name "myProject" as the default Babel package name. Note we have named our component "emptyComponent" because it has no uses nor provides ports and thus is rather uninteresting. Nonetheless all of the necessary make system scaffolding and code has been generated for the component, including the setServices() call. Here we use as an example the case where LANG is c++:

 
$  ls components/myProject.emptyComponent/
 
 
glue     myProject_emptyComponent_Impl.cxx
         myProject_emptyComponent_Impl.hxx 
$  
 

Fortran, C, and Python will contain similar files. Here in the components directory a new directory, myProject.emptyComponent has been created to hold your component. And inside there is the code already generated for the component (again continuing with LANG = c++) in the files : myProject_emptyComponent_Impl.cxx myProject_emptyComponent_Impl.hxx with some Babel glue code in the component subdirectory glue .

In order to have some exportable or importable functionality in a component we have to have some uses and provides ports. Bocca will also create the scaffolding and code for ports. Just as in the pre-built application of Chapter 2, Assembling and Running a CCA Application we will want to create a Function, a Integrator, and a Driver. Before we can do that we will have to create some ports for these components to use and provide. Similarly we wish to create a FunctionPort, and an IntegratorPort:


$  bocca create port IntegratorPort
$  bocca create port FunctionPort

Notice that we have opted for the default package myProject that is created for us transparently for all components and ports unless otherwise specified. Now create the components as in Chapter 2, Assembling and Running a CCA Application but this time we have to specify that they will provide or use the appropriate ports:



$  bocca create component Function --provides=FunctionPort:thisFunction
$  bocca create component Integrate --provides=IntegratorPort:integrate \
    --uses=FunctionPort:integrateThis
$  bocca create component Driver --uses=IntegratorPort:integrate \
    --provides=gov.cca.ports.GoPort:run


Bocca WARNING: Port gov.cca.ports.GoPort does not exist in project.
Bocca WARNING: Port definition assumed to be external to the project
$  

This last bocca create command is WARNING us about the fact that we are using a GoPort that is not part of this project. Since gov.cca.ports.GoPort is a part of the CCA specification, it will be found in the configure;make operation. Speaking of which, configure;make would be a good thing to do now:


$  configure;make


checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
                 .
                 .
                 .
################ Finished building everything #################
####### You can run some simple tests with 'make check' #######
$  

Note that this operation is usually very time-consuming.

At this point you can run the "make check" or do it yourself in the GUI:


$  make check

and/or


$  ./utils/run-gui.sh

make check will just attempt to instantiate the components in your project as a test. If you elect to run the ccafe-gui you can actually link the components together similar to Section 2.1.2, “Assembling and Running an Application Using the GUI” even though there is no implementation for any of the components yet. Be careful however not to click on and therefore run the GoPort because there is no code backing it and the containing framework will crash (no big problem if it does, just ^C out of it and start over).