Discussion:
[omniORB] IDL interface insufficient
David
2008-04-17 20:02:55 UTC
Permalink
Hi,

I'm having a problem with my IDL interface. I have a RemoteProxy class that
wraps an object on the server. On the server side, the factory creating the
RemoteProxy object needs to inject the wrapped object somehow. The interface
of RemoteProxy is however specified in IDL, and I can't specify my wrapped
object in IDL, and hence can't pass it as an argument to an IDL-specified
method.

So far, I have been able to add a RemoteProxy_i.setWrappedObject(
WrappedObject *o ) method to the RemoteProxy_i class, which is my object
implementation class (inheriting from POA_RemoteProxy). So when I create it,
I can do:

RemoteProxy_i *rp = new RemoteProxy_i();
rp->setWrappedObject( o );
poa->activate_object( rp );
RemoteProxy_ptr ref = rp->_this();

Once I've created the reference object "ref", "rp" is not saved. Now, my
problem is that I can't get the wrapped object "o" back from "ref", because
"ref" only implements the IDL interface. How should I solve this? Do I need
an external data structure, mapping references to "wrapped objects" (except
they wouldn't be mapped in an object-oriented sense). Any help is
appreciated.

/David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20080417/078533a5/attachment.htm
Michael
2008-04-17 20:35:13 UTC
Permalink
Hi David,

seems like you're using the default poa. What you could do is the following:

Assuming you a method that accepts a ref reference:

void MyObject::MyMethod(RemoteProxy_ptr p)
{
try
{
PortableServer::Servant servant = poa_->reference_to_servant(p)
if (RemoteProxy_i* rp = dynamic_cast<RemoteProxy_i*>(servant))
{
WrappedObject* o = rp->getWrapedObject();
}
}
catch(...)
{
// there are different (meaningful) exceptions emitted, check the standard
}
}
(this assumes, you stored the poa used somewhere - 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 oa (and
not a remote object).

cheers
michael
Post by David
Hi,
I'm having a problem with my IDL interface. I have a RemoteProxy class that
wraps an object on the server. On the server side, the factory creating the
RemoteProxy object needs to inject the wrapped object somehow. The interface
of RemoteProxy is however specified in IDL, and I can't specify my wrapped
object in IDL, and hence can't pass it as an argument to an IDL-specified
method.
So far, I have been able to add a RemoteProxy_i.setWrappedObject(
WrappedObject *o ) method to the RemoteProxy_i class, which is my object
implementation class (inheriting from POA_RemoteProxy). So when I create it,
RemoteProxy_i *rp = new RemoteProxy_i();
rp->setWrappedObject( o );
poa->activate_object( rp );
RemoteProxy_ptr ref = rp->_this();
Once I've created the reference object "ref", "rp" is not saved. Now, my
problem is that I can't get the wrapped object "o" back from "ref", because
"ref" only implements the IDL interface. How should I solve this? Do I need
an external data structure, mapping references to "wrapped objects" (except
they wouldn't be mapped in an object-oriented sense). Any help is
appreciated.
/David
------------------------------------------------------------------------
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
David
2008-04-17 22:50:01 UTC
Permalink
Hi Michael,

This is a great tip. Thanks a lot.

/David
Post by Michael
Hi David,
void MyObject::MyMethod(RemoteProxy_ptr p)
{
try
{
PortableServer::Servant servant = poa_->reference_to_servant(p)
if (RemoteProxy_i* rp = dynamic_cast<RemoteProxy_i*>(servant))
{
WrappedObject* o = rp->getWrapedObject();
}
}
catch(...)
{
// there are different (meaningful) exceptions emitted, check the standard
}
}
(this assumes, you stored the poa used somewhere - 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 oa (and
not a remote object).
cheers
michael
Post by David
Hi,
I'm having a problem with my IDL interface. I have a RemoteProxy class
that
Post by David
wraps an object on the server. On the server side, the factory creating
the
Post by David
RemoteProxy object needs to inject the wrapped object somehow. The
interface
Post by David
of RemoteProxy is however specified in IDL, and I can't specify my
wrapped
Post by David
object in IDL, and hence can't pass it as an argument to an
IDL-specified
Post by David
method.
So far, I have been able to add a RemoteProxy_i.setWrappedObject(
WrappedObject *o ) method to the RemoteProxy_i class, which is my object
implementation class (inheriting from POA_RemoteProxy). So when I create
it,
Post by David
RemoteProxy_i *rp = new RemoteProxy_i();
rp->setWrappedObject( o );
poa->activate_object( rp );
RemoteProxy_ptr ref = rp->_this();
Once I've created the reference object "ref", "rp" is not saved. Now, my
problem is that I can't get the wrapped object "o" back from "ref",
because
Post by David
"ref" only implements the IDL interface. How should I solve this? Do I
need
Post by David
an external data structure, mapping references to "wrapped objects"
(except
Post by David
they wouldn't be mapped in an object-oriented sense). Any help is
appreciated.
/David
------------------------------------------------------------------------
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20080417/37475e0d/attachment.htm
Martin Trappel
2008-04-18 16:45:05 UTC
Permalink
Post by Michael
Hi David,
void MyObject::MyMethod(RemoteProxy_ptr p)
{
try
{
PortableServer::Servant servant = poa_->reference_to_servant(p)
if (RemoteProxy_i* rp = dynamic_cast<RemoteProxy_i*>(servant))
{
WrappedObject* o = rp->getWrapedObject();
}
}
catch(...)
{
// there are different (meaningful) exceptions emitted, check the standard
}
}
(this assumes, you stored the poa used somewhere - 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 oa (and
not a remote object).
I though I might throw in what I used for this, maybe it's useful to
someone else ...

br,
Martin

[CODE]
//////////////////////////////////////////////////////////////////////
template<class ITF_IMPL_T, class POA_T, class ITF_PTR_T>
inline PortableServer::Servant_var<ITF_IMPL_T>
get_implemenation(POA_T poa, ITF_PTR_T itf_ptr_obj)
{
if(CORBA::is_nil(itf_ptr_obj))
return NULL;
else
return dynamic_cast<ITF_IMPL_T*>(
poa->reference_to_servant(itf_ptr_obj) );
}

//////////////////////////////////////////////////////////////////////
#define IMPL_OBJ(t, v)
get_implemenation<t>(PortableServer::POA_var(_default_POA()), v)

// Usage:
MyServant_i* p = IMPL_OBJ(ACI_MyServant_i, interface_ptr);
if(p) { ... }

[/CODE]

Loading...