CCA Wiki
CCA Software Resources
Menu [hide]

BoccaSimpleExample

A first project with bocca
print PDF
Presuming you have a bocca 0.3 installed and in path, here's a simple example.

bocca create project myproj
cd myproj
./configure ; # generates utility scripts important when testing
bocca create port myport
bocca create component mycomponent --uses=myport:out --provides:myport:in

This creates a component with two ports (named "in" and "out") of the same type myport (full SIDL type name is myproj.myport). It uses the default language c++. To specify using another language, add the --language="LANG" option to create component; LANG is one of "c,cxx,f77,f90,python,java".

To put some brains in the system we need to add a method to the port:
bocca edit myport

brings up the editor with the myport sidl file. The sidl file actually resides somewhere in the project source tree (myproj/ports/sidl/myproj.myport.sidl) that we don't want to remember.
(If there's a problem starting the editor, see BoccaEdit for hints.) Add method:

double doSomething(in double x);

in the block of the sidl file surrounded by:

// DO-NOT-DELETE bocca.splicer.begin(myproj.myport.methods)
...
// DO-NOT-DELETE bocca.splicer.end(myproj.myport.methods)


Now we need to implement doSomething in the component.
bocca edit -i mycomponent

brings up the editor with the component impl (implementation) file in c++.

here you will find (if you search):

// DO-NOT-DELETE splicer.begin(myproj.mycomponent.doSomething)
// Insert-Code-Here {myproj.mycomponent.doSomething} (doSomething method)

// DO-DELETE-WHEN-IMPLEMENTING exception.begin()
/*
* This method has not been implemented
*/
sidl
NotImplementedException ex =
sidl
NotImplementedException::_create();

ex.setNote("This method has not been implemented");
ex.add(FILE, LINE, "doSomething");
throw ex;
// DO-DELETE-WHEN-IMPLEMENTING exception.end()

// DO-NOT-DELETE splicer.end(myproj.mycomponent.doSomething)


Replace the block contents with some code:

// DO-NOT-DELETE splicer.begin(myproj.mycomponent.doSomething)
return x*x;
// DO-NOT-DELETE splicer.end(myproj.mycomponent.doSomething)


and then type 'make' again and you have a working component!

To prove the component is working, type 'make check'.
To prove the component is working with a gui, type 'make testgui'.

Please note that the ccafe-gui freezing up after loading some but not all components is a known bug and has nothing to do with your component.

Created by: baallan last modification: Friday 28 of September, 2007 [15:37:59 UTC] by baallan


Online users
19 online users