[omniORB] simple problem: ClassA getClassA();

Glenn A. Hochberg ghochberg@att.com
Fri, 22 Sep 2000 09:20:16 -0400


> >#ifndef __TEST_IDL__
> >#define __TEST_IDL__
> >
> >interface ClassA {
> >       void    test();
> >};
> >
> >interface ClassB {
> >       ClassA getClassA();
> >       void    test();
> >};
> >#endif
>
> And now my question is, how do i have to implement the method
> "ClassA getClassA();" ? It should return a pointer to a new ClassA object.

Assuming you are using Omniorb 3.0 and the POA, after you create your servant
and activate it, you obtain an object reference by using _this(), and return it,
e.g.

ClassA_ptr getClassA() {
    ClassA_i *myClassA = new ClassA_i();
    PortableServer::ObjectId_var myClassAid = poa->activate_object(myClassA);
    ClassA_var myClassAref = myClassA->_this();
    myClassA->_remove_ref();
    // above is to bring servant refcount back to 1 -- only POA will have ref.
to servant
    return myClassAref._retn();
}

The above snippet assumes ClassA_i is your servant implementation class for
ClassA.

There are lots of variations on this depending on POA policies, etc.  You should
get yourself a good book on the whole subject, like "Advanced CORBA Programming
with C++" by Henning and Vinoski.

--Glenn
--
Glenn A. Hochberg  | "Any activity becomes creative when the doer
AT&T Labs          |  cares about doing it right, or doing it better."
ghochberg@att.com  |      -John Updike