Calling SIDL methods from C

The names of the C functions used to call SIDL methods are a concatenation of the package name, the class or interface name and the method name(s) with the period characters changed to underscores. If the method is specified as being overloaded (i.e., has a name extension) , the full method name is the concatenation of the short name and the extension. For non-static methods, the object or interface pointer is passed as the first parameter before any of the formal parameters. This parameter operates like an in parameter.

For methods that throw exceptions, there is an extra out argument that holds the exception. For maximum backward compatibility, the extra argument is of type sidl.BaseInterface. When an exception is thrown, the caller should ignore the value of the other out parameters as well as the function's return value. In order

Here are the C bindings for the critical addRef and deleteRef methods from sidl.BaseInterface. These methods are mentioned in particular because C clients must manage object reference counts themselves.


void
sidl_BaseInterface_addRef(
  sidl_BaseInterface self);

void
sidl_BaseInterface_deleteRef(
  sidl_BaseInterface self);

These same methods can be called from the sidl.BaseClass bindings. In fact, every C binding for an interface or class will have entries for addRef and deleteRef.


void
sidl_BaseClass_addRef(
  sidl_BaseClass self);

void
sidl_BaseClass_deleteRef(
  sidl_BaseClass self);

The following SIDL method taken from the Babel regression tests demonstrates how exceptions are handled.


int getFib(in int n, in int max_depth, in int max_value, in int depth)
  throws NegativeValueException, FibException;

Here is the C binding for this method:


int32_t
ExceptionTest_Fib_getFib(
  ExceptionTest_Fib self,
  int32_t n,
  int32_t max_depth,
  int32_t max_value,
  int32_t depth,
  sidl_BaseInterface *_ex);

Here is an example of how to perform exception handling in C using a package of macros defined in sidl_Exception.h. Note that the macros assume the exception class that is being thrown and caught inherits from sidl.SIDLException.


#include "sidl_Exception.h"
/* ...numerous lines deleted... */
  int x;
  sidl_SIDLException _ex = NULL;

  x = ExceptionTest_Fib_getFib(f, 10, 1, 100, 0, &_ex);
  if (SIDL_CATCH(_ex, "ExceptionTest.TooDeepException")) {
    traceback(_ex);
    SIDL_CLEAR(_ex);
  }
  else if (SIDL_CATCH(_ex, "ExceptionTest.TooBigException")) {
    traceback(_ex);
    SIDL_CLEAR(_ex);
  }
  else if (_ex == NULL) {
    return FALSE;
  }
  SIDL_CHECK(_ex);
  return TRUE;

  EXIT:;
    traceback(_ex);
    SIDL_CLEAR(_ex);
    return FALSE;

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:


  int b1, i1, iresult, nresult;

  Overload_Sample t  = Overload_Sample__create ();

  nresult = Overload_Sample_getValue(t);
  iresult = Overload_Sample_getValueInt(t, i1);
  bresult = Overload_Sample_getValueBool(t, b1);



babel-0.9.0
users_guide Last Modified 2004-01-29

http://www.llnl.gov/CASC/components
components@llnl.gov