Skip to content
ELECTRONICS ENGINEERINGelectronics-engineering.com
CORBA

A Small CORBA Example with ACE+TAO, Step by Step up to Compilation

In this example I would like to describe step by step how to compile a CORBA application after the ACE TAO libraries have been installed in the directory ACE_wrappers. In this exercise I do not use any development environment…

https://www.electronics-engineering.com/en/a-small-corba-example-with-ace-tao-step-by-step-up-to-compilation/

Was this page useful? Rate it:
average 4.0 from 1 rating

In this example I would like to describe step by step how to compile a CORBA application after the ACE TAO libraries have been installed in the directory ACE_wrappers. In this exercise I do not use any particular development environment. The code can be written with a simple editor.  In particular, this example was built with Ubuntu  10.10 but it can just as well be done with any version of Linux.

The first thing to do is obviously to install the ACE TAO libraries. This is rather simple. The instructions in the manual are quite easy. 

From this link https://theaceorb.com/ you can download the latest available version of ACE TAO. For Linux it is preferable to download the tar.gz version: https://downloads.opendds.org/TAO-1.6a/ACE+TAO-1.6a.tar.gz

Once the version is downloaded, everything must be compiled following the notes described at this link:  https://theaceorb.com/support/faq.html#Building-HowToBuildACEandTAOonLinux

Now we are ready to start the first project. Before starting, however, I would like to copy my part of the .bashrc file concerning the development of my CORBA applications.

BASHRC DESCRIPTION

ACE_ROOT=~/ACE_wrappers
export ACE_ROOT
LD_LIBRARY_PATH=$ACE_ROOT/lib
export LD_LIBRARY_PATH
TAO_ROOT=~/ACE_wrappers/TAO
export TAO_ROOT
CIAO_ROOT=~/ACE_wrappers/TAO/CIAO
export CIAO_ROOT 
 
PATH=$PATH:$LD_LIBRARY_PATH:$ACE_ROOT/bin:$ACE_ROOT

DEFINING THE FOLDER

Let us create a folder in our home directory:

mkdir ~/esempioCORBA

Then put in the directory the IDL file shared by client and server, named Messenger.idl, with the following content:

// Messenger.idl
 
interface Messenger
{
  boolean send_message(in string user_name,
                       in string subject,
                       inout string message);
};

With this simple IDL we want to create an interface with a single send function, used to send a message from the server to the client. This message will be sent as soon as communication between the two is established.

With the command  

tao_idl  Messenger.idl   

you get the following files:

MessengerC.cpp
MessengerC.h
MessengerC.inl
MessengerS.cpp
MessengerS.h
MessengerS.inl

  These files are attached at the following link:  

This step is important while developing the code but it can be skipped if you want to run the overall compilation. In fact, in the final phase of the compilation these files are created again. 

The servant must be implemented with the functionality of the object:

//file Messenger_i.h:
/* -*- C++ -*- $Id: Messenger_i.h 83399 2008-10-22 15:58:30Z sowayaa $ */

// ******  Code generated by the The ACE ORB (TAO) IDL Compiler *******
// TAO and the TAO IDL Compiler have been developed by the Center for
// Distributed Object Computing at Washington University, St. Louis.
//
// Information about TAO is available at:
//                 http://www.cs.wustl.edu/~schmidt/TAO.html

#ifndef MESSENGERI_H_
#define MESSENGERI_H_

#include 'MessengerS.h'

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include 'tao/RTCORBA/RTCORBA.h'

//Class Messenger_i
class  Messenger_i : public virtual POA_Messenger
{
public:
  //Constructor
  Messenger_i(CORBA::ORB_ptr orb);

  //Destructor
  virtual ~Messenger_i();

  virtual CORBA::Boolean send_message(const char* user_name,
                                      const char* subject,
                                      char*& message);

private:
  RTCORBA::Current_var rt_current_;
};


#endif /* MESSENGERI_H_  */


//file Messenger_i.cpp
#include 'amh_pch.h'
/* -*- C++ -*- $Id: Messenger_i.cpp 85583 2009-06-09 13:47:38Z calabrese_p $ */

