[omniORB] Help for a beginner

Michael omniorb at bindone.de
Fri Aug 1 20:09:49 BST 2008


Hi Michel,

Test::B_ptr BFactory_i::createB(Test::A_ptr a)
{
  try
  {
    PortableServer::Servant servant = poa_->reference_to_servant(a)
    if (A_i* aimpl = dynamic_cast<A_i*>(servant))
    {
      return aimpl->createBFromThis(); // example
    }
  }
  catch(...)
  {
    // there are different (meaningful) exceptions emitted, check the
    //  standard
    std::cerr << "exception" << std::endl;
  }
  throw CORBA::BAD_PARAM();
}

(this assumes, you stored the poa used in poa_ - if it's the default poa
you could also get it through resolve_initial_reference)

This is also nice, because you can verify that the servant is really out
of this poa (and not a remote object).

The following calling conventions exist for reference_to_servant:

"This operation returns the servant associated with the object reference
if the RETAIN policy is set and the object is present in the active
object map. If the POA has the USE_DEFAULT_SERVANT policy and a default
servant has been registered with the POA, the default servant is
returned. If the object reference was not created by this POA, the
WrongAdapter exception is raised."

Exceptions:
WrongPolicy	An error occurs if neither the RETAIN nor the
                USE_DEFAULT_SERVANT policy was specified.
ObjectNotActive An error occurs if the RETAIN policy was specified and
                the object is not in the active object map.
WrongAdapter    An error occurs if the the reference does not belong to
                this POA.

cheers
michael

debutant wrote:
> Hello Michael,
> 
> Thanks a lot for your reply. 
> 
> I practised few exercices but none of them involved inheritance. 
> I could not write an implementation for the example you gave me.
> 
> I ordered the book you suggested. Waiting for it I would like to 
> ask you a last question:
> 
> Is it possible, on the server side, to convert a pointer to an 
> object reference A_ptr into a pointer to the instante of A_i it is related
> to ?
> 
> Thanks.
> Sincerely,
> Michel




More information about the omniORB-list mailing list