Main page / CORBA with MinCor.NET page

Callback - Using Callbacks between CORBA Applications


Description: 
	Most of the examples use a dedicated server process to host the CORBA objects. Within
	this examples, CORBA object IORs will usually be published via flat files or the CORBA 
	Naming Service.
	
	
	Very often it is necessary to have peer-to-peer dialogs between CORBA objects where 
	object references are passed as operation parameters between different processes.
	In this example we create such a dialog using a simple callback pattern.
	

Source: 
	MinCor\Demo\CallBack

Goal: 
	Realize a CORBA peer-to-peer communication using a callback object



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");
        }
    }