// ******  Code generated by the The ACE ORB (TAO) IDL Compiler *******
// TAO and the TAO IDL Compiler have been developed by the Center for
// Distributed Object Computing at Washington University, St. Louis.
//
// Information about TAO is available at:
//                 http://www.cs.wustl.edu/~schmidt/TAO.html

#include 'Messenger_i.h'
#include <iostream>
// Implementation skeleton constructor
Messenger_i::Messenger_i (void)
{
}

// Implementation skeleton destructor
Messenger_i::~Messenger_i (void)
{
}

CORBA::Boolean Messenger_i::send_message (
    const char * user_name,
    const char * subject,
    char *& message
  )
{
  std::cout << 'Message from: ' << user_name << std::endl;
  std::cout << 'Subject:      ' << subject << std::endl;
  std::cout << 'Message:      ' << message << std::endl;
  CORBA::string_free(message);
  message = CORBA::string_dup('Thanks for the message.');
  return true;
}

Now we have to write the code that implements the functionality of the client and the server, inheriting the skeletons provided by the compilation of the IDL.    The attachment below contains the other files that are needed:

MessengerClient.cpp
MessengerServer.cpp
started_pch.cpp
started_pch.h

The started files provide additional paths inside the code.

MAKEFILE AND COMPILATION

Before compiling you obviously need a makefile. To get it, you always use a command provided by ACE TAO:  

mwc.pl -type gnuace -recurse -exclude TAO/CIAO -features ssl=1,rpc=1

from inside the directory that contains all the files created.  

To use this command, the directory must contain one more input file, esempioCORBA.mpc   which contains the following code

// $Id: GettingStarted.mpc 979 2008-12-31 20:22:32Z mitza $
 
project(*idl): taoidldefaults {
  idlflags += -Wb,pch_include=started_pch.h
  IDL_Files {
    Messenger.idl
  }
  custom_only = 1
}
 
project(*Server): taoserver {
  exename = MessengerServer
  after += *idl
  Source_Files {
    Messenger_i.cpp
    MessengerServer.cpp
  }
  Source_Files {
    MessengerC.cpp
    MessengerS.cpp
  }
  IDL_Files {
  }
}
 
project(*Client): taoclient {
  exename = MessengerClient
  after += *idl
  Source_Files {
    MessengerClient.cpp
  }
  Source_Files {
    MessengerC.cpp
  }
  IDL_Files {
  }
}

This input file lets the mwc tool understand how to generate the makefile. This tool is very powerful and can create makefiles even for complex structures made of many subfolders

the mwc command creates the following files:

GNUmakefile
GNUmakefile.Messager_Client
GNUmakefile.Messager_Idl
GNUmakefile.Messager_Server

Now everything must be compiled by running the command

make

If there are no further problems, everything compiles correctly and at the end the two executable files are generated in the directory

MessengerClient
MessengerServer

By launching the two executables from two different terminals you can easily see how the server sends the message to the client using the send command defined in the IDL.

CORBA EXAMPLE USING THE NAMESERVICE IN A LINUX ENVIRONMENT

This code was implemented in Visual Studio 2005 Professional and then exported to Linux, only adding the .mpc file needed to build the Makefile.

#compilation:
cd <dir with the code>
mwc.pl -type gnuace -recurse -exclude TAO/CIAO -features ssl=1,rpc=1
make



#esecuzione:

#terminale 1
cd /ACE_wrappers/TAO/orbsvcs/Naming_Service
./Naming_Service -m 1 -ORBEndpoint iiop://localhost:12345




#terminale 2
cd <dir with the code>
SimpleInterfaceServer -ORBDottedDecimalAddresses 1 -ORBInitRef NameService=corbaloc:iiop:localhost:12345/NameService




#terminale 3
cd <dir with the code>
SimpleInterfaceClient -ORBDottedDecimalAddresses 1 -ORBInitRef NameService=corbaloc:iiop:localhost:12345/NameService
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
iElettronica
iElettronica
15 years ago

in seguito descrivero’ accuratamente come un progetto realizzato in Visual C++ puo’ essere esportato in Linux

2
0
Would love your thoughts, please comment.x
()
x