CORBA Programming/Echo/Object

The echo object is a simple object with only one method. This method takes a single string parameter and returns that string unchanged.

CORBA IDL definition
Any CORBA object needs to be defined in CORBA's Interface Definition Language (IDL). The IDL syntax is based on C/C++ including the use of the C preprocessor. Hence we need the usual protection against a double include:

Next we define a module name. While not strictly needed for such a small example it is a good practice never to pollute the global namespace with classes and to use modules instead. A class is called an "interface" in CORBA IDL. This should not be mixed up with interfaces in Ada or Java. A CORBA interface is the public part of the class &mdash; the part of the class you can interface with. As said, we define just one method. It takes a string called Message as input parameter and returns a string as result.

Ada Specification
Before you download the specification below you should try to call the following PolyORB command. It will generate an implementation template for you.

idlac -i test-echo.idl

Most CORBA implementations will generate specification and implementation template files for the chosen implementation language. Which implementation languages you can choose from depends on your ORB. In our case it is Ada.

The CORBA module (Test) and class (Echo) is mapped to an Ada package hierarchy &mdash; this is the normal way to do object oriented programming in Ada. The CORBA language mapping always tries to map close the implementation language. The Echo hierarchy contains several child packages which are fully generated and need no attention. Only the child package "Impl" contains the actual implementation of our Echo class and needs editing.

The type Object contains any data our class might want to store. However, all data stored is private, in fact all data in CORBA objects are private.

The Echo function is specified as a normal primitive operation to a normal Ada class. If you are interested to know how Ada classes are declared you can read Ada Programming/Object Orientation. Here, in the private section of the package, we could now declare data members for our class. However our simple echo class needs no data, so we just declare a "null record". If you are interested to know what it would look like with data members you can read Ada Programming/Types/record.

Ada Implementation
Now we know what the CORBA object looks like in Ada we have to actually implement the object. The implementation is a little more extensive than needed &mdash; using PolyORB logging facility to produce diagnostic output.