All SIDL methods are implemented as FORTRAN 77 subroutines regardless of whether they have a return value or not. For object methods, the object or interface pointer is passed as the first argument to the subroutine before all the formally declared arguments. The exception is static methods, where the object or interface pointer does not appear in the argument list at all.
When a method has a return value, a variable to hold the return value should be passed as an argument following the formally declared arguments. When a method can throw an exception (i.e., its SIDL definition has a throws clause), a variable of type INTEGER*8 should be passed to hold a pointer if an exception is thrown. For maximum backward compatibility, the base exception type argument is sidl.BaseInterface though the base exception class is sidl.SIDLException. The exception argument appears after the return value when both occur in a method. After the call, the client should test this argument. If it is non-zero, an exception was thrown by the method, and the method should respond appropriately. When an exception is thrown, the value of all other arguments is undefined.
The name of the subroutine that FORTRAN 77 clients should call is derived from the fully qualified name of the class and the name(s) of the method. If the method is specified as overloaded (i.e., has a name extension), the method's full name will be used. That is, the concatenation of the short name and the name extension will be used for a unique method name. Hence, to determine the subroutine name for FORTRAN 77, take the fully qualified name, replace all the periods with underscores, append an underscore, append the short method name, append the method name extension (if any) and then append "_f".
For example, to call the deleteRef() method on a sidl.BaseInterface interface, you would write:
integer*8 interface1, interface2 logical areSame C code to initialize interface1 & interface 2 here call sidl_BaseInterface_deleteRef_f(interface1)
To call the isSame method on a sidl.BaseInterface , you would write:
call sidl_BaseInterface_queryInt_f(interface1, 'My.Interface.Name', interface2)
To call the queryInt method on a sidl.BaseInterface, you would write:
call sidl_BaseInterface_queryInt_f(interface1, 'My.Interface.Name', interface2)
Examples of calls to SIDL overloaded methods are based on the overload_sample.sidl file shown in Section 3.6. Recall that the file describes three versions of the getValue method. The first takes no arguments, the second takes an integer argument, and the third takes a boolean. Each is called in the code snippet below:
integer*8 t logical b1, bretval integer*4 i1, iretval call Overload_Sample__create_f (t) call Overload_Sample_getValue_f (t, iretval) call Overload_Sample_getValueInt_f (t, i1, iretval) call Overload_Sample_getValueBool_f (t, b1, bretval)
For interfaces and classes, there are two implicit methods called _cast() and _cast2(). Both of these methods are used to convert from one type to another, and each can be used for upcasting up downcasting. Neither method will increment the reference count of the object.
_cast() is a static method. It tries to convert its opaque argument to the type of the class indicated by the method name. For example, x_y_z__cast(obj, xyz) will try to convert obj to type x.y.z. If xyz is nonzero, the cast was successful.
_cast2() is an object method. Its return type is opaque, and it has one formal argument, a string in addition to the implicit object/interface reference. The _cast() method attempts to cast the object/interface to the named type. It is similar to the queryInt method in sidl.BaseInterface except it does not increment the reference count of the return object or interface, and it may return an object or an interface pointer. The queryInt() method always returns an interface pointer.
For non-abstract classes, there is an implicit method called _create(). It creates and returns an instance of the class.
Here are examples of the use of these two methods:
integer*8 object, interface call sidl_BaseClass__create_f(object) call sidl_BaseInterface__cast_f(object, interface) c the following call to _cast2 is equivalent to the previous _cast call call sidl_BaseClass__cast2_f(object, 'SIDL.BaseInterface', $ interface)
Please note the presence of two underscores between BaseClass and create and between BaseClass and cast; the extra underscore is there because the first character of the method name is an underscore.
Here is an example call to the addSearchPath() in the sidl.Loader class:
call sidl_Loader_addSearchPath_f('/try/looking/here')
Your FORTRAN 77 must manage any object references created by the calls you make.
Here is another example adapted from the Babel regression tests. Package ExceptionTest has a class named Fib with a method declared in SIDL as follows:
int getFib(in int n, in int max_depth, in int max_value, in int depth) throws NegativeValueException, FibException;
Here is the outline of a FORTRAN 77 code fragment to use this method.
integer*8 fib, except, except2 integer*4 index, maxdepth, maxval, depth, result call ExceptionTest_Fib__create_f(fib) index = 4 maxdepth = 100 maxvalue = 32000 depth = 0 call ExceptionTest_getFib_f(fib, index, maxdepth, $ maxvalue, depth, result, except) if (except .ne. 0) then call ExceptionTest_FibException__cast_f(except, except2) if (except2 .ne. 0) then c do something here with the FibException else call ExceptionTest_NegativeValueException__cast_f $ (exception, except2) c do something here with the NegativeValueException endif call sidl_BaseException_deleteRef_f(except) else write (*,*) 'getFib for ', index, ' returned ', result endif call ExceptionTest_Fib_deleteRef_f(fib)
Here is how you should invoke Babel to create the FORTRAN 77 stubs for an IDL file 9.1.
% babel -client=f77 file.sidlor simply
% babel -c=f77 file.sidl
This will create a babel.make file, numerous C headers, numerous C source files, and some FORTRAN 77 files. The files ending in _fStub.c are the FORTRAN 77 stubs that allow FORTRAN 77 to call a SIDL method.
You will need to compile and link the files ending in _fStub.c into your application (i.e. STUBSRCS in babel.make). Normally, the IOR files (_IOR.c) are linked together with the implementation file, so you probably don't need to compile them.
If you have some enum's defined in your SIDL file, Babel will generate FORTRAN 77 include files in the style of DEC FORTRAN (Compaq FORTRAN? (now HP Fortran???)) %INCLUDE. These files are named by taking the fully qualified name of the enum, changing the periods to underscores, and appending .inc . Here is an example of a generated include file.
C File: enums_car.inc C Symbol: enums.car-v1.0 C Symbol Type: enumeration C Babel Version: 0.5.0 C Description: Automatically generated; changes will be lost C C babel-version = 0.5.0 C source-line = 25 C integer porsche parameter (porsche = 911) integer ford parameter (ford = 150) integer mercedes parameter (mercedes = 550)