Building Applications

Jump directly to:

Getting Started Using Visual C++

Introduction

Setting Up Your Environment

Setting Environment Variables

Setting Windows NT Environment Variables

Setting Windows 2000 Environment Variables

or or

Setting Windows 98 Environment Variables

Setting Visual C++ Options

A Simple Example

Create a Workspace

Create Projects within the Workspace

Interface Definition Language (IDL) File

Create the Messenger_i Implementation Class

      // ****** 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 MESSENGER_I_H_
      #define MESSENGER_I_H_

      #include "MessengerS.h"

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

      //Class Messenger_i
      class Messenger_i : public virtual POA_Messenger
      {
      public:
        //Constructor
        Messenger_i (void);

        //Destructor
        virtual ~Messenger_i (void);

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

      };

      #endif /* MESSENGERI_H_ */
C++ Implementation of the Messenger_i Class
      #include "Messenger_i.h"
      #include <ace/streams.h>

      // 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
        )
        ACE_THROW_SPEC ((
          CORBA::SystemException
        ))
        {
          cout << "Message from: " << user_name << endl;
          cout << "Subject: " << subject << endl;
          cout << "Message: " << message << endl;
          return 1;
        }

Create the Interface Library

C++ Implementation of the MessengerServer

C++ Implementation of the MessengerClient

Build the MessengerServer and MessengerClient

Build the projects

Running the Application

Footnotes for Visual C++ Section

1. The release libraries are ace.lib and tao.lib . The debug libraries are: aced.lib and taod.lib .
2. Instead of typing in each directory path, you may double-click on the empty entry at the bottom of the list, click on the box containing "..." that appears to the right, then select from the Choose Directory dialog box.
3. The command is $(ACE_ROOT)\bin\release\tao_idl.exe -GI $(InputPath) for the Win32 Release configuration.
4. To reduce the amount of typing required, use the Files button to generate $(InputPath) and $(InputName) .


Getting Started on UNIX and UNIX-like Platforms

Introduction

Setting Up Your Environment

Environment Variables

A Simple Example

Create a Workspace

      mkdir Messenger
      cd Messenger

Messenger Interface Definition Language (IDL) File

      // Messenger.idl

      interface Messenger
      {
        boolean send_message(in string user_name,
                             in string subject,
                             inout string message);
      };
Run the IDL Compiler
      $TAO_ROOT/TAO_IDL/tao_idl -GI Messenger.idl

Create the Messenger_i Implementation Class

C++ Header for the Messenger_i Class
     // ******  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 MESSENGER_I_H_
     #define MESSENGER_I_H_

     #include "MessengerS.h"

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

     //Class Messenger_i

     class  Messenger_i : public virtual POA_Messenger
     {
     public:
       //Constructor
       Messenger_i (void);

       //Destructor
       virtual ~Messenger_i (void);

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

     };


     #endif /* MESSENGERI_H_  */
C++ Implementation of the Messenger_i Class
     CORBA::Boolean Messenger_i::send_message (
         const char * user_name,
         const char * subject,
         char *& message
       )
       ACE_THROW_SPEC ((
         CORBA::SystemException
       ))

       {
         cout << "Message from: " << user_name << endl;
         cout << "Subject:      " << subject << endl;
         cout << "Message:      " << message << endl;
         return 1;
       }

C++ Implementation of the MessengerServer

      #include "Messenger_i.h"
      #include <ace/streams.h>

      int
      main(int argc, char * argv[])
      {
        try {
          // Initialize the ORB.
          CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

          // Get a reference to Root POA.
          CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
          PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

          // Activate the POA manager.
          PortableServer::POAManager_var mgr = poa->the_POAManager();
          mgr->activate();

          // Create a Messenger_i servant.
          Messenger_i messenger_servant;

          // Register the servant with the RootPOA, obtain its object reference,
          // stringify it, and write it to a file
          PortableServer::ObjectId_var oid =
            poa->activate_object( &messenger_servant );
          CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
          CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
          ofstream iorFile( "Messenger.ior" );
          iorFile << str.in() << endl;
          iorFile.close();
          cout << "IOR written to file Messenger.ior" << endl;

          // Accept requests from clients.
          orb->run();

          // Release resources.
          orb->destroy();
        }
        catch (const CORBA::Exception & ex) {
          cerr << "Caught a CORBA exception: " << ex << endl;
          return 1;
        }
        return 0;
      }

C++ Implementation of the MessengerClient

     #include "MessengerC.h"
     #include <ace/streams.h>


     int
     main(int argc, char * argv[])
     {
       try {
         // Initialize the ORB
         CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

         // Convert the contents of the file to an object reference.
         CORBA::Object_var obj = orb->string_to_object("file://Messenger.ior");
         if (CORBA::is_nil(obj.in())) {
           cerr << "Nil Messenger reference" << endl;
           throw 0;
         }

         // Narrow the object reference to a Messenger object reference.
         Messenger_var messenger = Messenger::_narrow(obj.in());
         if (CORBA::is_nil(messenger.in ())) {
           cerr << "Not a Messenger object reference" << endl;
           throw 0;
         }

         // Create a message and send it to the Messenger.
         CORBA::String_var message = CORBA::string_dup("Howdy!");
         messenger->send_message ("rick", "Test", message.inout());

         // Release resources.
         orb->destroy();
       }
       catch (const CORBA::Exception & ex) {
         cerr << "Caught a CORBA exception: " << ex << endl;
         return 1;
       }
       catch (...) {
         return 1;
       }

       cout << "Message was sent" << endl;
       return 0;
     }

Create a Makefile to Build the Example

     # IDL_SRCS contains a list of the basenames of the IDL files.
     IDL_SRCS = Messenger

     # SERVER_SRCS contains a list of the source files for building the server.
     SERVER_SRCS = MessengerC.cpp MessengerS.cpp Messenger_i.cpp MessengerServer.cpp
     SERVER_OBJS = $(SERVER_SRCS:.cpp=.o)
     SERVER_BIN = server

     # CLIENT_SRCS contains a list of the source files for building the client.
     CLIENT_SRCS = MessengerC.cpp MessengerClient.cpp
     CLIENT_OBJS = $(CLIENT_SRCS:.cpp=.o)
     CLIENT_BIN = client

     # LDLIBS contains a list of libraries to link with the client and server.
     LDLIBS = -lTAO

     # BIN lists the executables to be built.
     BIN = $(SERVER_BIN) $(CLIENT_BIN)

     # Use .PRECIOUS to preserve certain generated files.
     .PRECIOUS: MessengerC.h MessengerC.i MessengerC.cpp
     .PRECIOUS: MessengerS.h MessengerS.i MessengerS.cpp

     #----------------------------------------------------------------------------
     # Include macros and targets (provided with ACE+TAO)
     #----------------------------------------------------------------------------

     include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
     include $(ACE_ROOT)/include/makeinclude/macros.GNU
     include $(TAO_ROOT)/rules.tao.GNU
     include $(ACE_ROOT)/include/makeinclude/rules.common.GNU
     include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU
     include $(ACE_ROOT)/include/makeinclude/rules.local.GNU
     include $(TAO_ROOT)/taoconfig.mk

     # Target to build the server.
     $(SERVER_BIN): $(addprefix $(VDIR),$(SERVER_OBJS))
     $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK)

     # Target to build the client.
     $(CLIENT_BIN): $(addprefix $(VDIR),$(CLIENT_OBJS))
     $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK)

Build the MessengerServer and MessengerClient

Running the Application

      ./MessengerServer &
      ./MessengerClient
      Message from: rick
      Subject: Test
      Message: Howdy
      message was sent