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 J-Integra® Espresso IDL-to-C# mapping, this will result in a separate namespace named '<interface>Package', containing these data types.

Source:

\Demo\ListArrayStruc

Mapping:

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


Example

Step 1. 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)

Step 2. The Server Implementation (LstArrSrv.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;
        
        public override void createGreetingsList( ListArray.GreetingsPackage.ReligiousHoliday[] _arHolidayLst )   
        {
            oTHolidayLst = _arHolidayLst;
            System.Console.WriteLine("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: Ics.CORBA.portable.IDLEntity
            {
                public string strFamilyname;
                public string[] strName;
                public Family( string strFamilyname, string[] strName )   
                {
                    this.strFamilyname = strFamilyname;
                    this.strName = strName;
                }
            }
            
            // [...]
            public struct ReligiousHoliday: Ics.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: Ics.CORBA.portable.IDLEntity
            {
                public const int value = 2;
            }
        }
    }
    

Step 3. The Client (LstArrClt.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:

    Family[] oFamily = m_oIGreetings.hello( a_strHoliday);
    
    Console.WriteLine("\n\n\nGreetings to {0} for:", a_strHoliday);
    
    if( oFamily == null)
    {
        Console.WriteLine("No one to sent greetings to");
        return;
    }
    
    for( int iCnt = 0; iCnt < oFamily.Length; iCnt++)
    {
        Console.Write("\n\tFamily:{0} To ", oFamily[iCnt].strFamilyname);
        foreach( string strFNam in oFamily[iCnt].strName)
        {
            Console.Write("{0} ", strFNam);
        }
    }
    

Step 4. Run the example

a.) Start the Server.

b.) Start the Client.