Jump to content

The SOM Interface Definition Language: Difference between revisions

From EDM2
Prokushev (talk | contribs)
No edit summary
 
Prokushev (talk | contribs)
No edit summary
Line 1: Line 1:
by [[Prokushev]]
In [[Introduction to SOM|previous]] article we briefly looked at SOM.
Now we'll try to define our class interface.
Interface Definition Language (IDL) is core of [http://en.wikipedia.org/wiki/System_Object_Model System Object Model]. All classes has definition of its interface via IDL. With help of [[SOM Compiler]] IDL file can be translated to various formats, including various language bindings. For example, to produce C header you can run
Interface Definition Language (IDL) is core of [http://en.wikipedia.org/wiki/System_Object_Model System Object Model]. All classes has definition of its interface via IDL. With help of [[SOM Compiler]] IDL file can be translated to various formats, including various language bindings. For example, to produce C header you can run
  sc -s"h" somcls.idl
  sc -s"h" somcls.idl
Line 4: Line 9:
  sc -s"def" somcls.idl
  sc -s"def" somcls.idl
[[SOM Compiler]] uses [[emitter]] to produce corresponding language binding. You can create new bindings using [[Emitter Framework]].
[[SOM Compiler]] uses [[emitter]] to produce corresponding language binding. You can create new bindings using [[Emitter Framework]].
First of all, think about your class. What it must do? Define them in
terms of object. Propose attributes and methods of class.
Ok. Imagine, we need class to have access to Java objects. Let's write
class interface in terms of Interface Definition Language.
#include <somobj.idl>
interface JavaObject : SOMObject
{
  implementation
  {
    somDefaultInit: override;
    // Init Java machine (if no current) and create Java object
    somDefaultDestruct: override;
    // Destruct Java object and close Java machine (if needed)
  }
}
As you can see, no many problems. Syntax of IDL too closest to C-like
languages. First thing you need is to include definitions of parent
classes. In our case it is '''SOMObject''' definition. Generic Java object
doesn't need to have any methods. Only thing '''JavaObject''' will do its
check for existance of Java Machine and execution of it if required.
On object destruction checks is Java Machine still required will be
done and it will be destroed if not required. Also same constructor
and destructor will call corresponding constructor and destructor
of Java object.
Classic IDL file contains definitons like
interface <object> : <parent>
{
  attribute <type> <name>
  <type> <method>(<parameters>)
}
As I known [http://www.omg.org OMG] IDL doesn't support methods override. SOM IDL has
such feature (and incompatability with OMG CORBA). This is done via
keyword '''implementation'''. To solve problems with other IDL compilers
such part must be wrapped to #ifdef structure:
#include <somobj.idl>
interface JavaObject : SOMObject
{
  implementation
  #ifdef __SOMIDL__
  {
    somDefaultInit: override;
    // Init Java machine (if no current) and create Java object
    somDefaultDestruct: override;
    // Destruct Java object and close Java machine (if needed)
  }
  #endif
}
Such approach well known in C-world, but also have some problems.
For example, IDL of Document Object Model (DOM) (Yes, [http://www.w3.org W3C] DOM uses
same IDL as SOM and CORBA) has attribute '''implementation'''. As result,
[SOM Compiler] has some problems with IDL compilation.
Ok. Let's stop talking about syntax things (you always can read documentation)
and try to create IDL from
Java class.

Revision as of 05:01, 14 November 2004

by Prokushev

In previous article we briefly looked at SOM. Now we'll try to define our class interface.

Interface Definition Language (IDL) is core of System Object Model. All classes has definition of its interface via IDL. With help of SOM Compiler IDL file can be translated to various formats, including various language bindings. For example, to produce C header you can run

sc -s"h" somcls.idl

to produce DEF file you can run

sc -s"def" somcls.idl

SOM Compiler uses emitter to produce corresponding language binding. You can create new bindings using Emitter Framework.

First of all, think about your class. What it must do? Define them in terms of object. Propose attributes and methods of class.

Ok. Imagine, we need class to have access to Java objects. Let's write class interface in terms of Interface Definition Language.

#include <somobj.idl>

interface JavaObject : SOMObject
{
  implementation
  {
    somDefaultInit: override;
    // Init Java machine (if no current) and create Java object
    somDefaultDestruct: override;
    // Destruct Java object and close Java machine (if needed)
  }
}

As you can see, no many problems. Syntax of IDL too closest to C-like languages. First thing you need is to include definitions of parent classes. In our case it is SOMObject definition. Generic Java object doesn't need to have any methods. Only thing JavaObject will do its check for existance of Java Machine and execution of it if required. On object destruction checks is Java Machine still required will be done and it will be destroed if not required. Also same constructor and destructor will call corresponding constructor and destructor of Java object.

Classic IDL file contains definitons like

interface <object> : <parent>
{
  attribute <type> <name>

  <type> <method>(<parameters>)
}

As I known OMG IDL doesn't support methods override. SOM IDL has such feature (and incompatability with OMG CORBA). This is done via keyword implementation. To solve problems with other IDL compilers such part must be wrapped to #ifdef structure:


#include <somobj.idl>

interface JavaObject : SOMObject
{
  implementation

  #ifdef __SOMIDL__
  {
    somDefaultInit: override;
    // Init Java machine (if no current) and create Java object
    somDefaultDestruct: override;
    // Destruct Java object and close Java machine (if needed)
  }
  #endif
}

Such approach well known in C-world, but also have some problems. For example, IDL of Document Object Model (DOM) (Yes, W3C DOM uses same IDL as SOM and CORBA) has attribute implementation. As result, [SOM Compiler] has some problems with IDL compilation.

Ok. Let's stop talking about syntax things (you always can read documentation) and try to create IDL from Java class.