wm withdraw .; wm withdraw .output; wm geom .konsola 829x629+183+7; kons_font 16 kons_font 13; # Morasko ## wyciaganie CDR z roznych brokerow corby... 08.2016 # + cel: PRJ dla TAS # + sa problemy z JavaIDL... # tylko w combacie to jest proste... # nie wiem jak z mico... # + corba spec: "corba 3.3 interoperability.pdf", str 85 # widac ze strony negocjuja "endian", encoding(?), ... # + CDR umozliwia wysylanie danych z opisem typu (TC), # lub samych tylko danych... # + UWAGA: ciagle nie wiem jak obsluzyc wstring!! # trzeba podac opcje wencoding i cencoding w buforze...??? # ale jakie? patrz przyklad z "x5" # # ... # CDR z combata # + mozna wielokrotnie wywolac Marshal/Demarshal # + typy i liczba wart. musza sie zgadzac... # + typecode mozna wyciagac z IR... # + wnioski: calkiem wygodne, ale jak jest w innych brokerach ?!? # PRJ dla TAS ?!?!!?!? # + widac ze dzialanie CDR wymaga dluzszch eksperymentow # oraz czytania rozdzialu o CDR ze spec Corby... # proc e args {catch $args err; set err} lappend auto_path ../combat-tcl-0.7.4; package re combat #% 0.7 Combat::CDR::Encoder e1 e1 Marshal {sequence long} {1 2 3} e1 Marshal {sequence long} {44 5 6 7} set x1 [e1 get_data] itcl::delete object e1 Combat::CDR::Decoder d1 $x1 d1 Demarshal {sequence long} #% 44 5 6 7 #% 1 2 3 # + musimy wiedziec ze sa 2 wartosci!! itcl::delete object d1 binary scan $x1 c* xx1; set xx1 #% 3 0 0 0 1 0 0 0 2 0 0 0 3 0 0 0 4 0 0 0 44 0 0 0 5 0 0 0 6 0 0 0 7 0 0 0 Combat::CDR::Encoder e1 [e1 get_buffer] configure -byteorder 0 # + zmiana endian !! e1 Marshal {array long 3} {1 2 3} set x2 [e1 get_data] itcl::delete object e1 Combat::CDR::Decoder d1 $x2 [d1 get_buffer] configure -byteorder 0 d1 Demarshal {array long 3} #% 1 2 3 itcl::delete object d1 binary scan $x2 c* xx1; set xx1 #% 0 0 0 1 0 0 0 2 0 0 0 3 #% 1 0 0 0 2 0 0 0 3 0 0 0 # + dlaczego "1 0 0 0" a nie "0 0 0 1" ? odp: endian... # mozna zmienic endian, ale trzeba byc konsekw.!! Combat::CDR::Encoder e1 [e1 get_buffer] configure -byteorder 0 e1 Marshal any {{array long 3} {1 2 3}} set x3 [e1 get_data] itcl::delete object e1 Combat::CDR::Decoder d1 $x3 [d1 get_buffer] configure -byteorder 0 d1 Demarshal any #% {array long 3} {1 2 3} itcl::delete object d1 binary scan $x3 c* xx1; set xx1 #% 0 0 0 20 0 0 0 12 0 102 111 111 0 0 0 3 0 0 0 3 0 0 0 1 0 0 0 2 0 0 0 3 string len $x3 #% 32 Combat::CDR::Encoder e1 [e1 get_buffer] configure -byteorder 0 e1 Marshal TypeCode {array long 3} set x4 [e1 get_data] itcl::delete object e1 Combat::CDR::Decoder d1 $x4 [d1 get_buffer] configure -byteorder 0 d1 Demarshal TypeCode #% array long 3 itcl::delete object d1 binary scan $x4 c* xx1; set xx1 #% 0 0 0 20 0 0 0 12 0 102 111 111 0 0 0 3 0 0 0 3 # + widac ze "any" to "TypeCode+wartosc" ! string len $x4 #% 20 # + 1 long to dlugosc TC ?? set conv1 [Combat::CONV_FRAME::getConverter 1 2 65538] # + 65538, 65792, 83951617 - zaden nie dziala z JavaIDL... # patrz plik codeset.tcl combata... # ktory kod jest std w JavaIDL?? jak to sprawdzic??? Combat::CDR::Encoder e1 [e1 get_buffer] configure -byteorder 0 #e e1 Marshal wstring {A ku ku !!! ³³³ ¶¶¶} #% no wchar encoder in ::Combat::CDR::WriteBuffer::wstring # + trzeba zdef ten encoder !?!?!?!!? [e1 get_buffer] configure -wencoder $conv1 e1 Marshal wstring {A ku ku !!! ³³³ ¶¶¶} set x5 [e1 get_data] itcl::delete object e1 #itcl::delete object $conv1 Combat::CDR::Decoder d1 $x5 [d1 get_buffer] configure -byteorder 0 -wdecoder $conv1 d1 Demarshal wstring #% A ku ku !!! ³³³ ¶¶¶ itcl::delete object d1 binary scan $x5 c* xx1; set xx1 #% 0 0 0 19 65 32 107 117 32 107 117 32 33 33 33 32 -77 -77 -77 32 -74 -74 -74 Combat::CDR::Encoder e1 [e1 get_buffer] configure -byteorder 0 e1 Marshal string {A ku ku !!!} set x6 [e1 get_data] itcl::delete object e1 Combat::CDR::Decoder d1 $x6 [d1 get_buffer] configure -byteorder 0 d1 Demarshal string #% A ku ku !!! itcl::delete object d1 binary scan $x6 c* xx1; set xx1 #% 0 0 0 12 65 32 107 117 32 107 117 32 33 33 33 0 string len {A ku ku !!!} #% 11 # + 12 = 11+1 ??? (zero) # + typ "string" nie wymaga zadnego encodera! # dane z mico/prog000... TC tab1 + arr[3] set x7 {0 0 0 21 0 0 0 60 0 0 0 0 0 0 0 17 73 68 76 58 113 113 113 47 116 97 98 49 58 49 46 48 0 0 0 0 0 0 0 5 116 97 98 49 0 0 0 0 0 0 0 20 0 0 0 12 0 0 0 0 0 0 0 3 0 0 0 3 0 0 0 11 0 0 0 22 0 0 0 33 } set x8 [binary format c* $x7] Combat::CDR::Decoder d1 $x8 [d1 get_buffer] configure -byteorder 0; # BigEndian d1 Demarshal any #% {array long 3} {11 22 33} # + wszystko sie zgadza!! itcl::delete object d1 # dane z mico2/prog000... TC tab2 + seq_long set x7 {0 0 0 19 0 0 0 12 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 3 0 0 0 44 0 0 0 55 0 0 0 66} set x8 [binary format c* $x7] Combat::CDR::Decoder d1 $x8 [d1 get_buffer] configure -byteorder 0; # BigEndian d1 Demarshal any #% {sequence long} {44 55 66} # + ok!!! itcl::delete object d1 # dane z mico2/prog000... TC str1 + str1 set x8 [binary format c* { 0 0 0 15 0 0 0 72 0 0 0 0 0 0 0 17 73 68 76 58 113 113 113 47 115 116 114 49 58 49 46 48 0 0 0 0 0 0 0 5 115 116 114 49 0 0 0 0 0 0 0 2 0 0 0 2 97 0 0 0 0 0 0 3 0 0 0 2 98 0 0 0 0 0 0 18 0 0 0 0 0 0 0 123 0 0 0 12 65 32 107 117 32 107 117 32 33 33 33 0 }] Combat::CDR::Decoder d1 $x8 [d1 get_buffer] configure -byteorder 0; # BigEndian d1 Demarshal any #% {struct IDL:qqq/str1:1.0 {a long b string}} {a 123 b {A ku ku !!!}} itcl::delete object d1 # dane z mico2/prog000... TC str2 + str2 set x8 [binary format c* { 0 0 0 15 0 0 0 224 0 0 0 0 0 0 0 17 73 68 76 58 113 113 113 47 115 116 114 50 58 49 46 48 0 0 0 0 0 0 0 5 115 116 114 50 0 0 0 0 0 0 0 4 0 0 0 2 97 0 0 0 0 0 0 3 0 0 0 2 98 0 0 0 0 0 0 18 0 0 0 0 0 0 0 2 99 0 0 0 0 0 0 21 0 0 0 60 0 0 0 0 0 0 0 17 73 68 76 58 113 113 113 47 116 97 98 49 58 49 46 48 0 0 0 0 0 0 0 5 116 97 98 49 0 0 0 0 0 0 0 20 0 0 0 12 0 0 0 0 0 0 0 3 0 0 0 3 0 0 0 2 100 0 0 0 0 0 0 21 0 0 0 60 0 0 0 0 0 0 0 17 73 68 76 58 113 113 113 47 116 97 98 50 58 49 46 48 0 0 0 0 0 0 0 5 116 97 98 50 0 0 0 0 0 0 0 19 0 0 0 12 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 123 0 0 0 12 65 32 107 117 32 107 117 32 63 63 63 0 0 0 0 1 0 0 0 2 0 0 0 3 0 0 0 2 0 0 0 4 0 0 0 5 }] Combat::CDR::Decoder d1 $x8 [d1 get_buffer] configure -byteorder 0; # BigEndian d1 Demarshal any #% {struct IDL:qqq/str2:1.0 {a long b string c {array long 3} d {sequence long}}} {a 123 b {A ku ku ???} c {1 2 3} d {4 5}} itcl::delete object d1 #% # ... # CDR z JavaIDL # + kons2 lub kons3 (!); pamietac o ". e" # + os= orb.create_output_stream(); # po wpisaniu danych do bufora mozna wywolac os.create_input_stream() # oraz czytac dane z bufora... # http://docs.oracle.com/javase/6/docs/api/org/omg/CORBA/portable/OutputStream.html # + okazuje sie ze niektore metody z os i os NIE sa zaimplementowane!! # jest inaczej w javaidl i jaco... # najwiekszy problem jest z brakiem is.available() w javaidl # nie wiadomo ile bajtow czytac z bufora... # pod jaco is.available() dziala ok # + jest problem z ustaleniem endian i encodingiem(?) # to sa rzeczy negocjowane przez iiop... # + jak utworzyc sekwencje longow ??? # prawd. trzeba uzyc write_Any i zignorowac TC... # do przesylania zlozonych typow bez "any" # trzeba prawd. uzyc pienka wygenerowanego przez idlj... # proc ii o {join [java::info meth $o] \n} proc narrow ob {java::cast [[$ob getClass] getName] $ob} proc e args {catch $args err; set err} lappend auto_path ~/tcl/mini-blend; package re java #% 1.3.3 # broker JavaIDL set orb [java::call org.omg.CORBA.ORB \ {init {java.lang.String[]} java.util.Properties} \ [java::null] [java::null] ] #ii $orb # broker Jaco (zamiast javaidl) ?! set jp [java::new java.util.Properties] $jp put java.endorsed.dirs /root/zajecia/tas/corba/jacorb/jacorb-3.5/lib $jp put jacorb.home /root/zajecia/tas/corba/jacorb/jacorb-3.5 $jp put org.omg.CORBA.ORBClass org.jacorb.orb.ORB $jp put org.omg.CORBA.ORBSingletonClass org.jacorb.orb.ORBSingleton set orb [java::call org.omg.CORBA.ORB \ {init {java.lang.String[]} java.util.Properties} [java::null] $jp ] #ii $orb set os [$orb create_output_stream] #ii $os #[$os getClass] getName #% com.sun.corba.se.impl.encoding.EncapsOutputStream #% org.jacorb.orb.CDROutputStream #ii org.jacorb.orb.CDROutputStream #ii com.sun.corba.se.impl.encoding.EncapsOutputStream set a1 [java::new {int[]} {} {1 2 3}] set a2 [java::new {int[]} {} {44 5 6 7}] $os write_long_array $a1 0 3 $os write_long_array $a2 0 4 # + dlaczego to nie dziala ?!?!?!!? # java.lang.IndexOutOfBoundsException # chyba inputstream trzeba utworzyc na koncu!! set is [$os create_input_stream] #ii $is #[$is getClass] getName #% com.sun.corba.se.impl.encoding.EncapsInputStream #% org.jacorb.orb.CDRInputStream #ii org.jacorb.orb.CDRInputStream #ii com.sun.corba.se.impl.encoding.EncapsInputStream $is available #% 28 e $is read #% -1 #% 7 #% 0 #% 0 #% 0 #% 6 #% 0 #% 0 #% 0 #% 5 #% 0 #% 0 #% 0 #% 44 #% 0 #% 0 #% 0 #% 3 #% 0 #% 0 #% 0 #% 2 #% 0 #% 0 #% 0 #% 1 #% 0 #% 0 #% 0 #% org.omg.CORBA.NO_IMPLEMENT: vmcid: 0x0 minor code: 0 completed: No # + pod JavaIDL read() nie dziala... pod JacORB dziala!! # + ... moze jednak read() == read_octet() ?!?!!?!? $is reset # + reset nic nie daje!? set a3 [java::new {int[]} 10] $a3 getrange #% 0 0 0 0 0 0 0 0 0 0 $is read_long_array $a3 0 3 $a3 getrange set a4 [java::new {int[]} 10] $a4 getrange #% 0 0 0 0 0 0 0 0 0 0 $is read_long_array $a4 0 4 #% $a4 getrange #% 44 5 6 7 0 0 0 0 0 0 # + bledne odczyty powoduja javowy wyjatek ?!?!?! e $is read_octet #% org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 202 completed: No #% 7 #% 0 #% 0 #% 0 #% 6 #% 0 #% 0 #% 0 #% 5 #% 0 #% 0 #% 0 #% 44 #% 0 #% 0 #% 0 #% 3 #% 0 #% 0 #% 0 #% 2 #% 0 #% 0 #% 0 #% 1 #% 0 #% 0 #% 0 # + przy read_octet nie ma danych o dlugosci tablic... # obsluga typu "wstring" # + na razie jest problem; # nie wiem jakich conv/enc uzyc pod combatem... binary scan $x5 c* xx5; set xx5 #% 0 0 0 19 65 32 107 117 32 107 117 32 33 33 33 32 -77 -77 -77 32 -74 -74 -74 # + to jest "wstring" ! pochodzi z przykladu combat. z x5 !! set os [$orb create_output_stream] set b1 [java::new {byte[]} {} $xx5] $os write_octet_array $b1 0 [$b1 length] set is [$os create_input_stream] $is read_wstring # + BLEDNE kodowanie ?!?!?!?!!!?!?!? # jakie kodowanie (converter) nalezy ustawic po stronie nadawcy?? # nie wiem skad takie info brac w JavaIDL...? set is2 [narrow $is] set os2 [narrow $os] [$os2 getGIOPVersion] toString #% 1.2 $os2 isLittleEndian #% 0 # ... # CDR z JavaIDL + plik qqq.idl i pieniek # + zakl., ze zaladowalismy pakiet java oraz # utworzylismy orb z JacORB # + w qqq.idl powinny byc typedefy, struct, ...? # b. elegancki kod produkuje idlj !!! # interesuja nas glownie klasy *Helper # + co jest w klasie *Helper? # met. read, write, (obsluga strumieni) # met. type, insert, extract, (obsluga TC/any) # + problemy: # czy to zadziala z orb z JavaIDL?!?!!? # moze byc problem z met. read... # niestety, takze w Jaco nie zaimpl. met. write... ?!?! # czy to oznacza klape ?!?!!? # niekoniecznie, mozna uzywac read/write_octet_array... # tylko skad znac licz. bajtow skoro available nie dziala pod javaidl? # widac, ze nie jest calkiem pewne czy da sie uzywac CDR # pod brokerami javowymi... 20.08.2016 # exec cat qqq.idl #% module qqq { typedef long tab1[3]; typedef sequence tab2; struct str1 { long a; string b; }; struct str2 { long a; string b; tab1 c; tab2 d; }; }; # + kompilacja: idlj qqq.idl; javac qqq/*.java java::call qqq.tab1Helper id #% IDL:qqq/tab1:1.0 java::call qqq.tab2Helper id #% IDL:qqq/tab2:1.0 java::call qqq.str1Helper id #% IDL:qqq/str1:1.0 java::call qqq.str2Helper id #% IDL:qqq/str2:1.0 [java::call qqq.tab1Helper type] toString #% {TypeCode: Kind=21 (tk_alias), ID=IDL:qqq/tab1:1.0, recursive=false} [java::call qqq.tab2Helper type] toString #% {TypeCode: Kind=21 (tk_alias), ID=IDL:qqq/tab2:1.0, recursive=false} [java::call qqq.str1Helper type] toString #% {TypeCode: Kind=15 (tk_struct), ID=IDL:qqq/str1:1.0, recursive=false} [java::call qqq.str2Helper type] toString #% {TypeCode: Kind=15 (tk_struct), ID=IDL:qqq/str2:1.0, recursive=false} set os [$orb create_output_stream] set a1 [java::new {int[]} {} {1 2 3}] java::call qqq.tab1Helper write $os $a1 set is [$os create_input_stream] # jaco: $is available #% 12 $is read #% -1 #% -1 #% 3 #% 0 #% 0 #% 0 #% 2 #% 0 #% 0 #% 0 #% 1 #% 0 #% 0 #% 0 # javaidl: $is available #% 0 e $is read_octet #% org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 202 completed: No #% org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 202 completed: No #% 3 #% 0 #% 0 #% 0 #% 2 #% 0 #% 0 #% 0 #% 1 #% 0 #% 0 #% 0 set os [$orb create_output_stream] set a1 [java::new {int[]} {} {4 5 6 7}] java::call qqq.tab2Helper write $os $a1 set is [$os create_input_stream] $is available #% 20 $is read #% -1 #% -1 #% 7 #% 0 #% 0 #% 0 #% 6 #% 0 #% 0 #% 0 #% 5 #% 0 #% 0 #% 0 #% 4 #% 0 #% 0 #% 0 #% 4 #% 0 #% 0 #% 0 set os [$orb create_output_stream] set str1 [java::new qqq.str1] java::info fields $str1 #% a b java::field $str1 a 111; # long java::field $str1 b "A ku ku !"; # string java::call qqq.str1Helper write $os $str1 set is [$os create_input_stream] $is available #% 18 set b1 [java::new {byte[]} 18] $is read $b1 $b1 getrange #% 0 0 0 111 0 0 0 10 65 32 107 117 32 107 117 32 33 0 # + zakodowana struktura str1... # co jesli read() nie dziala, jak pod javaidl???? set is [$os create_input_stream] $is available #% 18 set b1 [java::new {byte[]} 18] $is read_octet_array $b1 0 18 $b1 getrange #% 0 0 0 111 0 0 0 10 65 32 107 117 32 107 117 32 33 0 # + jak widac read_octet_array() dziala tak jak read() # czyli z tym akurat nie ma problemu pod javaidl... # + jest problem z nie dzialajacym available() pod javaidl!!! # nie wiadomo ile bajtow czytac... # !?!!?!?!?!?!?!?!?! # teraz probujemy odkodowac... set os [$orb create_output_stream] e $os write $b1 #% org.omg.CORBA.NO_IMPLEMENT: vmcid: 0x0 minor code: 0 completed: No # + no i klapa... moze uzyc write_octet_array??? $os write_octet_array $b1 0 18 set is [$os create_input_stream] $is available #% 18 set s1 [java::call qqq.str1Helper read $is] java::field $s1 a #% 111 java::field $s1 b #% A ku ku ! # ... # spis metod $os i $is # ii $os #% close create_input_stream equals java.lang.Object flush getClass hashCode notify notifyAll orb toString wait wait long wait long int write {byte[]} write {byte[]} int int write int write_Context org.omg.CORBA.Context org.omg.CORBA.ContextList write_Object org.omg.CORBA.Object write_Principal org.omg.CORBA.Principal write_TypeCode org.omg.CORBA.TypeCode write_any org.omg.CORBA.Any write_boolean boolean write_boolean_array {boolean[]} int int write_char char write_char_array {char[]} int int write_double double write_double_array {double[]} int int write_fixed java.math.BigDecimal write_float float write_float_array {float[]} int int write_long int write_long_array {int[]} int int write_longlong long write_longlong_array {long[]} int int write_octet byte write_octet_array {byte[]} int int write_short short write_short_array {short[]} int int write_string java.lang.String write_ulong int write_ulong_array {int[]} int int write_ulonglong long write_ulonglong_array {long[]} int int write_ushort short write_ushort_array {short[]} int int write_wchar char write_wchar_array {char[]} int int write_wstring java.lang.String ii $is #% available close equals java.lang.Object getClass hashCode mark int markSupported notify notifyAll orb read read {byte[]} read {byte[]} int int read_Context read_Object read_Object java.lang.Class read_Principal read_TypeCode read_any read_boolean read_boolean_array {boolean[]} int int read_char read_char_array {char[]} int int read_double read_double_array {double[]} int int read_fixed read_float read_float_array {float[]} int int read_long read_long_array {int[]} int int read_longlong read_longlong_array {long[]} int int read_octet read_octet_array {byte[]} int int read_short read_short_array {short[]} int int read_string read_ulong read_ulong_array {int[]} int int read_ulonglong read_ulonglong_array {long[]} int int read_ushort read_ushort_array {short[]} int int read_wchar read_wchar_array {char[]} int int read_wstring reset skip long toString wait wait long wait long int # ... exit