Example
The IDL (CallBack.idl):
module CallBack
{
// "client" side callback interface:
interface IGreetings
{
string hello( in string strName);
};
// "server" side interface calling back:
interface ISrvAdm
{
void regCallBack( in IGreetings oNameOfInterface);
};
};
(Will be compiled into CallBack.cs)
"Client" Side Callback Object Implementation (within ClientImpl.cs):
Implement the callback class:
public class GreetingsImpl: CallBack.IGreetingsPOA
{
private ClientImpl m_oClientImpl = null;
public GreetingsImpl( ClientImpl a_oClientImpl)
{
m_oClientImpl = a_oClientImpl;
}
override public string hello( string a_strName )
{
m_oClientImpl.CbText = "Callback hallo. Parameter: " + a_strName;
return "Greeting from " + a_strName;
}
}
Create a callback object:
Greetings oGreetings = new Greetings( this );
Retrieve a server reference and send the callback objects servant reference
(obtained by calling its '_this()' method) to the server:
CallBack.ISrvAdm oSrvAdm = CallBack.ISrvAdmHelper.narrow( m_oOrb.string_to_object("file://.\\CallBackSrv.ior"));
oSrvAdm.regCallBack( oGreetings._this() );
Wait for Callbacks:
System.Threading.Thread.Sleep( 1000);
"Server" Side Object Implementation calling back (within ServerImpl.cs):
The server passes the callback object reference into a newly created background thread:
public class SrvAdmImpl: CallBack.ISrvAdmPOA
{
private ServerImpl m_oServer;
public SrvAdmImpl( ServerImpl a_oServer)
{
m_oServer = a_oServer;
}
override public void regCallBack( CallBack.IGreetings a_oNameOfInterface )
{
// Make a call back
a_oNameOfInterface.hello("Hans");
m_oServer.theFrm.writeLog("regCallBack");
}
}