forked from wireshark/wireshark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethereal_gen.py
2836 lines (1973 loc) · 75.2 KB
/
ethereal_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- python -*-
#
# $Id$
#
# ethereal_gen.py (part of idl2eth)
#
# Author : Frank Singleton (frank.singleton@ericsson.com)
#
# Copyright (C) 2001 Frank Singleton, Ericsson Inc.
#
# This file is a backend to "omniidl", used to generate "Ethereal"
# dissectors from CORBA IDL descriptions. The output language generated
# is "C". It will generate code to use the GIOP/IIOP get_CDR_XXX API.
#
# Please see packet-giop.h in Ethereal distro for API description.
# Ethereal is available at http://www.ethereal.com/
#
# Omniidl is part of the OmniOrb distribution, and is available at
# http://www.uk.research.att.com/omniORB/omniORB.html
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
# Description:
#
# Omniidl Back-end which parses an IDL list of "Operation" nodes
# passed from ethereal_be2.py and generates "C" code for compiling
# as a plugin for the Ethereal IP Protocol Analyser.
#
#
# Strategy (sneaky but ...)
#
# problem: I dont know what variables to declare until AFTER the helper functions
# have been built, so ...
#
# There are 2 passes through genHelpers, the first one is there just to
# make sure the fn_hash data struct is populated properly.
# The second pass is the real thing, generating code and declaring
# variables (from the 1st pass) properly.
#
"""Ethereal IDL compiler back-end."""
from omniidl import idlast, idltype, idlutil, output
import sys, string
import tempfile
#
# Output class, generates "C" src code for the sub-dissector
#
# in:
#
#
# self - me
# st - output stream
# node - a reference to an Operations object.
# name - scoped name (Module::Module::Interface:: .. ::Operation
#
#
# TODO -- FS
#
# 1. generate hf[] data for searchable fields (but what is searchable?)
# 2. add item instead of add_text()
# 3. sequence handling [done]
# 4. User Exceptions [done]
# 5. Fix arrays, and structs containing arrays [done]
# 6. Handle pragmas.
# 7. Exception can be common to many operations, so handle them outside the
# operation helper functions [done]
# 8. Automatic variable declaration [done, improve, still get some collisions.add variable delegator function ]
# For example, mutlidimensional arrays.
# 9. wchar and wstring handling [giop API needs improving]
# 10. Support Fixed [done]
# 11. Support attributes (get/set) [started, needs language mapping option, perhaps ethereal GUI option
# to set the attribute function prefix or suffix ? ] For now the prefix is "_get" and "_set"
# eg: attribute string apple => _get_apple and _set_apple
#
# 12. Implement IDL "union" code [done]
# 13. Implement support for plugins [done]
# 14. Dont generate code for empty operations (cf: exceptions without members)
# 15. Generate code to display Enums numerically and symbolically [done]
# 16. Place structs/unions in subtrees
# 17. Recursive struct and union handling [done ]
# 18. Improve variable naming for display (eg: structs, unions etc)
#
# Also test, Test, TEST
#
#
# Strategy:
# For every operation and attribute do
# For return val and all parameters do
# find basic IDL type for each parameter
# output get_CDR_xxx
# output exception handling code
# output attribute handling code
#
#
class ethereal_gen_C:
#
# Turn DEBUG stuff on/off
#
DEBUG = 0
#
# Some string constants for our templates
#
c_u_octet4 = "guint32 u_octet4;"
c_s_octet4 = "gint32 s_octet4;"
c_u_octet2 = "guint16 u_octet2;"
c_s_octet2 = "gint16 s_octet2;"
c_u_octet1 = "guint8 u_octet1;"
c_s_octet1 = "gint8 s_octet1;"
c_float = "gfloat my_float;"
c_double = "gdouble my_double;"
c_seq = "gchar *seq = NULL;" # pointer to buffer of gchars
c_i = "guint32 i_"; # loop index
c_i_lim = "guint32 u_octet4_loop_"; # loop limit
c_u_disc = "guint32 disc_u_"; # unsigned int union discriminant variable name (enum)
c_s_disc = "gint32 disc_s_"; # signed int union discriminant variable name (other cases, except Enum)
#
# Constructor
#
def __init__(self, st, protocol_name, dissector_name ,description):
self.st = output.Stream(tempfile.TemporaryFile(),4) # for first pass only
self.st_save = st # where 2nd pass should go
self.protoname = protocol_name # Protocol Name (eg: ECHO)
self.dissname = dissector_name # Dissector name (eg: echo)
self.description = description # Detailed Protocol description (eg: Echo IDL Example)
self.exlist = [] # list of exceptions used in operations.
#self.curr_sname # scoped name of current opnode or exnode I am visiting, used for generating "C" var declares
self.fn_hash = {} # top level hash to contain key = function/exception and val = list of variable declarations
# ie a hash of lists
self.fn_hash_built = 0 # flag to indicate the 1st pass is complete, and the fn_hash is correctly
# populated with operations/vars and exceptions/vars
#
# genCode()
#
# Main entry point, controls sequence of
# generated code.
#
#
def genCode(self,oplist, atlist, enlist, stlist, unlist): # operation,attribute,enums,struct and union lists
self.genHelpers(oplist,stlist,unlist) # sneaky .. call it now, to populate the fn_hash
# so when I come to that operation later, I have the variables to
# declare already.
self.genExceptionHelpers(oplist) # sneaky .. call it now, to populate the fn_hash
# so when I come to that exception later, I have the variables to
# declare already.
self.genAttributeHelpers(atlist) # sneaky .. call it now, to populate the fn_hash
# so when I come to that exception later, I have the variables to
# declare already.
self.fn_hash_built = 1 # DONE, so now I know , see genOperation()
self.st = self.st_save
self.genHeader() # initial dissector comments
self.genEthCopyright() # Ethereal Copyright comments.
self.genGPL() # GPL license
self.genIncludes()
self.genDeclares(oplist,atlist,enlist,stlist,unlist)
self.genProtocol()
self.genRegisteredFields()
self.genOpList(oplist) # string constant declares for operation names
self.genExList(oplist) # string constant declares for user exceptions
self.genAtList(atlist) # string constant declares for Attributes
self.genEnList(enlist) # string constant declares for Enums
self.genExceptionHelpers(oplist) # helper function to decode user exceptions that have members
self.genExceptionDelegator(oplist) # finds the helper function to decode a user exception
self.genAttributeHelpers(atlist) # helper function to decode "attributes"
self.genHelpers(oplist,stlist,unlist) # operation, struct and union decode helper functions
self.genMainEntryStart(oplist)
self.genOpDelegator(oplist)
self.genAtDelegator(atlist)
self.genMainEntryEnd()
self.gen_proto_register()
self.gen_proto_reg_handoff(oplist)
self.gen_plugin_register()
#self.dumpvars() # debug
#
# genHeader
#
# Generate Standard Ethereal Header Comments
#
#
def genHeader(self):
self.st.out(self.template_Header,dissector_name=self.dissname)
if self.DEBUG:
print "XXX genHeader"
#
# genEthCopyright
#
# Ethereal Copyright Info
#
#
def genEthCopyright(self):
if self.DEBUG:
print "XXX genEthCopyright"
self.st.out(self.template_ethereal_copyright)
#
# genGPL
#
# GPL licencse
#
#
def genGPL(self):
if self.DEBUG:
print "XXX genGPL"
self.st.out(self.template_GPL)
#
# genIncludes
#
# GPL licencse
#
#
def genIncludes(self):
if self.DEBUG:
print "XXX genIncludes"
self.st.out(self.template_Includes)
#
# denDeclares
#
# generate function prototypes if required
#
# Currently this is used for struct and union helper function declarations.
#
def genDeclares(self,oplist,atlist,enlist,stlist,unlist):
if self.DEBUG:
print "XXX genDeclares"
# prototype for start_dissecting()
self.st.out(self.template_prototype_start_dissecting)
# struct prototypes
self.st.out(self.template_prototype_struct_start)
for st in stlist:
#print st.repoId()
sname = self.namespace(st, "_")
self.st.out(self.template_prototype_struct_body, stname=st.repoId(),name=sname)
self.st.out(self.template_prototype_struct_end)
# union prototypes
self.st.out(self.template_prototype_union_start)
for un in unlist:
sname = self.namespace(un, "_")
self.st.out(self.template_prototype_union_body, unname=un.repoId(),name=sname)
self.st.out(self.template_prototype_union_end)
#
# genProtocol
#
#
def genProtocol(self):
self.st.out(self.template_protocol, dissector_name=self.dissname)
self.st.out(self.template_init_boundary)
#
# genProtoAndRegisteredFields
#
#
def genRegisteredFields(self):
self.st.out(self.template_registered_fields )
#
# genMainEntryStart
#
def genMainEntryStart(self,oplist):
self.st.out(self.template_main_dissector_start, dissname=self.dissname, disprot=self.protoname)
self.st.inc_indent()
self.st.out(self.template_main_dissector_switch_msgtype_start)
self.st.out(self.template_main_dissector_switch_msgtype_start_request_reply)
self.st.inc_indent()
#
# genMainEntryEnd
#
def genMainEntryEnd(self):
self.st.out(self.template_main_dissector_switch_msgtype_end_request_reply)
self.st.dec_indent()
self.st.out(self.template_main_dissector_switch_msgtype_all_other_msgtype)
self.st.dec_indent()
self.st.out(self.template_main_dissector_end)
#
# genOpList
#
# in: oplist
#
# out: C code for IDL operations
#
# eg:
#
# static const char Penguin_Echo_echoShort_op[] = "echoShort" ;
#
def genOpList(self,oplist):
self.st.out(self.template_comment_operations_start)
for n in oplist:
sname = self.namespace(n, "_")
opname = n.identifier()
self.st.out(self.template_operations_declare, sname=sname, opname=opname)
self.st.out(self.template_comment_operations_end)
#
# genExList
#
# in: oplist
#
# out: C code for IDL User Exceptions that contain members
#
# eg:
#
# static const char user_exception_tux_bad_value[] = "IDL:tux/bad_value:1.0" ;
#
def genExList(self,oplist):
self.st.out(self.template_comment_user_exceptions_string_declare_start)
exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
for ex in exlist:
if self.DEBUG:
print "XXX Exception " , ex.repoId()
print "XXX Exception Identifier" , ex.identifier()
print "XXX Exception Scoped Name" , ex.scopedName()
if (ex.members()): # only if has members
sname = self.namespace(ex, "_")
exname = ex.repoId()
self.st.out(self.template_user_exceptions_declare, sname=sname, exname=ex.repoId())
self.st.out(self.template_comment_user_exceptions_string_declare_end)
#
# genAtList
#
# in: atlist
#
# out: C code for IDL attribute decalarations.
#
# NOTE: Mapping of attributes to operation(function) names is tricky.
#
# The actual accessor function names are language-mapping specific. The attribute name
# is subject to OMG IDL's name scoping rules; the accessor function names are
# guaranteed not to collide with any legal operation names specifiable in OMG IDL.
#
# eg:
#
# static const char get_Penguin_Echo_get_width_at[] = "get_width" ;
# static const char set_Penguin_Echo_set_width_at[] = "set_width" ;
#
# or:
#
# static const char get_Penguin_Echo_get_width_at[] = "_get_width" ;
# static const char set_Penguin_Echo_set_width_at[] = "_set_width" ;
#
# TODO: Implement some language dependant templates to handle naming conventions
# language <=> attribute. for C, C++. Java etc
#
# OR, just add a runtime GUI option to select language binding for attributes -- FS
#
#
#
# ie: def genAtlist(self,atlist,language)
#
def genAtList(self,atlist):
self.st.out(self.template_comment_attributes_start)
for n in atlist:
for i in n.declarators(): #
sname = self.namespace(i, "_")
atname = i.identifier()
self.st.out(self.template_attributes_declare_Java_get, sname=sname, atname=atname)
if not n.readonly():
self.st.out(self.template_attributes_declare_Java_set, sname=sname, atname=atname)
self.st.out(self.template_comment_attributes_end)
#
# genEnList
#
# in: enlist
#
# out: C code for IDL Enum decalarations using "static const value_string" template
#
def genEnList(self,enlist):
self.st.out(self.template_comment_enums_start)
for enum in enlist:
sname = self.namespace(enum, "_")
self.st.out(self.template_comment_enum_comment, ename=enum.repoId())
self.st.out(self.template_value_string_start, valstringname=sname)
for enumerator in enum.enumerators():
self.st.out(self.template_value_string_entry, intval=str(self.valFromEnum(enum,enumerator)), description=enumerator.identifier())
#atname = n.identifier()
self.st.out(self.template_value_string_end, valstringname=sname)
self.st.out(self.template_comment_enums_end)
#
# genExceptionDelegator
#
# in: oplist
#
# out: C code for User exception delegator
#
# eg:
#
#
def genExceptionDelegator(self,oplist):
self.st.out(self.template_main_exception_delegator_start)
self.st.inc_indent()
exlist = self.get_exceptionList(oplist) # grab list of ALL UNIQUE exception nodes
for ex in exlist:
if self.DEBUG:
print "XXX Exception " , ex.repoId()
print "XXX Exception Identifier" , ex.identifier()
print "XXX Exception Scoped Name" , ex.scopedName()
if (ex.members()): # only if has members
sname = self.namespace(ex, "_")
exname = ex.repoId()
self.st.out(self.template_ex_delegate_code, sname=sname, exname=ex.repoId())
self.st.dec_indent()
self.st.out(self.template_main_exception_delegator_end)
#
# genAttribueHelpers()
#
# Generate private helper functions to decode Attributes.
#
# in: atlist
#
# For readonly attribute - generate get_xxx()
# If NOT readonly attribute - also generate set_xxx()
#
def genAttributeHelpers(self,atlist):
if self.DEBUG:
print "XXX genAttributeHelpers: atlist = ", atlist
self.st.out(self.template_attribute_helpers_start)
for attrib in atlist:
for decl in attrib.declarators():
self.genAtHelper(attrib,decl,"get") # get accessor
if not attrib.readonly():
self.genAtHelper(attrib,decl,"set") # set accessor
self.st.out(self.template_attribute_helpers_end)
#
# genAtHelper()
#
# Generate private helper functions to decode an attribute
#
# in: at - attribute node
# in: decl - declarator belonging to this attribute
# in: order - to generate a "get" or "set" helper
def genAtHelper(self,attrib,decl,order):
if self.DEBUG:
print "XXX genAtHelper"
sname = order + "_" + self.namespace(decl, "_") # must use set or get prefix to avoid collision
self.curr_sname = sname # update current opnode/exnode scoped name
if not self.fn_hash_built:
self.fn_hash[sname] = [] # init empty list as val for this sname key
# but only if the fn_hash is not already built
self.st.out(self.template_attribute_helper_function_start, sname=sname, atname=decl.repoId())
self.st.inc_indent()
self.st.out(self.template_helper_function_vars_start)
self.dumpCvars(sname)
self.st.out(self.template_helper_function_vars_end )
self.st.out(self.template_exception_helper_function_get_endianess)
#
# TODO - attributes are simple types, so remove array handling
#
if decl.sizes(): # an array
indices = self.get_indices_from_sizes(decl.sizes())
string_indices = '%i ' % indices # convert int to string
self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
self.addvar(self.c_i + decl.identifier() + ";")
self.st.inc_indent()
self.getCDR3(attrib.attrType(), decl.identifier() )
self.st.dec_indent()
self.st.out(self.template_get_CDR_array_end)
else:
self.getCDR3(attrib.attrType(), decl.identifier() )
self.st.dec_indent()
self.st.out(self.template_attribute_helper_function_end)
#
# genExceptionHelpers()
#
# Generate private helper functions to decode Exceptions used
# within operations
#
# in: oplist
#
def genExceptionHelpers(self,oplist):
exlist = self.get_exceptionList(oplist) # grab list of exception nodes
if self.DEBUG:
print "XXX genExceptionHelpers: exlist = ", exlist
self.st.out(self.template_exception_helpers_start)
for ex in exlist:
if (ex.members()): # only if has members
#print "XXX Exception = " + ex.identifier()
self.genExHelper(ex)
self.st.out(self.template_exception_helpers_end)
#
# genExhelper()
#
# Generate private helper functions to decode User Exceptions
#
# in: exnode ( an exception node)
#
def genExHelper(self,ex):
if self.DEBUG:
print "XXX genExHelper"
sname = self.namespace(ex, "_")
self.curr_sname = sname # update current opnode/exnode scoped name
if not self.fn_hash_built:
self.fn_hash[sname] = [] # init empty list as val for this sname key
# but only if the fn_hash is not already built
self.st.out(self.template_exception_helper_function_start, sname=sname, exname=ex.repoId())
self.st.inc_indent()
self.st.out(self.template_helper_function_vars_start)
self.dumpCvars(sname)
self.st.out(self.template_helper_function_vars_end )
self.st.out(self.template_exception_helper_function_get_endianess)
for m in ex.members():
#print "XXX genExhelper, member = ", m, "member type = ", m.memberType()
for decl in m.declarators():
#print "XXX genExhelper, d = ", decl
if decl.sizes(): # an array
indices = self.get_indices_from_sizes(decl.sizes())
string_indices = '%i ' % indices # convert int to string
self.st.out(self.template_get_CDR_array_comment, aname=decl.identifier(), asize=string_indices)
self.st.out(self.template_get_CDR_array_start, aname=decl.identifier(), aval=string_indices)
self.addvar(self.c_i + decl.identifier() + ";")
self.st.inc_indent()
self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
self.st.dec_indent()
self.st.out(self.template_get_CDR_array_end)
else:
self.getCDR3(m.memberType(), ex.identifier() + "_" + decl.identifier() )
self.st.dec_indent()
self.st.out(self.template_exception_helper_function_end)
#
# genHelpers()
#
# Generate private helper functions for each IDL operation.
# Generate private helper functions for each IDL struct.
# Generate private helper functions for each IDL union.
#
#
# in: oplist, stlist, unlist
#
def genHelpers(self,oplist,stlist,unlist):
for op in oplist:
self.genOperation(op)
for st in stlist:
self.genStructHelper(st)
for un in unlist:
self.genUnionHelper(un)
#
# genOperation()
#
# Generate private helper functions for a specificIDL operation.
#
# in: opnode
#
def genOperation(self,opnode):
if self.DEBUG:
print "XXX genOperation called"
sname = self.namespace(opnode, "_")
if not self.fn_hash_built:
self.fn_hash[sname] = [] # init empty list as val for this sname key
# but only if the fn_hash is not already built
self.curr_sname = sname # update current opnode's scoped name
opname = opnode.identifier()
self.st.out(self.template_helper_function_comment, repoid=opnode.repoId() )
self.st.out(self.template_helper_function_start, sname=sname)
self.st.inc_indent()
self.st.out(self.template_helper_function_vars_start)
self.dumpCvars(sname)
self.st.out(self.template_helper_function_vars_end )
self.st.out(self.template_helper_switch_msgtype_start)
self.st.out(self.template_helper_switch_msgtype_request_start)
self.st.inc_indent()
self.genOperationRequest(opnode)
self.st.out(self.template_helper_switch_msgtype_request_end)
self.st.dec_indent()
self.st.out(self.template_helper_switch_msgtype_reply_start)
self.st.inc_indent()
self.st.out(self.template_helper_switch_rep_status_start)
self.st.out(self.template_helper_switch_msgtype_reply_no_exception_start)
self.st.inc_indent()
self.genOperationReply(opnode)
self.st.out(self.template_helper_switch_msgtype_reply_no_exception_end)
self.st.dec_indent()
self.st.out(self.template_helper_switch_msgtype_reply_user_exception_start)
self.st.inc_indent()
self.genOpExceptions(opnode)
self.st.out(self.template_helper_switch_msgtype_reply_user_exception_end)
self.st.dec_indent()
self.st.out(self.template_helper_switch_msgtype_reply_default_start)
self.st.out(self.template_helper_switch_msgtype_reply_default_end)
self.st.out(self.template_helper_switch_rep_status_end)
self.st.dec_indent()
self.st.out(self.template_helper_switch_msgtype_default_start)
self.st.out(self.template_helper_switch_msgtype_default_end)
self.st.out(self.template_helper_switch_msgtype_end)
self.st.dec_indent()
self.st.out(self.template_helper_function_end, sname=sname)
#
# Decode function parameters for a GIOP request message
#
#
def genOperationRequest(self,opnode):
for p in opnode.parameters():
if p.is_in():
if self.DEBUG:
print "XXX parameter = " ,p
print "XXX parameter type = " ,p.paramType()
print "XXX parameter type kind = " ,p.paramType().kind()
self.getCDR3(p.paramType(),p.identifier())
#
# Decode function parameters for a GIOP reply message
#
def genOperationReply(self,opnode):
rt = opnode.returnType() # get return type
if self.DEBUG:
print "XXX opnode = " , opnode
print "XXX return type = " , rt
print "XXX return type.unalias = " , rt.unalias()
print "XXX return type.kind() = " , rt.kind();
if (rt.kind() == idltype.tk_alias): # a typdef return val possibly ?
#self.getCDR3(rt.decl().alias().aliasType(),"dummy") # return value maybe a typedef
#self.get_CDR_alias(rt, "Operation_Return_Value" )
self.get_CDR_alias(rt, rt.name() )
else:
self.getCDR3(rt, "Operation_Return_Value") # return value is NOT an alias
for p in opnode.parameters():
if p.is_out(): # out or inout
self.getCDR3(p.paramType(),p.identifier())
#self.st.dec_indent()
def genOpExceptions(self,opnode):
for ex in opnode.raises():
if ex.members():
#print ex.members()
for m in ex.members():
t=0
#print m.memberType(), m.memberType().kind()
#
# Delegator for Operations
#
def genOpDelegator(self,oplist):
for op in oplist:
opname = op.identifier()
sname = self.namespace(op, "_")
self.st.out(self.template_op_delegate_code, sname=sname)
#
# Delegator for Attributes
#
def genAtDelegator(self,atlist):
for a in atlist:
for i in a.declarators():
atname = i.identifier()
sname = self.namespace(i, "_")
self.st.out(self.template_at_delegate_code_get, sname=sname)
if not a.readonly():
self.st.out(self.template_at_delegate_code_set, sname=sname)
#
# Add a variable declaration to the hash of list
#
def addvar(self, var):
if not ( var in self.fn_hash[self.curr_sname] ):
self.fn_hash[self.curr_sname].append(var)
#
# Print the variable declaration from the hash of list
#
def dumpvars(self):
for fn in self.fn_hash.keys():
print "FN = " + fn
for v in self.fn_hash[fn]:
print "-> " + v
#
# Print the "C" variable declaration from the hash of list
# for a given scoped operation name (eg: tux_penguin_eat)
#
def dumpCvars(self, sname):
for v in self.fn_hash[sname]:
self.st.out(v)
#
# Given an enum node, and a enumerator node, return
# the enumerator's numerical value.
#
# eg: enum Color {red,green,blue} should return
# val = 1 for green
#
def valFromEnum(self,enumNode, enumeratorNode):
if self.DEBUG:
print "XXX valFromEnum, enumNode = ", enumNode, " from ", enumNode.repoId()
print "XXX valFromEnum, enumeratorNode = ", enumeratorNode, " from ", enumeratorNode.repoId()
if isinstance(enumeratorNode,idlast.Enumerator):
value = enumNode.enumerators().index(enumeratorNode)
return value
## tk_null = 0
## tk_void = 1
## tk_short = 2
## tk_long = 3
## tk_ushort = 4
## tk_ulong = 5
## tk_float = 6
## tk_double = 7
## tk_boolean = 8
## tk_char = 9
## tk_octet = 10
## tk_any = 11
## tk_TypeCode = 12
## tk_Principal = 13
## tk_objref = 14
## tk_struct = 15
## tk_union = 16
## tk_enum = 17
## tk_string = 18
## tk_sequence = 19
## tk_array = 20
## tk_alias = 21
## tk_except = 22
## tk_longlong = 23
## tk_ulonglong = 24
## tk_longdouble = 25
## tk_wchar = 26
## tk_wstring = 27
## tk_fixed = 28
## tk_value = 29
## tk_value_box = 30
## tk_native = 31
## tk_abstract_interface = 32
#
# getCDR()
#
# This is the main "iterator" function. It takes a node, and tries to output
# a get_CDR_XXX accessor method(s). It can call itself multiple times
# if I find nested structures etc.
#
def getCDR3(self,type,name="fred"):
pt = type.unalias().kind() # param CDR type
pn = name # param name
if self.DEBUG:
print "XXX getCDR3: kind = " , pt
if pt == idltype.tk_ulong:
self.get_CDR_ulong(pn)
elif pt == idltype.tk_void:
self.get_CDR_void(pn)
elif pt == idltype.tk_short:
self.get_CDR_short(pn)
elif pt == idltype.tk_long:
self.get_CDR_long(pn)
elif pt == idltype.tk_ushort:
self.get_CDR_ushort(pn)
elif pt == idltype.tk_float:
self.get_CDR_float(pn)
elif pt == idltype.tk_double:
self.get_CDR_double(pn)
elif pt == idltype.tk_fixed:
self.get_CDR_fixed(type.unalias(),pn)
elif pt == idltype.tk_boolean:
self.get_CDR_boolean(pn)
elif pt == idltype.tk_char:
self.get_CDR_char(pn)
elif pt == idltype.tk_octet:
self.get_CDR_octet(pn)
elif pt == idltype.tk_any:
self.get_CDR_any(pn)
elif pt == idltype.tk_string:
self.get_CDR_string(pn)
elif pt == idltype.tk_wstring:
self.get_CDR_wstring(pn)
elif pt == idltype.tk_wchar:
self.get_CDR_wchar(pn)
elif pt == idltype.tk_enum:
#print type.decl()
self.get_CDR_enum(pn,type)
#self.get_CDR_enum(pn)
elif pt == idltype.tk_struct: