[omniORB] Callback problem

Stefan Seefeld seefeld@sympatico.ca
Fri, 16 Feb 2001 11:24:17 -0500


Andrew Parkin wrote:

> CorbaRemoteSMListenerImpl* corbaRemoteSMListenerImpl = new
> CorbaRemoteSMListenerImpl();
> CORBA::String_var ticketID = e->submitMessageGetEvents(msgStruct,
> (sms::_objref_CorbaRemoteSMListener*)corbaRemoteSMListenerImpl);

uuh, what an evil line of code !
C++ provides type safety not to bypass it with casts, but to guide
you write correct code.

The above lines should read like this:

CorbaRemoteSMListenerImpl* corbaRemoteSMListenerImpl = new 
  CorbaRemoteSMListenerImpl();
sms::CorbaRemoteSMListener_var listener = corbaRemoteSMListenerImpl->_this();

CORBA::String_var ticketID = e->submitMessageGetEvents(msgStruct, listener);


The thing you need to understand is that a servant and a reference are two
distinct types. The '_this()' method provided by servants returns a reference
that you can use in CORBA method invocations.

Stefan