160 likes | 418 Views
OmniORB. An Introduction. Michael E. Kounavis Dept. of Electrical Engineering Columbia University http://comet.columbia.edu/~mk mk@comet.columbia.edu. TUTORIAL 2. 15 October, 1998. OMA. Application Interfaces. Domain Interfaces. Common Facilities. ORB. Object Services. CORBA.
E N D
OmniORB An Introduction Michael E. Kounavis Dept. of Electrical Engineering Columbia University http://comet.columbia.edu/~mk mk@comet.columbia.edu TUTORIAL 2 15 October, 1998
OMA Application Interfaces Domain Interfaces Common Facilities ORB Object Services
CORBA client Object implementation DSI IDL Skel. DII IDL stub ORB Intf OA ORB core
OmniORB • CORBA2 compliant • multithreaded • Supports unique IDL to C++ mappings • but • persistent severs only • no DSI, DII • no IR
Building a distributed system application • Define the object interface in IDL • use the IDL compiler to generate stub code • provide the object implementation • write the client code
A simple IDL file interface Echo { string echoString(in string mesg); }; • compile with omniidl2 • generates a c++ header file and a C++ source file • echo.hh • echoSK.cc this is the skeleton file!
What does echo.hh contain? (I) class Echo; typedef Echo* Echo_ptr; class Echo: public virtual omniObject, public virtual CORBA::Object { public: virtual char * echoString ( const char * mesg ) = 0; static Echo_ptr _nil(); static Echo_ptr _duplicate(Echo_ptr); static Echo_ptr _narrow(CORBA::Object_ptr); // . . . };
What does echo.hh contain? (II) • Echo_ptr is an object reference to the object Echo • Use _nil(), is_nil(), _duplicate(), _narrow(), _is_equivalent() to manipulate object references • Don’t use operators such as (void *), = , == etc. for object references • Object references should be explicitly release with CORBA::release operation • Echo_var variables are automatically released though. • Interchanging Echo_ptr and Echo_var is valid, although casting might be needed;
What does the Skeleton contain? (I) Class _sk_Echo : public virtual Echo { public: _sk_Echo(const omniORB::objectKey& k); virtual char * echoString (const char * mesg) = 0; Echo_ptr _this(); void _obj_is_ready(BOA_ptr); void _dispose(); BOA_ptr _boa(); OmniORB::objectKey _key(); // . . . };
What does the Skeleton contain? (II) • _sk_Echo is an abstract class • through the abstract function echoString() the implementation class provides the implementation for the echoString Operation. • _this() returns an objct reference for the target object • _obj_is _ready tells the BOA that the object is ready to serve • _dispose tells the BOA to dispose the object • _boa returns a reference to the BOA that serves the object • _key identifies the object
Providing an object implementation • class Echo_i : public virtual _sk_Echo { public Echo_i() {} virtual ~Echo_i() {} virtual char (* echiString(const char *mesg); }; char* Echo_i::echoString(const char *mesg) { char *p = CORBA::string_dup(mesg); return p; } • The implementation class Echo_i inherits from the skeleton
Writing the client void hello (CORBA::Object_ptr obj) { Echo_var e = Echo::_narrow(obj); if (CORBA::is_nil(e)) { cerr << “hello cannot invoke a nil object” << endl; return; } CORBA::String_var src = (const char*) “Hello!” CORBA::String_var dest; dest = e->echoString(src); } • It is straightforward!
Writing the Server • First get a reference to ORB and BOA CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv, “omniORB2”); CORBA::ORB_ptr boa = orb->BOA_init(argc, argv, “omniORB2_BOA”); • Instantiate the implementation object Echo_i *my_obj = new Echo_i(); myobj->_obj_is_ready(boa); • Get an object reference (in order to bind to a name) Echo_var myobjRef = my_obj->_this(); • Call impl_is_ready() boa->impl_is_ready();
How does the client get the target object reference? • Via stringified form • Via naming service • OmniNames • centralized not distributed • OmniNames • Name database structured as a tree • Root is for the Naming Service object itself
References • Sai-Lai Lo “The omniORB2 version 2.5 User’s Guide”, Olivetti and Oracle research laboratory, Feb. 1998 Chapter 2, “The Basics” (required) • Steve Vinosky “CORBA, Integrating Diverse Applications within Heterogeneous Distributed Environments”, IONA Technologies (recommended)
Homework • IDL for the server is given: • interface CookieServer { string getCookie(in string email); // returns the cookie string testCookie(in string email, in string cookie); // returns the response }; • Date posted: 10/16/98 • Date due: 10/27/98