The language binding files generated by the SOM compiler include a template for the C-language source program for the class implementation. This program template contains stub procedures for all new and override methods specified in the class definition file. You must supply the code implementation for the stub-method procedures. The sample codes illustrated in the following figures show the stages in this process:

/*
 * A class defining a set of objects (dogs)
*/
#ifndef dog1_idl
#define dog1_idl
#include <somobj.idl>

interface Dog : SOMObject
{
  void Bark();

  // Have the dog bark

  #ifdef __SOMIDL__
  implementation
  {
    releaseorder:  Bark;

    //# Class modifiers

    callstyle = oidl;    // For compatibility with SOM1
    majorversion = 1;
    minorversion = 2;
  };
  #endif /* __SOMIDL__ */
};
#endif  /* dog1_idl */

In the previous sample code, the Dog class is defined. According to this class definition file, the Dog class is derived from the SOMObject class. The behavior of the SOMObject class is defined in the file, SOMOBJ.IDL, which was generated by the SOM compiler when the SOMObject class was implemented. Object instances of the Dog class inherit the behavior of its parent class SOMObject by specifying the SOMOBJ.IDL file in the Include section of the Dog class definition file. This means that all methods that can act on instances of SOMObject can act on the Dog class objects.

In the real world, dogs have many characteristics and behaviors. A comprehensive definition of the Dog class would include methods that relate to these characteristics and behaviors. In this example, the only behavior that is defined is barking. The behavior, "dogs can bark" corresponds to the prototype of the "bark" method specified in the Methods section of the class definition file.

The SOM compiler processes the DOG.IDL file as shown in the previous sample code and generates the DOG.C C-language source-program template shown in the following figure. Notice that DOG.IH, another file generated by the SOM compiler, is included automatically in this program template. This file contains the data structures, macros, and functions for accessing data and methods for object instances of the Dog class. This file also provides stubs for all methods prototyped in the Methods section of the DOG.IDL file.

/*
*  This file was generated by the SOM compiler and Emitter framework.
*  Generated using:  SOM Emitter emitctm: 2.38
*/

#ifndef SOM_Module_dog1_Source
#define SOM_Module_dog1_Source
#endif

#define Dog_Class_Source

#include "dog1.ih"

/*
 * Have the dog bark
*/

SOM_Scope void  SOMLINK Bark(Dog *somSelf)
{
    /* DogData *somThis = DogGetData(somSelf); */
    DogMethodDebug("Dog","Bark");
}

The general form for a method stub is shown in the following figure:

SOM_Scope void SOMLINK <methodname>(<classname> *somSelf)
{
  <classname>Data *somThis = <classname>GetData(somSelf);
  <classname>MethodDebug("<classname>", "<methodname>");
}

SOM_Scope and SOMLINK are C macros used internally with the C-binding files.


[Back] [Next]