Discussion:
[omniORB] How to convert an object reference to a servant?
Tuyen Chau
2006-09-18 21:51:38 UTC
Permalink
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060918/52594fac/attachment.htm
JHJE (Jan Holst Jensen)
2006-09-19 13:49:17 UTC
Permalink
Is there a way to convert an object reference to its servant?
We are porting this Orbix server application to omniORB. One
Dear Tuyen.

The POA method id_to_servant() should fit the bill. If you are using a
POA with a proper policy that is...

See e.g. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4655385 for
more.

Cheers
-- Jan Holst Jensen, Novo Nordisk A/S, Denmark
Tuyen Chau
2006-09-20 02:30:08 UTC
Permalink
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060919/18eceab3/attachment.htm
JHJE (Jan Holst Jensen)
2006-09-20 20:39:43 UTC
Permalink
Post by JHJE (Jan Holst Jensen)
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
Tim Theisen
2006-09-20 20:58:31 UTC
Permalink
In the example given below. You can easily call getBalance() with the
Account_ptr.

double balance = account->getBalance();

I don't see any need to get an Account_I *.

...Tim
--
Tim Theisen Lead Research Software Engineer
Phone: +1 608 824 2848 TomoTherapy Incorporated
Fax: +1 608 824 2996 1240 Deming Way
Web: http://www.tomotherapy.com <http://www.tomotherapy.com/>
Madison, WI 53717-1954





________________________________

From: omniorb-list-***@omniorb-support.com
[mailto:omniorb-list-***@omniorb-support.com] On Behalf Of Tuyen
Chau
Sent: Tuesday, September 19, 2006 15:29
To: JHJE (Jan Holst Jensen)
Cc: OmniOrb
Subject: Re: [omniORB] How to convert an object reference to a servant?


Since I didn't make myself very clear in the topic, let me give you an
example this time. Consider this IDL,

interface Account {
double getBalance();
...
};

interface BankManager {
Account getAccount( in string name );

void deleteAccount( in account);
};

The implementation that I'm having trouble with is deleteAccount(). The
C++ code looks something like this,

void BankManager_I::deleteAccount( Account_ptr account )
{
//
// Here I want to access the "account" implementation. How do I do
it?
// Somehow I will need to convert Account_ptr to (Account_I *)
//
Account_I *account_i;
.....
}

As you can see in the code above, I would like to be able to get access
to the implementation of the "account" object, passed in from the
client. How do I do that? Orbix provides the _deref() function to do
this, and I'm hoping there is a 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?

Thanks again for any information that you can provide,
Tuyen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060920/f98dd1c3/attachment.htm
Tuyen Chau
2006-09-21 03:08:27 UTC
Permalink
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060920/d701e708/attachment.htm
Duncan Grisby
2006-09-20 23:50:02 UTC
Permalink
Post by JHJE (Jan Holst Jensen)
Post by JHJE (Jan Holst Jensen)
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.

[...]
Post by JHJE (Jan Holst Jensen)
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 --
-- ***@grisby.org --
-- http://www.grisby.org --
Tuyen Chau
2006-09-21 03:04:05 UTC
Permalink
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20060920/0bb9c45f/attachment.htm
JHJE (Jan Holst Jensen)
2006-09-22 01:19:51 UTC
Permalink
Just a small question though. I'm using the default POA
policy so there should be only POA in this application. Is
there a way to query the object reference for its POA? If
not, I can keep the POA in a global place but just thought
that if there was a way to get to it, I wouldn't even have to do that.
Hi Tuyen.

I can't say that I know of a standard way of getting a servant's POA by
querying it. There is _default_POA(), but that returns the root POA and
not necessarily the servant's POA. _default_POA() can be overridden, but
is that a good idea, considering its name ?

I'd say go with the global reference to the POA or keep it in a servant
member variable. Check for instance omniNames - look in
NamingContext_i.cc, search for "nc_poa".

Cheers
-- Jan Holst Jensen, Novo Nordisk A/S, Denmark
Duncan Grisby
2006-09-25 01:44:12 UTC
Permalink
Post by JHJE (Jan Holst Jensen)
I can't say that I know of a standard way of getting a servant's POA by
querying it. There is _default_POA(), but that returns the root POA and
not necessarily the servant's POA. _default_POA() can be overridden, but
is that a good idea, considering its name ?
The whole point of _default_POA() is that servants override it to return
the POA they want to be activated in. _default_POA() is used to decide
which POA to activate in with the _this() call.

Tuyen is interested in getting the POA for an object reference, not from
a servant, so it's irrelevant for that case anyway.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Continue reading on narkive:
Loading...