[omniORB] How to convert an object reference to a servant?

JHJE (Jan Holst Jensen) jhje at novonordisk.com
Wed Sep 20 17:37:08 BST 2006


>>> 		Is there a way to convert an object reference 
>>>         to its servant? 

>> 	The POA method id_to_servant() should fit the bill. If 

> Thanks for your reply.  I tried reference_to_id() and then 
> id_to_servant(), but didn't get the right object returned.  
[...]
> way to do it in omniORB, but so far I'm not successful.  Is 
> this an unusual case for the IDL, ie. you shouldn't allow 
> clients to pass in an object reference as a parameter?

Hi Tuyen.

You are allowed to pass in object references as parameters, no problem.
But getting to the servant instance from the id_to_servant() call is far
more tricky than I initially thought. I eventually got to this

  PortableServer::ServantBase_var servant_base_ref =
the_poa->id_to_servant(id);
  MyObject_i* this_ref =
dynamic_cast<MyObject_i*>(servant_base_ref.in());

after having been past Hennings "Advanced CORBA programming in C++" a
few times (page 499 and 489 are especially helpful).

Cheers
-- Jan



More information about the omniORB-list mailing list