Corba Example [PDF]

  • 0 0 0
  • Gefällt Ihnen dieses papier und der download? Sie können Ihre eigene PDF-Datei in wenigen Minuten kostenlos online veröffentlichen! Anmelden
Datei wird geladen, bitte warten...
Zitiervorschau

Interoperability between C++ and Java Objects using CORBA A Tutorial Using C++Builder 4, JBuilder 2 and VisiGenic ORB Furrukh S. Khan Summer 1999

Introduction This is a tutorial, which demonstrates interoperability between Java and C++ objects using CORBA. In this tutorial we implement objects conforming to the following IDL interfaces: module Bank { interface Account { float balance(); }; interface AccountManager { Account open(in string name); }; }; This tutorial specifically uses C++Builder 4 (Enterprise Edition) and JBuilder 2 (Client/Server Edition). Both these products come with VisiGenic, the commercial ORB from Inprise. This tutorial guides you, step by step, to build servers in C++ and Java, which serve objects conforming to the above IDL interfaces, and to build clients in C++ and Java, which use these objects through these interfaces. All the servers and clients built in this tutorial can interoperate, independent of the language of implementation, by using the VisiGenic ORB.

1

C++ Create Folders D:\CorbaDemo D:\CorbaDemo\Cpp D:\CorbaDemo\Cpp\ClientCpp D:\CorbaDemo\Cpp\ServerCpp

C++ Server Start C+Builder4 Start a new CORBA Server project: File->New->Multitier Tag->Corba SERVER Choose Console Application in the wizard Save project: File->Save Save project in D:\CorbaDemo\Cpp\ServerCpp as ServerCpp.bpr C++Builder makes the project and automatically produces a cpp file named ServerCpp.cpp in D:\CorbaDemo\Cpp\ServerCpp //------------------- ServerCpp.cpp ----------------------------#include #pragma hdrstop //--------------------------------------------------------------------#include #include USEIDL("Bank.idl"); USEUNIT("Bank_c.cpp"); USEUNIT("Bank_s.cpp"); //--------------------------------------------------------------------#pragma argsused int main(int argc, char* argv[]) { try { // Initialize the ORB and BOA CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); CORBA::BOA_var boa = orb->BOA_init(argc, argv); // Wait for incoming requests boa->impl_is_ready(); } catch(const CORBA::Exception& e) { cerr CORBA idl File Save it as Bank.idl in D:\CorbaDemo\Cpp\ServerCpp Use the C++Builder editor to enter the following IDL interfaces in Bank.idl: module Bank { interface Account { float balance(); }; interface AccountManager { Account open(in string name); }; };

Compile Bank.idl: Choose Project Manager: view->Project Manager right click on Bank.idl in the Project Manager and choose compile C++Builder produces the following files in the directory D:\CorbaDemo\Cpp\ServerCpp Bank_c.hh (header file for stub classes) Bank_c.cpp (implementation for stub classes) Bank_s.hh (header file for skeleton classes) Bank_s.cpp (implementation for skeleton classes)

Implement the AccountManager and Account Interfaces: Invoke the implementation wizard: File->New->Multitier Tag-> CORBA Object Implementation In the wizard, choose: Unit Name: AccountManagerServer (this is the name of the .h and .cpp files of the AccountManager implementaion, you will need to fill in the implementation details of empty methods in the file AccountManagerServer.cpp) Class Name: AccountManagerImpl (name of the class which implements the AccountManager interface. This class will initially have an empty body, you will need to fill in the implementation details) Deligation Tie: Unchecked In Main: Checked

3

Object Name: AccountManagerObject C++Builder modifies the ServerCpp.cpp file to: //------------------- ServerCpp.cpp ----------------------------#include #pragma hdrstop //--------------------------------------------------------------------#include "AccountManagerServer.h" #include #include USEIDL("Bank.idl"); USEUNIT("Bank_c.cpp"); USEUNIT("Bank_s.cpp"); USEUNIT("AccountManagerServer.cpp"); /* Bank.idl: CORBAIdlFile */ //--------------------------------------------------------------------#pragma argsused int main(int argc, char* argv[]) { try { // Initialize the ORB and BOA CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); CORBA::BOA_var boa = orb->BOA_init(argc, argv); AccountManagerImpl accountManager_AccountManagerObject("AccountManagerObject"); boa->obj_is_ready(&accountManager_AccountManagerObject); // Wait for incoming requests boa->impl_is_ready(); } catch(const CORBA::Exception& e) { cerr Multitier Tag-> CORBA Object Implementation In the wizard, choose: Unit Name: AccountServer (this is the name of the .h and .cpp files of the Account implementaion you will need to fill in the implementation details of empty methods in the file AccountServer.cpp) Class Name: AccountImpl (name of the class which implements the interface. This class will initially have an empty body, you will need to fill in the implementation details)

4

Deligation Tie: unchecked In Main: Checked Object Name: AccountObject CppBuilder modifies the ServerCpp.cpp file to: //------------------- ServerCpp.cpp ----------------------------#include #pragma hdrstop //--------------------------------------------------------------------#include "AccountServer.h" #include "AccountManagerServer.h" #include #include USEIDL("Bank.idl"); USEUNIT("Bank_c.cpp"); USEUNIT("Bank_s.cpp"); USEUNIT("AccountManagerServer.cpp"); /* Bank.idl: CORBAIdlFile */ USEUNIT("AccountServer.cpp"); /* Bank.idl: CORBAIdlFile */ //--------------------------------------------------------------------#pragma argsused int main(int argc, char* argv[]) { try { // Initialize the ORB and BOA CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); CORBA::BOA_var boa = orb->BOA_init(argc, argv); AccountManagerImpl accountManager_AccountManagerObject("AccountManagerObject"); boa->obj_is_ready(&accountManager_AccountManagerObject); AccountImpl account_AccountObject("AccountObject"); boa->obj_is_ready(&account_AccountObject); // Wait for incoming requests boa->impl_is_ready(); } catch(const CORBA::Exception& e) { cerr