PreviousNext

Writing an Interface Definition

Traditionally, calling code and called procedures share the same address space. In an RPC application, the calling code and the called remote procedures are not linked; rather, they communicate indirectly through an RPC interface. An RPC interface is a logical grouping of operations, data types, and constants that serves as a contract for a set of remote procedures. DCE RPC interfaces are compiled from formal interface definitions written by application developers using IDL.

The first step in developing a distributed application is to write an interface definition file in IDL. The IDL compiler, idl, uses the interface definition to generate a header file, a client stub file, and a server stub file. The IDL compiler produces header files in C and can produce stubs as C source files or as object files.

For some applications, you may also need to write an Attribute Configuration File (ACF) to accompany the interface definition. If an ACF exists, the IDL compiler interprets the ACF when it compiles the interface definition. Information in the ACF is used to modify the code that the compiler generates. (The greet example does not require an ACF.)

The remainder of this topic briefly explains how to create an interface definition and gives simple examples of each kind of IDL declaration. For a detailed description of IDL, see Interface Definition Language. For information on the IDL compiler, see the OSF DCE Command Referenceidl(1rpc) reference page.

An IDL interface definition consists of a header and a body. The following example shows the interface definition for the greet application:

/*

* greet.idl

*

* The "greet" interface.

*/

[uuid(3d6ead56-06e3-11ca-8dd1-826901beabcd),

version(1.0)]

interface greetif

{

const long int REPLY_SIZE = 100;

void greet(

[in] handle_t h,

[in, string] char client_greeting[],

[out, string] char server_reply[REPLY_SIZE]

);

}

The header of each RPC interface contains a UUID, which is a hexadecimal number that uniquely identifies an entity. A UUID that identifies an RPC interface is known as an interface UUID. The interface UUID ensures that the interface can be uniquely identified across all possible network configurations. In addition to an interface UUID, each RPC interface contains major and minor version numbers. Together, the interface UUID and version numbers form an interface identifier that identifies an instance of an RPC interface across systems and through time.

The interface body can contain the following constructs:

· Import declarations (not shown)

· Constant declarations (REPLY_SIZE)

· Data type declarations (not shown)

· Operation declarations (void greet(...);)

IDL declarations resemble declarations in ANSI C. IDL is purely a declarative language, so, in some ways, an IDL interface definition is like a C header file. However, an IDL interface definition must specify the extra information that is needed by the remote procedure call mechanism. Most of this information is expressed via IDL attributes. IDL attributes can apply to types, to type members, to operations, to operation parameters, or to an interface as a whole. An attribute is represented in [ ] (brackets) before the item to which it applies. In the greet.idl example, the [in, string] attributes associated with the client_greeting array means the parameter is for input only and that the array of characters has the properties of strings.

A comment can be inserted at any place in an interface definition where white space is permitted. IDL comments, like C comments, begin with /* (a slash and an asterisk) and end with */ (an asterisk and a slash).

More:

RPC Interfaces That Represent Services

Generating an Interface UUID

Naming the Interface

Specifying Interface Attributes

Import Declarations

Constant Declarations

Type Declarations

Operation Declarations