Advanced Distributed Systems
Practical using CORBA
Michaelmas Term, 2002, Lancaster University
Welcome to the Advanced Distributed Systems Practical
This practical is intended to familiarise you with the basics
of CORBA programming in general, and the TAO orb in particular. The practical
is intended to be reasonably open-ended, to allow for further independent exploration
of CORBA and TAO. While C++ is used for this exercise, the initial code is provided,
and additional guidance will be available should you require it.
The CORBA devleopment enviroment used for this practical and for the coursework is TAO, which is a OpenSource ORB developed by Douglas Schmit at the University of California. It is installed on the lab machines in the c:\ace_wrappers folder in the same way as descibed in the building tao section.
1. The Development Environment.
The development platform for this exercise is Microsoft Visual Studio 7 (.NET).
TAO has been compiled in Static form (as opposed to Dynamic) on these machines,
beacuse of a Microsoft compiler bug detailed here.
This affects the names of the librarys and utilities (e.g. acesd.lib as opposed
to aced.lib) - the correct names are given in this document and in the provided
workspaces, but you should be aware that documents elsewhere may refer to the
dynamic names of the libraries.
So all files, projects and libraries should be built as static debug versions.
Where necessary, instructions for using Visual Studio have been provided in this document.
ACE is a library upon which TAO is built. There is no need to go into ACE too deeply, and in most places you may, if you prefer, use standard C++ functions.
For the exercises in this tutorial, the visual studio workspaces have already been created for you. The coursework will require you to create a new project using the instructions in creating a project.
2. The TAO IDL compiler.
TAO provides an idl compiler, which generates the stubs and skeletons needed to implement the specified interface. The name of this compiler is 'tao_idl.exe' and it may be found in the 'c:\ace_wrappers\bin\' directory.
Running tao_idl on an idl file (e.g. Example.idl) generates nine files (by default - more on this in a moment). ExampleC.h, ExampleC.i, and ExampleC.cpp contain the stubs for the client - these are all that are required for a typical client. ExampleS.h, ExampleS.i, and ExampleS.cpp contain the server side skeletons. Note that servers must also link to the client-side stubs. The other three files are ExampleS_T.h, ExampleS_T.i and ExampleS_T.cpp. These contain the TIE classes, composition (rather than inheritance) based skeletons. From the perspective of this exercise, they are only required in order to compile ExampleS.cpp.
Finally, if the -GI switch is provided, the TAO IDL compiler will also generate
two additional files, ExampleI.hExampleI.cpp. These contain outline code for
the necessary implementation of the methods defined in the idl file. NOTE! It
is unwise to include and modify these files in a project directly, as the next
time the IDL compiler is run, it will overwrite any changes made to them! Instead,
copy the contents to a different file and modify those.
3. Passing the Server IOR to Clients:
To keep these examples simple, the server advertises its IOR (the address of the server)in the following manner - The server program writes its server object's IOR to a ior_file. Later on, the client reads this IOR from the specified ior_file and uses the <string_to_object> method to obtain a reference to the server object.
For this mechanism to work, the file must be readable and writable. If it doesn't exist, a new file is created by the server. Moreover, the file path must be accessible to both the client and server.
If the client and server are on different machine, then there must be a shared directory accessible by both. On UNIX system's this is typically done via the NFS mount command. On Windows, the 'explorer' application provides an option to share drives.
All these examples run on the same machine from the same folder so the IOR is simply written and read from a file in the same folder. In a real world scenario the IOR will be passed as a client argument or discovered using a IOR service or a naming service.
4. The ACE_DEBUG output function
ACE provides an output function, which works similarly to printf. Example:
char * string = "I am a string";
int number = 42;
ACE_DEBUG ((LM_DEBUG, "A string: %s and a number: %d\n", string, number));
This code will result in the output 'A string: I am a string and a number: 42'
That is, %s has been substituted with the contents of the third argument to
ACE_DEBUG (the second being the format string and the first being LM_DEBUG),
and %d with the fourth. We could add further instances of %s and %d and provide
additional arguments to the function for additional output.
The Practical
This practical consists of three exercises which, depending on you programming knowledge should take a couple of hours. The first involves editing a few lines of code in a visual studio project, and is designed to allow you to familiarise yourself with the layout of a TAO project. The second involves writing the main execute program for the client and server, The third involves writing most of the code for a notify program.
If you complete the three exercises with time spare then you are advised to have a look at the coursework definition, and then have a go at creating your own project.
Exercises
This Exercise is designed to allow you to familarise yourself with TAO and build a simple corba program.
The Echo exercise consists of a client and a server. The Server simply executes and listens for client requests. The client connects to the server and using the echo interface, sends the server a string. The Server then echos it back to the client which then displays it at the prompt.
The exercise is in c:\corba\exercise1\. So start windows explorer, navigate to that directory and load the Echo 'Solution' file. This will start visual studio.
The workspace and initial code is provided for the Echo exercise is provided for you. Take the time to look at the files. EchoSImp.h and EchoSImp.cpp contain the implementation of the interface. server.cpp and client.cpp contain the main methods of the server and client implementations respectively. Note that, for this exercise, the IOR (Inter-operable Object Reference) is shared by use of a file.
To compile the projects, you can simply right-click on each of the two projects (client and server) in the Solution Explorer and select 'Build'. Note that first time you compile there may be an error, if this occurs compile the other project first. Note also that, at the linking stage, a lot (in the 100's) of warnings will arise. This is expected and will not affect the functionality of the resulting executable.>
To run the server and client: you can open a command prompt (START MENU->RUN->CMD
c:\corba\exercise1), and run the executables manually from there. Typing 'start
server' will run the server executable in a new window. You can then run the
client. You can also run them from Windows Explorer, or from within .NET. To
run them from within .NET, you can first right-click on the server project and
select 'Set as Start Up Project', and then click on the Debug menu and select
'Start Without Debugging'. Then repeat for the client.
Extending Echo:
Once the provided Echo application is compiled and working, we can extend it. We wish to alter the echo method to allow the return of a number specifying how many times the echo method has been called.
So, open the Echo.idl interface, edit the single function "echo" (line 12) to pass back a 'long' (CORBA::Long and CORBA::Long_out).
Once this change is made and the idl file is recompiled, you will need to adjust the EchoSImp.h and the EchoSImp.cpp files to reflect the change, and, of course, you will also need to change the client (client.cpp) appropriately.
(note: If you use the tao idl compiler's generated example implementation files,
in the Echo workspace, the names of the classes and methods are not identical
to those in the generated files - although they are largely equivalent to each
other. You may change class and method names as you see fit.)
This exercise consists of another visual studio project space which contains two projects, a server and a client. A server is run which can return the current time to a client.
This is a simple CORBA exercise that has an object (Time) with two methods: one that returns the current time of day and another that shuts down the server. It uses a helper class called "Simple_util" which contains a number of functions for initialising and communicating using CORBA clients and servers.
The exercise is in c:\corba\exercise2\. So start windows explorer, navigate to that directory and load the Echo.sln file. This will start visual studio. You will need to examine the exercise to learn how it works then follow the following rough guide.
1. You will need to edit the blank file client.cpp, to include Time_Client_i.h and in a main method create a instance of time_client_i and run the client. HINT: investigate the simple_util class.
2. You will need to edit the blank file server.cpp similarily to (1), create a instance of the time server, start a new corba environment using ACE_DECLARE_NEW_CORBA_ENV; then init and run the server. HINT: investigate the simple_util class.
To start the server, start a command console, navigate to c:\corba\exercise2. server_static.exe -o file.ior.
The "-o file.ior" outputs the IOR descriptor to a file.
To start the client, start a command console, navigate to c:\corba\exercise2. client_static.exe -f file.ior
The "-o file.ior" loads the IOR descriptor from the file.
The server should return the time.
A minimal workspace is provided for this exercise. This workspace contains only the basic idl files for the simplest implementation of the task, and placeholders for the additional files you will require.
The task is to develop a client which has the ability to receive messages (defined in Listener.idl) from the server. Thus, a client may register with the server to receive messages sent to the server from other clients. Of course, the registration process requires an additional method on the server side - see Notify.idl.
You will need to implement the entirety of client.cpp, server.cpp, NotifySImp.h, NotifySImp.cpp, ListenerSImp.h and ListenerSImp.cpp. The tao idl compiler generated outline implementation files (NotifyI.h, NotifyI.cpp, ListenerI.h, ListenerI.cpp) will no doubt be of use in this. But remember not to make changes to the generated files directly!
In order to keep this task (relatively) simple, it is not required to use multi-threading at this stage. A client may send a message, and then register itself and start its Listener implementation. (running the Listener at the same time as performing other functionality, be it sending a message, listening to additional input, etc., would of course require multi-threading.)
Note that this exercise is a lot harder than the first two, as such you may not finish it within the practical.
You should be aware that a very simple messaging application has been created. This should give you some ideas about tackling the coursework.
CORBA Programming Exercise
Develop a CORBA-based 'chat' application that enables an online group of people
to converse using text messages. One possible architecture would employ a central
distribution server that accepts client registrations and echoes strings that
are issued by any of its registered clients to all the other registered clients
(perhaps along with an attached 'nickname' provided by the originating client).
In the clients you would need to devise some means of simultaneously 'listening'
for incoming invocations from the distribution server and for messages typed
in at the keyboard. This may involve the use of an additional thread, or the
use of library facilities provided by TAO.
More sophisticated solutions (and more credit will be given) might involve:
Feel free to develop the solution in any way you think fit.
The deadline for the exercise is to be confirmed. You should hand in a full
program listing together with documentation that describes the design and specifies
and justifies your design choices. A demo may be required.
You should use the "creating a project" section as a starting point, or us the notify exercise, or use the template in exercise 2. But you will learn more by doing it all yourself :-).
You will probably have to build extra parts to TAO and orb services, there is a large amount of documents on the Douglas Schmit web page.
You all have network filespace available (see resources), but compiling using this will be slow so it is recomended that you use this as a backup store for your programs, and that you should copy it locally when you are working on it.
Creating a CORBA Visual Studio Project
These instructions detail how to create a Visual Studio 7 Project for a CORBA project.
Visual Studio 7and the MSDN library are available free off charge on the MSDNAA server.
1. Creating TAO Projects in .NET.
In general, you will need two projects to implement a CORBA application - one
for the client, and one for the server. For this exercise, you are provided
with a workspace with these already created. If you should need to create them
yourself, you will need to do the following:
1: Select New->Project from the File menu.
2: Choose 'Win32 Project', and ensure 'Add to Solution' is checked. Give it
a suitable name, click OK, then Application Settings. Select Console Application
and Empty Project.
3: Right-click on the new project in the Solution Explorer, and select Properties
4: Click on C/C++->General. You will need to add the paths to the ACE_wrappers
and the ACE_wrappers\TAO directories into the Additional Include Directories
setting. Ensure that a trailing slash is included.
5: Click on C/C++->Preprocessor. Add ACE_AS_STATIC_LIBS to the Preprocessor
Definitions section.
6: Select C/C++->Code Generation. Change the Runtime Library to Multi-threaded
Debug DLL.
7: Click on linker->General. Check that the output name is appropriate. Add
the ACE_Wrappers\ACE, the ACE_Wrappers\TAO\tao, and (if server functionality
is needed) the ACE_Wrappers\TAO\tao\PortableServer directories to the Additional
Library Directories setting.
7: Click on linker->Input. Add acesd.lib, TAOsd.lib, and (if using server
functionality ) TAO_PortableServersd.lib to the Additional Dependencies setting.
2. Creating and compiling the IDL file in .NET
Again, the initial IDL file is provided along with the below settings. The
details of these settings are provided here for reference as needed.
1: If it doesn't already exist, right click on the project in Solution Explorer
and select 'Add->New Folder'. Call the folder IDL Files.
2: Right-click on the folder, and select 'Add->Add New Item'. Call the item
<name as appropriate>.idl
3: To compile the idl file within .NET, a custom build step will have to be
set up for the idl file. To do this, first right-click on the file and select
Properties.
4: Click in the settings section of the 'Tool' line, and change the current
setting to Custom Build Step. Click on 'Apply'
5: Click on Custom Build Step in the left panel. The settings should be made
as follows:
Command Line = <path to ACE_Wrappers\bin\>tao_idl_static -Ge 1 $(InputName).idl
(add -GI to the arguments if you wish the generated outline implementation files)
Description = Invoking TAO_IDL Compiler
Outputs = $(InputName)C.h;
$(InputName)C.i;
$(InputName)C.cpp;
$(InputName)S.h;
$(InputName)S.i;
$(InputName)S.cpp;
$(InputName)S_T.h;
$(InputName)S_T.i;
$(InputName)S_T.cpp
Additional Dependencies = <path to ACE_Wrappers\bin\>tao_idl_static.exe
6: The IDL can now be compiled. The resulting files can then be added to the
client or server projects as appropriate.
Building ACE and TAO on your own machine.
You can either use the CORBA installation on the machines in the MSc lab or use your own PC.
Instructions are for Windows 2000/XP using visual studio .NET (7). Both available free of charge from the MSDNAA server.
WARNING: This will take a few hours on a high-spec machine and a lot longer on a lesser machine.
It will also take up around 700 MB of hard drive space.
(when loading projects, you will have to say "yes" to convert them to visual studio 7 files, you may also have to change some idl compiler settings in the project files if the static verision of the idl compiler is not found).
1. Set the following environment variables. (Control panel\System\advanced\system vars)
set ACE_ROOT=C:\ACE_wrappers
set TAO_ROOT= %ACE_ROOT%\TAO
set PATH = C:\ACE_wrappers\bin
2. Download ace and tao from here.
3. Extract the files to a location on your hard disk, say c:\, a folder will be created call ACE_wrappers.
This contains ACE, TAO and a number of tools you will need to create CORBA projects.
4. load the project $ACE_ROOT/ace/ace.dsw
-> Build -> Batch build -> just select "ACE DLL - Win32 Static Debug"
Click Build
5. load the project $ACE_ROOT/apps/gperf/src/gperf.dsw
-> Build -> Batch build -> just select "gperf -Win32 Static Debug"
Click Build
6. load the project $TAO_ROOT/TAO/tao/tao.dsw
-> Build -> Batch build -> select all the "Win32 - Static Debug" projects
Click Build
7. load the project $TAO_ROOT/TAO_IDL/tao_idl.dsw
-> Build -> Batch build -> just select "TAO_IDL Compiler -Win32 Static Debug" and "TAO_IDL_DE_DLL - Win32 Static Debug" and "TAO_IDL_FE_DLL - Win32 Static Debug"
Click Build
8. load the project $TAO_ROOT\tao\orbsvcs\orbsvcs\orbsvcs_static.dsw
-> Build -> Batch build -> select all "static Debug"
Click Build
A fully built version is available here, this was built using the instructions above. Although you will still need to set the enivronment variables in section 1.
Depending on how you plan to implement the coursework, you may need to build some other libraries, including the MFC versions of the libraries if you use MFC and the naming service if you use that.
There are further examples, reference documents and tutorials on Douglas Schmit's web page (the designer of ACE and TAO).
There is a yahoo forum for TAO modeated by Schmit and a team of developers. Although you probably won't need to post on the forum, there is a wide variety of help already detailed in the forum. They are TAO_bugs and TAO_users.
The MSDNAA
library is a archive of microsoft software available to Lancaster University
Computing Students. It includes to software needed to do the coursework on your
own PC at home, including Windows XP and Visual Studio 7.
From the TAO website, an overview of TAO, and an index of tutorials
A network fileshare has been provided for students on this course at //syslab_main/ (this link will be invalid when viewed from outside the University network). You should use this to store you coursework.
Visual Studio 7workspaces for the exercises (in .zip archive format): the Exercise1 workspace, Exercise 2 workspace and the Exercise 3 workspace.
Any technical problems or additions to this web site, obtaining/building TAO or questions about TAO contact Kevin Lee.
Any issues with the coursework or problems contact Geoff or Gordon.
Remember however that this coursework is meant to be resonably hard, as it is designed to prepare you for the level of programming which some of the projects next year involve.
____________________________________________________________________________________________
Maintained by Kevin Lee