Practical CORBA Programming using TAO


Your First CORBA Application


Table of Contents

  1. Introduction
  2. Step 1: Setting Up Tao
  3. Step 2: Writing and compiling IDL file
  4. Step 3: Your First Server
  5. Step 4: Your First Client
  6. Step 5: Some practice with options
Introduction

This chapter takes you through the process of setting up ACE/TAO environment on your machine. We will limit our discussion to Windows NT platform and Visual C++ as development environment. Most of the process is applicable to other operating systems and tools, however, certain specific settings might be needed on them. After going through this chapter, you should be able to create a simple CORBA client and server.

The chapter deals with setting up environment on your machine from scratch. TAO can be used on wide variety of platforms and with variety of tools. For details please see Building and Installing TAO.

In the tutorial we will use WindowsNT system and Visual C++ 5 as development environment. The users of other platforms and development tools can refer Building and Installing TAO. we will discuss some general aspects of CORBA and TAO also.

The aim of this chapter is to give you a good starting point and hands on experience with CORBA. This discussion assumes working knowledge of Windows, Developer Studio and C++. Some initial knowledge of CORBA will be helpful.

Step 1: Setting Up TAO

A blank window will be created. Now add following text to the file:
#include "ace/config-win32.h"
To save the file as config.h in c:\corba\ACE_wrappers\ace directory, proceed as follows:
  1. Click on Save As.. menu item.
  2. Choose c:\corba\ACE_wrappers\ace directory
  3. Specify config.h in the space for filename
  4. Click Save.
We are now ready to compile the code. Proceed with instructions below:
  1. Click on Batch Build under Build menu.
  2. Check Naming_Service -Win32 Debug option
  3. Click on Build button.
Note: You might get error like "Cannot open include file: 'config.h': No such file or directory" or other errors, if you have not created config.h properly or if you have not saved it in proper directory. If this happens, stop the build. Visit the section Setting up Environment. Identify and fix the problem and rebuild again.
Step 2: Writing and compiling IDL file
Voila. You have successfully compiled ACE/TAO source files. (If not, go back to step 1 and have it compiled. Without the tools and dlls you will not be able to proceed.)

Now we are ready to write a sample application to get hands on CORBA (and TAO). Proceed as follows:

  1. Close the workspace (TAOACE.dsw) you had opened in step 1.
  2. Click on New.. in File Menu. (See fig.)
  3. In the dialog click on Projects tab.
  4. Click on Win32 Console Application option.
  5. Select c:\corba directory in place for Location.
  6. Enter Server in the place for Project Name.
  7. Click OK
A project called server shall be created for you, in the workspace (whose name is also server).
        module HelloApplication{
                interface Hello{
                        string sayHello();
                };
        };

This file now needs to be included in the project. Here is procedure if you don't know how to do:
Now we have the interface declared in the file Hello.idl. The interface is defined using Interface Definition Language. The tao_idl.exe, the IDL compiler, will be used to map the IDL to C++ mappings. We will specify custom compilation options for Hello.idl in the developer studio. If anybody knows how to customize the Developer Studio for IDL files compilation, please email it to [email protected].
The idl file has been set up for custom build. Now proceed with compilation as follows: The idl file is compiled when you see 0 errors 0 warnings in output window. This process has generated 9 files in your c:\corba\server directory. We will discuss about these files later.

Open the directory c:\corba \server with explorer, and confirm that these files are present. Their names are:

  1. HelloC.h
  2. HelloC.cpp
  3. HelloC.i
  4. HelloS.h
  5. HelloS.cpp
  6. HelloS.i
  7. HelloS_T.h
  8. HelloS_T.cpp
  9. HelloS_T.i
Note: If you see any errors or if you do not see the (9) files generated, identify and fix the problem. Experts could go to command prompt and issue tao_idl Hello.idl command in c:\corba\server directory to see what is wrong. The path could be checked for spelling mistakes.
Step 3: Your First Server
In step 2, you have setup the environment. This is essencial part of the whole process.

Now, You are ready to take first test flight of CORBA. The best way to understand what is going on, is to write a small application. This section deals with steps involved in making of a test server.

The server development involves few steps. Implementing the interface and finally making it available to the world. The first step involves defining a class that shall implement Hello.idl. Other steps are consolidated in developing the server.cpp and we will discuss in detail later.

Step 4: Your First Client
Under Construction
Step 5: Some practice with options
Under Construction.
Hosted by www.Geocities.ws

1