[omniORB] How to convert an object reference to a servant?
Duncan Grisby
duncan at grisby.org
Wed Sep 20 19:50:08 BST 2006
On Wednesday 20 September, "JHJE (Jan Holst Jensen)" wrote:
> >>> Is there a way to convert an object reference
> >>> to its servant?
>
> >> The POA method id_to_servant() should fit the bill. If
There's no need to use reference_to_id then id_to_servant -- you can
just use reference_to_servant to go there directly.
Note that in case it's not obvious, you have to call these methods on
the POA that the servant is activated in, otherwise you get exceptions.
[...]
> 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());
Yes, that's what you have to do -- I don't think it's tricky to have to
use dynamic_cast<> -- there's no other way you could do it, since the
class you want to cast to is application-defined.
Cheers,
Duncan.
--
-- Duncan Grisby --
-- duncan at grisby.org --
-- http://www.grisby.org --
More information about the omniORB-list
mailing list