Managing your Bank Acount with CORBA dynamic invocation

 

 

In this class you must produce client and server programs based on the CORBA dynamic invocation mechanism. The server program should allow you to withdraw and deposit a sum of money to and from your account and print a balance of your currently cleared funds. The client should send a number of requests to the server to perform a sequence of deposits and withdrawals and finally print out the balance. 

 

Earlier in this course you worked with similar client and server program based on the CORBA static invocation mechanism. To refresh your memory download the following codes from:

 

sample code for static invocation

 

  1. account.idl

 

The IDL interface definition for the account service:

 

interface Account {

       void deposit( in unsigned long amount );

      void withdraw( in unsigned long amount );

      long balance();

};

 

  1. server.cc:

 

Implements the Account interface, e.g.

 

   void deposit (CORBA::ULong amount)

   {

    _current_balance += amount;

   };

 

…and also provides server code in the main method that creates an instance of Account_impl, registering it with BOA and obtaining a reference to it.  This reference is exported into an external file, so the client application can look it up.

 

   Account_impl* server = new Account_impl ;

  

  

   // write object reference to a file

   CORBA::String_var ref = orb->object_to_string(server) ;

   ofstream out ("account.objid") ;

   out << ref << endl ;

   out.close() ;

  

   // tell adapter that impl is ready and run orb

   boa->impl_is_ready(CORBA::ImplementationDef::_nil()) ;

   orb->run() ;

 

  1. client1.cc

 

Retrieves object reference from file and makes calls to known interface of server object -.e.g.

 

CORBA::Object_var obj = orb->string_to_object(ref) ;

   Account_var client = Account::_narrow(obj) ;

 

client->deposit(700) ;

   client->withdraw(200) ;

   cout << "Balance is: " << client->balance() << endl ;

 

  1. compile_idl.sh

 

Generates stub and skeleton code:

 

idl --boa --no-poa account.idl

 

5. compile.sh

 

Compiles the server and client code:

 

mico-c++ -I. -I/server/opt/mico/2.3.10/include -c account.cc -o account.o

mico-c++ -I. -I/server/opt/mico/2.3.10/include -c server1.cc -o server1.o

mico-c++ -I. -I/server/opt/mico/2.3.10/include -c client1.cc -o client1.o

mico-ld -L /server/opt/mico/2.3.10/lib account.o server1.o -lmico2.3.10  -o server1

mico-ld -L /server/opt/mico/2.3.10/lib account.o client1.o -lmico2.3.10  -o client1

 

 

Your task is to replace the method calls in 3 above with dynamic invocations using the Corba Request object. For each request, the client application should create and initialise a Request object (org.omg.CORBA.Request) with the name of the method to invoke, and details of the method’s arguments. Note that you can assume you know the details of the remote method although this is not normally the case where dynamic invocations are used. You should invoke the remote method via the org.omg.CORBA.Request.invoke() method.