Main page / CORBA with MinCor.NET page

ListArrayStruc - Using IDL Sequences, Arrays & Structs


Description: 
	CORBA IDL arrays as well as sequences will both be mapped into C# arrays. IDL structs
	result in C# structs.
	
	Complex and constructed IDL data types may be declared within the scope of an interface.
	According to the MinCor.NET IDL-to-C# mapping, this will result in a separate namespace 
	named '<interface>Package', containing these data types.

Source: 
	MinCor\Demo\ListArrayStruc

Mapping: 
	CORBA IDL array     <--->  C# array
	CORBA IDL sequence  <--->  C# array
	CORBA IDL struct    <--->  C# struct



Example 

The IDL (ListArray.idl):

    
    module ListArray
    {
        interface Greetings
        {
            // IDL sequence with fixed size:
            typedef sequence  TNameLst;
            
            struct Family
            {
                string   strFamilyname;
                TNameLst strName;
            };
            
            // IDL sequence with dynamic size:
            typedef sequence  TFamilyLst;
            
            struct ReligiousHoliday
            {
                string     strHolidayName;
                TFamilyLst lstFamilys;
            };
            
            //  IDL array:
            const long maxReligiousHolidays = 2;
            typedef ReligiousHoliday THolidayLst[maxReligiousHolidays];
            
            // some operations:
            void createGreetingsList( in THolidayLst arHolidayLst);
            
            TFamilyLst hello( in string strHolidayName);
        };
    };
    
    (Will be compiled into ListArray.cs)


The Implementation (ServerImpl.cs):

    Because the data types declared within the IDL will be completely generated, we have only to 
    implement the methods:
    
    public class GreetingsImpl:	ListArray.GreetingsPOA
    {
        private ReligiousHoliday[] oTHolidayLst;
        private ServerImpl m_oServer;
        
        public GreetingsImpl( ServerImpl a_oServer)
        {
            m_oServer = a_oServer;
        }
        
        public override void createGreetingsList(  ReligiousHoliday[] _arHolidayLst  )
        {
            oTHolidayLst = _arHolidayLst;
            m_oServer.theFrm.writeLog(  "get GreetingsList");
        }
        
        public override ListArray.GreetingsPackage.Family[] hello(  string _strHolidayName  )
        {
            for ( int iCnt = 0; iCnt < oTHolidayLst.Length; iCnt++)
            {
                if( oTHolidayLst[iCnt].strHolidayName == _strHolidayName)
                {
                    return oTHolidayLst[iCnt].lstFamilys;
                }
            }
            return null;
        }
    }
    
    
    Note, that all data types and constants defined within the scope of the interface 'Greetings' 
    will be generated into a separate package 'GreetingsPackage' (ListArray.cs):
    
    namespace ListArray
    {
        namespace GreetingsPackage
        {
            // [...]
            public struct Family: Middsol.CORBA.portable.IDLEntity
            {
                public string strFamilyname;
                public string[] strName;
                public Family( string strFamilyname, string[] strName )
                {
                    this.strFamilyname = strFamilyname;
                    this.strName = strName;
                }
            }
            
            // [...]
            public struct ReligiousHoliday: Middsol.CORBA.portable.IDLEntity
            {
                public string strHolidayName;
                public ListArray.GreetingsPackage.Family[] lstFamilys;
                public ReligiousHoliday( string strHolidayName, ListArray.GreetingsPackage.Family[] lstFamilys )
                {
                    this.strHolidayName = strHolidayName;
                    this.lstFamilys = lstFamilys;
                }
            }
            
            public struct maxReligiousHolidays: Middsol.CORBA.portable.IDLEntity
            {
                public const int value = 2;
            }
        }
    }
    
    
    
The Client (ClientImpl.cs):

    Data will be passed by value, so we create an array (corresponding to an IDL array of structs,
    containing sequences of structs, which in turn contain a fixed size sequence of strings)
    locally, fill it and pass it to the server:
    
    ReligiousHoliday[] oTHolidayLst = new ReligiousHoliday[maxReligiousHolidays.value];
    
    // Add christmas
    oTHolidayLst[0].strHolidayName = "Christmas";
    oTHolidayLst[0].lstFamilys = new Family[2];
    
    // Family Mayer
    String[] strFirstNamesMayer = {"Hans", "Anna", "Fred"};
    oTHolidayLst[0].lstFamilys[0] = new Family( "Mayer", strFirstNamesMayer);
    
    // Family Schmidt
    String[] strFirstNamesSchmidt = {"Klaus", "Sofie", "Jesse", "Andre"};
    oTHolidayLst[0].lstFamilys[1] = new Family( "Schmidt", strFirstNamesSchmidt);
    
    // Add eastern
    oTHolidayLst[1].strHolidayName = "Eastern";
    oTHolidayLst[1].lstFamilys = new Family[3];
    
    // Family Mayer
    oTHolidayLst[1].lstFamilys[0] = new Family( "Mayer", strFirstNamesMayer);
    
    // Family Schmidt
    oTHolidayLst[1].lstFamilys[1] = new Family( "Schmidt", strFirstNamesSchmidt);
    
    // Family Fischer
    String[] strFirstNamesFischer = {"Lory", "Dave", "Meike"};
    oTHolidayLst[1].lstFamilys[2] = new Family( "Fischer", strFirstNamesFischer);
    
    // Set HolidayList
    m_oIGreetings.createGreetingsList( oTHolidayLst);
    
    
    Arrays corresponding IDL sequences may also be obtained from the remote server:
    
    a_strMsg += "\nCall Hallo";
    Family[] oFamily = a_oIGreetings.hello( a_strHoliday);
    
    a_strMsg += "\nGreetings to " + a_strHoliday;
    
    if( oFamily == null)
    {
        a_strMsg += "\nNo one to sent greetings to";
        return;
    }
    
    for( int iCnt = 0; iCnt < oFamily.Length; iCnt++)
    {
        a_strMsg += "\nFamily:" + oFamily[iCnt].strFamilyname + " To ";
        foreach( string strFNam in oFamily[iCnt].strName)
        {
            a_strMsg += "\n" + strFNam;
        }
    }