8.3 The Anatomy of a Basic CORBA Consumer

One of the most common models for distributed programming is the consumer-producer model. In this model, one program plays the role of producer and another plays the role of consumer. The producer creates some service or data used by a consumer. For example, we could have a program that generates unique license plate numbers upon demand. The consumer is the program that makes requests for new license plate numbers and the producer is the program that generates the license plate numbers . Typically, the consumer and producer are located in different address spaces. Figure 8-4 shows several components and steps that most CORBA consumer programs contain.

Figure 8-4. Components and steps used by a CORBA consumer program.

graphics/08fig04.gif

To communicate with objects on other computers or in different address spaces, each program involved in the communication must declare an ORB object. Once the Orb object is declared, then the consumer program has access to its member functions. In Figure 8-4, the ORB is initialized using the call:

 CORBA::ORB_var Orb = CORBA::ORB_init(argc,argv,"mico-local-orb"); 

This initializes an ORB object. The CORBA::ORB_var type is a handle to an object of type ORB. In CORBA implementations , objects that have the _var designation take care of deallocating its underlying reference. This is in contrast to the objects that have the _ptr designation. The command-line arguments are passed to the ORB's constructor along with an orb_id . In our case, the orb_id is "mico-local-orb" . The string passed to the ORB_init() function that names the ORB to be initialized is implementation specific and can differ between implementations. The derived object is referred to as the servant object.

Once the ORB and the object adapter are initialized, the next basic component that any CORBA application will need is the IOR for the remote object(s). In Figure 8-4, the IOR is retrieved from a file named adding_machine.ior . The IOR has been written in its stringified form to the file. The ORB object is used to convert the IOR from a string back to its object form using its string_to_object() method. In Figure 8-4, this is accomplished by the call:

 CORBA::Object_var Obj = Orb->string_to_object(Ior.c_str()); 

Here, Ior.c_str() returns the stringified IOR and Obj will be a reference to the object form of the IOR. The object form of the IOR is then narrowed. This narrowing process is analogous to C++ type casting. The narrowing process sizes an object reference to the appropriate object type. In this case, the appropriate type is adding_machine The consumer program in Figure 8-4 narrows the IOR object using the call:

 adding_machine_var Machine = adding_machine::_narrow(Obj); 

This process creates a reference to an adding_machine object. The consumer program can now call the methods defined in the IDL interface for the adding_machine class. For instance:

 Machine->add(500); Machine->subtract(125); 

call the add() and subtract() methods of the remote object. Although the consumer program in Figure 8-4 is an oversimplified consumer, it does show the basic components of a typical CORBA consumer or client program. The consumer program requires a producer program in order for the application to be complete. We will look at a simplified CORBA program that acts as the producer for the program in Figure 8-4.



Parallel and Distributed Programming Using C++
Parallel and Distributed Programming Using C++
ISBN: 0131013769
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net