There will be a few artifacts of CCA's (and Babel's) insistence on an object model. Generally the object oriented style of programming groups state data and subroutines (or methods) into "objects". Because CCA requires an object model for its components, Fortran programmers will have to become a little familiar with how CCA/Babel implements this in the language. A broad exposition on object oriented concepts is beyond the scope of this tutorial document, more and better information can be found elsewhere.
The first thing objects need is a constructor and destructor to
initialize state data. For Fortran, the methods ending in
_ctor and _dtor are
the constructor and destructor for the component (see listing above). This allows the
programmer to create (in the constructor) and delete (in the
destructor) state data associated with the component. One thing that
almost all components want to store is the
gov_cca_Services handle that is passed in
through the setServices(). A complex
component may wish to store parameters associated with its function as
well.
Looking at the cca specification cca.sidl, Babel
maps each CCA SIDL type (e.g. gov.cca.Port) to
a Fortran type (e.g. type(gov_cca_Port_t)).
Because return values cannot accept all Babel types and because Fortran does not provide either an object model or a mechanism for exceptions, these features are placed in the argument list:
A handle that represents the component and holds the state (or
private) data for the component is prepended to the
front of the argument list for every subroutine
method: it is usually called self.
The return value is appended to the end of the argument list.
If there is an exception specified in the .sidl
file, then the exception (of type SIDL_BaseInterface_t) is appended after the return value.
As an example, if a user specifies a SIDL snippet such as:
file: ./cca-spec-babel/cca.sidl line:108 package gov { package cca version 0.8.0 { ... Port getPort(in string portName) throws CCAException; ... } // end of package cca } // end package gov
In Fortran translates into:
... type(gov_cca_Port_t) :: port type(SIDL_BaseInterface_t) :: excpt type(gov_cca_Services) :: frameworkServices ... port = getPort(frameworkServices, port, excpt)