Chapter 3. IDL

In this chapter, we present the basic information needed to define interfaces that will be used by Tweek. This is not a detailed introduction to IDL programming. Readers are referred to [Hen99].

IDL “programming” means defining interfaces. In the scope of Tweek and CORBA, the interfaces declare what operations may be performed on CORBA references. The arguments and return values may be of several basic types including, but not limited to, string, int, long, and float. These types are specified in a language-independent manner. When the IDL compiler generates the code for a specific language, the language-specific types that correspond to the IDL types are used.

In Example 3.1, “Subject.idl”, we show the Tweek Subject interface. Note the similarity to a C++ header file. The IDL file can be included by other IDL files, and thus it must “protect” the contents in the same manner as a header file. The actual Subject interface is defined within the tweek module. An IDL module corresponds to a C++ namespace or to a Java package. The interface itself has three methods: attach(), detach(), and notify(). The first two take a read-only argument of type Observer. The fact that the argument is read-only (to the server) is specified by the in modifier. Other modifiers are out (sent from server to client) and inout (initialized by the client, writable by the server). The third method, notify(), takes no arguments, and none of the methods have a return type.

Example 3.1. Subject.idl

#ifndef _TWEEK_SUBJECT_IDL_
#define _TWEEK_SUBJECT_IDL_

#include <tweek/idl/Observer.idl>

module tweek
{

interface Subject
{
   void attach(in Observer o);
   void detach(in Observer o);
   void notify();
};

};

#endif

By definition, all objects are passed by reference in CORBA. The modifier stating the readability and/or writability in the IDL file determines how the referenced object may be modified, if at all, within the method.

Applications that make use of Tweek will define custom interfaces that extend the Subject interface. For example, consider a custom subject that maintains a floating-point value. It could have the following interface:

Example 3.2. CustomSubject.idl

#ifndef _CUSTOM_SUBJECT_IDL_
#define _CUSTOM_SUBJECT_IDL_

#include <tweek/idl/Subject.idl>

module mymod
{

interface CustomSubject : tweek::Subject
{
   float getValue();
   void setValue(in float v);
};

};

#endif

In this interface, we define two methods: getValue() and setValue(). The implementation of this interface would of course include these methods and would derive from the implementation of the Subject interface.