CORBA Anys and TypeCodes Martin Senger senger@ebi.ac.uk.

  • Published on
    17-Dec-2015

  • View
    218

  • Download
    6

Transcript

  • Slide 1
  • CORBA Anys and TypeCodes Martin Senger senger@ebi.ac.uk
  • Slide 2
  • We want something, but we do not know what... Type-safety vs. flexibility type-safe are objects with type known at the compile time - but it limits developers most often the type-safe problems end by crashing programs - but not breaking security inheritance is (probably) also sort of type- unsafe Methods to find the real type: type-casting, narrowing, testing a variable,...
  • Slide 3
  • In CORBA, there are: org.omg.CORBA.Object a super-class to all CORBA Objects represents (only) interfaces narrowing to the real type can be costly Any and we are going to talk about it in details... DynAny thats a new story - an extension of Anys
  • Slide 4
  • A place of Anys in CORBA Entity Object reference Value Type Abstract Interface Basic Value Constructed Values Struct Sequence Union Array Short Long LongLong UShort ULong ULongLong Float Double LongDouble Fixed Char WChar String WString Boolean Octet Enum Any
  • Slide 5
  • Some features... The any type permits the specification of values that can express any OMG IDL type An any contains a TypeCode and a value that is described by the TypeCode Each IDL language mapping provides operations that allow to insert and access the TypeCode and value contained in an any
  • Slide 6
  • Remember: The golden rule You can pass in Any only things whose types are known to the receiving program already in time of compilation Therefore the things in Any can be only basic IDL types (boolean, float,) sequences of (most) basic IDL types String and WString are exceptions types defined in IDL files known to both sites of communication
  • Slide 7
  • Creating Anys (in Java) create an empty Any: Any any = orb.create_any(); insert the value into the Any for basic IDL types: String str = Hello World; any.insert_string (str); for compiled IDL types use their Helper classes: MyClass myClass = new MyClass (); MyClassHelper.insert (any, myClass); for sequences of basic IDL types use their Helper classes that are provided by ORB: int[] myNumbers = new int[] { 1, 2, 3, 4, 6 }; ShortSeqHelper.insert (any, myNumbers);
  • Slide 8
  • Extracting from Anys (in Java) extract the value from an Any for basic IDL types: int number = any.extract_short(); for compiled IDL types use their Helper classes: MyClass myClass = MyClassHelper.extract (any); for sequences of basic IDL types use their Helper classes that are provided by ORB: int[] myNumbers = ShortSeqHelper.extract (any); of course, first you have to know what type you have got in the Any...
  • Slide 9
  • CORBA TypeCodes TypeCodes are values that represent data types TypeCode is described as a CORBA interface with methods to enquire what type it represents, to ask if two TypeCodes are equal or equivalent, and with some exceptions (BadParam, Bounds) TypeCodes are used in Anys, by Interface Repository, by DII, etc...
  • Slide 10
  • The contents of a TypeCode a kind field enum TCKind { tk_null, tk_void, tk_short, tk_long, tk_ushort, tk_ulong, tk_float, tk_double, tk_boolean, tk_char, tk_octet, tk_any, tk_TypeCode, tk_Principal, tk_objref, tk_struct, tk_union, tk_enum, tk_string, tk_sequence, tk_array, tk_alias, tk_except, tk_longlong, tk_ulonglong, tk_longdouble, tk_wchar, tk_wstring, tk_fixed, tk_value, tk_value_box, tk_native, tk_abstract_interface }; a set of parameters appropriate for that kind
  • Slide 11
  • TypeCode parameters From the book: Advanced CORBA Programming with C++ by Michi Henning and Steve Vinoski Each TypeCode has a kind field... and for each kind field it has different parameters
  • Slide 12
  • Some TypeCodes special kinds tk_null this TC does not describe anything (not-there condition) tk_TypeCode to insert TypeCodes into an Any tk_alias describes typedef definitions tk_any because an Any can contain another Any tk_void used in the Interface Repository (never in Anys)
  • Slide 13
  • Where TypeCodes come from dont bother, usually they are created for you Helper classes have method returning TC: TypeCode tc = MyClassHelper.type(); ORB has methods for creating TCs (examples): TypeCode create_struct_tc ( in RepositoryId id, in Identifier name, in StructMemberSeq members); TypeCode get_primitive_tc (in TCKind tcKind);
  • Slide 14
  • Notes on hands-on [skipping Anys => will be done in Property Service hands-on] TypeCodes go to directory TypeCodes compile ExerciseTypeCodes.idl implement conversion methods stringToEnum , enumToString , and printAll in the example ReadingColors.java hint: look what parameters are available for kind enum

Recommended

View more >