source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/tecsgen/tecslib/plugin/lib/GenHRP2Marshaler.rb@ 337

Last change on this file since 337 was 337, checked in by coas-nagasima, 6 years ago

ASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 24.4 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# TECS Generator
4# Generator for TOPPERS Embedded Component System
5#
6# Copyright (C) 2008-2014 by TOPPERS Project
7#--
8# 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
9# ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
10# 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
11# (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
12# 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
13# スコード中に含まれていること.
14# (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
15# 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
16# 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
17# の無保証規定を掲載すること.
18# (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
19# 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
20# と.
21# (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
22# 作権表示,この利用条件および下記の無保証規定を掲載すること.
23# (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
24# 報告すること.
25# (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
26# 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
27# また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
28# 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
29# 免責すること.
30#
31# 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
32# よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
33# に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
34# アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
35# の責任を負わない.
36#
37#++
38
39#プラグインオプション用変数
40#@task_priority:: Integer
41#@channelCelltype:: String
42#@channelCellName:: String
43#@PPAllocatorSize:: Integer
44module GenTransparentMarshaler
45
46 # プラグイン引数名と Proc
47 RPCPluginArgProc = {
48 "taskPriority" => Proc.new { |obj,rhs| obj.set_taskPriority rhs },
49 "channelCelltype" => Proc.new { |obj,rhs| obj.set_channelCelltype rhs },
50 "TDRCelltype" => Proc.new { |obj,rhs| obj.set_TDRCelltype rhs },
51 "channelCell" => Proc.new { |obj,rhs| obj.set_channelCellName rhs },
52 "PPAllocatorSize" => Proc.new { |obj,rhs| obj.set_PPAllocatorSize rhs },
53 }
54
55 #=== プラグイン引数 taskPriority のチェック
56 def set_taskPriority( rhs )
57 @task_priority = rhs
58 end
59
60 #=== プラグイン引数 channelCelltype のチェック
61 def set_channelCelltype( rhs )
62 @channelCelltype = rhs.to_sym
63 # path = [ "::", @channelCelltype ]
64 # obj = Namespace.find( path )
65 nsp = NamespacePath.analyze( @channelCelltype.to_s )
66 obj = Namespace.find( nsp )
67 if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
68 cdl_error( "RPCPlugin: channeclCelltype '#{rhs}' not celltype or not found" )
69 end
70 end
71
72 #=== プラグイン引数 TDRCelltype のチェック
73 def set_TDRCelltype( rhs )
74 @TDRCelltype = rhs.to_sym
75 # path = [ "::", @TDRCelltype ]
76 # obj = Namespace.find( path )
77 nsp = NamespacePath.analyze( @TDRCelltype.to_s )
78 obj = Namespace.find( nsp )
79 if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
80 cdl_error( "RPCPlugin: TDRCelltype '#{rhs}' not celltype or not found" )
81 end
82 end
83
84 #=== プラグイン引数 channelCellName のチェック
85 def set_channelCellName( rhs )
86 @channelCellName = rhs
87 if @channelCellName =~ /\A[a-zA-Z_]\w*/ then
88 # OK
89 else
90 cdl_error( "RPCPlugin: channeclCellName '#{rhs}' unsuitable for identifier" )
91 end
92 end
93
94 #=== プラグイン引数 PPAllocatorSize のチェック
95 def set_PPAllocatorSize( rhs )
96 @PPAllocatorSize = rhs
97 end
98
99 #=== marshaler のセルタイプ名を設定する
100 def initialize_transparent_marshaler cell_name
101 @task_priority = 8
102 @channelCelltype = "tDataqueueOWChannel"
103 @TDRCelltype = "tTDR"
104 @channelCellName = "#{cell_name}_Channel"
105 @PPAllocatorSize = nil
106
107 @marshaler_celltype_name = "tMarshaler_#{@signature.get_name}"
108 @unmarshaler_celltype_name = "tUnmarshaler_#{@signature.get_name}"
109 @marshaler_celltype_file_name = "#{$gen}/#{@marshaler_celltype_name}.cdl"
110 end
111
112 def gen_marshaler_celltype
113
114 if @PPAllocatorSize then
115 alloc_call_port = " call sPPAllocator cPPAllocator;\n"
116 else
117 alloc_call_port = ""
118 end
119
120 f = CFile.open( @marshaler_celltype_file_name, "w" )
121 # 同じ内容を二度書く可能性あり (AppFile は不可)
122
123 # modified by ishikawa
124 f.print <<EOT
125
126celltype #{@marshaler_celltype_name} {
127 entry #{@signature.get_name} eClientEntry;
128 call sEventflag cEventflag;
129 call sSemaphore cSemaphore;
130 call sMessageBuffer cMessageBuffer;
131 //[optional]
132 // call sSemaphore cLockChannel; // this port is eliminated by optimize
133};
134celltype #{@unmarshaler_celltype_name} {
135 call #{@signature.get_name} cServerCall;
136 call sEventflag cEventflag;
137 call sSemaphore cSemaphore;
138 call sMessageBuffer cMessageBuffer;
139 entry sTaskBody eUnmarshalAndCallFunction;
140#{alloc_call_port}
141 FACTORY{
142 write("$ct$_factory.h", "#include <t_syslog.h>");
143 };
144};
145EOT
146 f.close
147 end
148
149 #=== 受け口関数の本体コードを生成(頭部と末尾は別途出力)
150 #ct_name:: Symbol (through プラグインで生成された) セルタイプ名 .Symbol として送られてくる(らしい)
151 def gen_ep_func_body( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
152
153 # unmarshaler クラスか?
154 if ct_name == @unmarshaler_celltype_name.to_sym then
155 gen_ep_func_body_unmarshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
156 else
157 gen_ep_func_body_marshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
158 end
159 end
160
161 #=== marshal コードの生成
162 def gen_ep_func_body_marshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
163
164 b_void = false
165 b_ret_er = false
166
167 # 関数の戻り値の元の型を得る(typedef されている場合)
168 type = func_type.get_type.get_original_type
169
170 # 戻り値記憶用の変数を出力(void 型の関数では出力しない)
171 if ! type.kind_of?( VoidType ) then
172 if func_type.get_type.kind_of?( DefinedType ) && ( func_type.get_type.get_type_str == "ER" || func_type.get_type.get_type_str == "ER_INT" ) then
173 file.print( " #{func_type.get_type.get_type_str} retval_ = E_OK;\n" )
174 b_ret_er = true
175 else
176 file.print( " #{func_type.get_type.get_type_str} retval_;\n" )
177 end
178 else
179 b_void = true
180 end
181
182 file.print( " ER ercd_;\n" )
183 file.print( " FLGPTN flgptn;\n" )
184
185 # 呼び先の signature を取り出す
186 signature = @signature
187
188 # 関数 ID (整数値)
189 func_id = signature.get_id_from_func_name( func_name )
190 file.print( " int16_t func_id_ = #{func_id}; /* id of #{func_name}: #{func_id} */\n" )
191
192 file.print( " uint8_t msg[256];\n" )
193
194 # シングルトンでないか?
195 if ! b_singleton then
196
197 # singleton でなければ p_cellcb 取得コードを出力
198 file.print <<EOT
199 #{ct_name}_CB *p_cellcb;
200
201 if( VALID_IDX( idx ) ){
202 p_cellcb = GET_CELLCB(idx);
203EOT
204
205 # エラーを返すか?
206 if b_ret_er then
207 file.print <<EOT
208 }else{
209 return ERCD( E_RPC, E_ID );
210 }
211EOT
212 else
213 file.print <<EOT
214 }else{
215 /* エラー処理コードをここに記述 */
216 }
217EOT
218 end
219 end
220
221 # channel lock コード
222 file.print <<EOT
223 ///* Channel Lock */
224 //if( is_cLockChannel_joined() )
225 // cLockChannel_wait();
226
227EOT
228
229=begin
230 # SOP を送信
231 file.print " /* SOPの送出 */\n"
232 file.print " if( ( ercd_ = cTDR_sendSOP( true ) ) != E_OK )\n"
233 file.print " goto error_reset;\n"
234=end
235
236 # func_id を送信
237 file.print " /* 関数 id の送出 */\n"
238=begin
239 file.print " if( ( ercd_ = cTDR_putInt16( func_id_ ) ) != E_OK )\n"
240 file.print " goto error_reset;\n"
241=end
242 file.print " *((int16_t *)(&msg[0])) = func_id_;\n"
243
244 # p "celltype_name, sig_name, func_name, func_global_name"
245 # p "#{ct_name}, #{sig_name}, #{func_name}, #{func_global_name}"
246
247 b_get = false # marshal なら put
248 b_marshal = true # marshal
249
250 # in 方向の入出力を出力
251 @index = 2
252 file.print " /* 入力引数送出 */\n"
253 print_params( params, file, 1, b_marshal, b_get, true, func_type.is_oneway? )
254 print_params( params, file, 1, b_marshal, b_get, false, func_type.is_oneway? )
255=begin
256 if ! b_void && ! func_type.is_oneway? then
257 ret_ptr_type = PtrType.new( func_type.get_type )
258 print_param_nc( "retval_", ret_ptr_type, file, 1, :RETURN, "&", nil, b_get )
259 end
260=end
261
262 file.print " /* EOPの送出(パケットの掃きだし) */\n"
263 if ! func_type.is_oneway? then
264 b_continue = "true"
265 else
266 b_continue = "false"
267 end
268=begin
269 file.print " if( (ercd_=cTDR_sendEOP(#{b_continue})) != E_OK )\n"
270 file.print " goto error_reset;\n\n"
271=end
272 file.print " if( (ercd_=cMessageBuffer_send(msg, #{@index})) != E_OK )\n"
273 file.print " goto error_reset;\n\n"
274
275 file.print " cSemaphore_signal();\n\n"
276
277 if ! func_type.is_oneway? then
278 file.print <<EOT
279 if( (ercd_=cEventflag_wait( 0x01, TWF_ANDW, &flgptn )) != E_OK ){
280 ercd_ = ERCD(E_RPC,ercd_);
281 goto error_reset;
282 }
283 if( (ercd_=cEventflag_clear( 0x00 ) ) != E_OK ){
284 ercd_ = ERCD(E_RPC,ercd_);
285 goto error_reset;
286 }
287EOT
288 end # ! func_type.is_oneway?
289
290 file.print <<EOT
291 ///* Channel Lock */
292 //if( is_cLockChannel_joined() )
293 // cLockChannel_signal();
294EOT
295
296 if( b_void == false )then
297 # 呼び元に戻り値をリターン
298 file.print( " cMessageBuffer_receive(&retval_);\n" )
299 file.print( " return retval_;\n" )
300 else
301 file.print( " return;\n" )
302 end
303
304 file.print <<EOT
305
306error_reset:
307#if 0
308 if( ercd_ != ERCD( E_RPC, E_RESET ) )
309 (void)cTDR_reset();
310#endif
311EOT
312
313 # channel lock コード
314 file.print <<EOT
315 ///* Channel Lock */
316 //if( is_cLockChannel_joined() )
317 // cLockChannel_signal();
318
319EOT
320
321 if( b_ret_er != false )then
322 # 呼び元に戻り値をリターン
323 file.print( " return ercd_;\n" )
324 else
325 file.print( " return;\n" )
326 end
327
328 end
329
330 #=== unmarshal コードの生成
331 def gen_ep_func_body_unmarshal( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
332
333# b_ret_er = true
334 b_ret_er = false
335
336 # func_id を得るコードを生成
337 file.print <<EOT
338
339 int16_t func_id_;
340 ER ercd_;
341
342 #{ct_name}_CB *p_cellcb;
343
344 if( VALID_IDX( idx ) ){
345 p_cellcb = GET_CELLCB(idx);
346EOT
347
348 if b_ret_er then
349 file.print <<EOT
350 }else{
351 return ERCD( E_RPC, E_ID );
352 }
353EOT
354 else
355 file.print <<EOT
356 }else{
357 /* エラー処理コードをここに記述 */
358 }
359EOT
360 end
361
362 file.print <<EOT
363
364 cSemaphore_wait();
365
366#if 0
367 /* SOPのチェック */
368 if( (ercd_=cTDR_receiveSOP( false )) != E_OK )
369 goto error_reset;
370 /* func_id の取得 */
371 if( (ercd_=cTDR_getInt16( &func_id_ )) != E_OK )
372 goto error_reset;
373#endif
374
375 if( (ercd_ = cMessageBuffer_receive(msg) < 0 ) )
376 goto error_reset;
377 func_id_ = ((int16_t *)msg)[0];
378
379#ifdef RPC_DEBUG
380 syslog(LOG_INFO, "unmarshaler task: func_id: %d", func_id_ );
381#endif
382 switch( func_id_ ){
383EOT
384
385 # 呼び先の signature を取り出す
386 # port = @celltype.find( @next_cell_port_name )
387 # signature = port.get_signature
388 signature = @signature
389
390 # through の signature に含まれる すべての関数について
391 signature.get_function_head_array.each { |f|
392 f_name = f.get_name
393 f_type = f.get_declarator.get_type
394 id = signature.get_id_from_func_name( f_name )
395
396 # 関数は返り値を持つか?
397 if f_type.get_type.kind_of?( VoidType ) then
398 b_void = true
399 else
400 b_void = false
401 end
402
403 # パケットの終わりをチェック(未受け取りのデータが残っていないかチェック)
404 file.print " case #{id}: /*** #{f_name} ***/ \n"
405 file.print " if( tTransparentUnmarshaler_#{@signature.get_name}_#{f_name}() != E_OK )\n"
406 file.print " goto error_reset;\n"
407 file.print " break;\n"
408
409 } #
410
411 if @PPAllocatorSize then
412 ppallocator_dealloc_str = " /* PPAllocator のすべてを解放 */\n cPPAllocator_dealloc_all();"
413 else
414 ppallocator_dealloc_str = ""
415 end
416
417
418 file.print <<EOT
419 default:
420#if 0 // deleted by ishikawa: tSysLogが未実装
421 syslog(LOG_INFO, "unmarshaler task: ERROR: unknown func_id: %d", func_id_ );
422#endif /* 0 */
423 break;
424 };
425#{ppallocator_dealloc_str}
426 return;
427
428error_reset:
429#if 0
430 if( ercd_ != ERCD( E_RPC, E_RESET ) )
431 (void)cTDR_reset();
432#else
433 return ercd_;
434#endif
435#{ppallocator_dealloc_str}
436EOT
437
438 end
439
440 # IN b_marshal, b_get
441 # b_marshal = true && b_get == false : マーシャラで入力引数送出
442 # b_marshal = true && b_get == true : マーシャラで出力引数受取
443 # b_marshal = false && b_get == true : アンマーシャラで入力引数受取
444 # b_marshal = false && b_get == get : アンマーシャラで出力引数送出
445 def print_params( params, file, nest, b_marshal, b_get, b_referenced, b_oneway = false )
446 params.each{ |param|
447# p "#{param.get_name}: b_marshal: #{b_marshal} b_get: #{b_get}"
448 if ! ( b_referenced == param.is_referenced? ) then
449 next
450 end
451
452 dir = param.get_direction
453 type = param.get_type
454 if b_oneway && dir == :IN && type.get_original_type.kind_of?( PtrType ) || type.get_original_type.kind_of?( ArrayType ) then
455 # oneway, in, PtrType の場合コピー
456 alloc_cp = "cPPAllocator_alloc"
457 alloc_cp_extra = nil
458 print_param( param.get_name, type, file, nest, dir, nil, nil, b_get, alloc_cp, alloc_cp_extra )
459 else
460 if( b_get == false && b_marshal == true || b_get == true && b_marshal == false )then
461 case dir
462# when :IN, :INOUT, :SEND
463 when :IN, :INOUT, :OUT, :SEND, :RECEIVE
464 print_param_nc( param.get_name, type, file, nest, b_marshal, nil, nil, b_get )
465 end
466 else
467# case dir
468# when :OUT, :INOUT, :RECEIVE
469# when :RECEIVE
470# print_param_nc( param.get_name, type, file, nest, b_marshal, nil, nil, b_get )
471# end
472 end
473 end
474 }
475 end
476
477 #=== コピーしない引数渡しコードの出力
478 def print_param_nc( name, type, file, nest, b_marshal, outer, outer2, b_get )
479 indent = " " * ( nest + 1 )
480
481 case type
482 when DefinedType
483 print_param_nc( name, type.get_type, file, nest, b_marshal, outer, outer2, b_get )
484 when BoolType, IntType, FloatType, PtrType, ArrayType
485 case type
486 when BoolType
487 type_str = "Int8"
488 cast_str = "int8_t"
489 when IntType
490 bit_size = type.get_bit_size
491 case type.get_sign
492 when :UNSIGNED
493 signC = "U"
494 sign = "u"
495 when :SIGNED
496 if bit_size == -1 || bit_size == -11 then
497 # signed char の場合、signed を指定する
498 signC = "S"
499 sign = "s"
500 else
501 signC = ""
502 sign = ""
503 end
504 else
505 signC = ""
506 sign = ""
507 end
508
509 # p "pn:: #{name} #{bit_size} #{type.get_type_str}"
510 case bit_size
511 when -1, -11 # -1: char_t, -11: char
512 type_str = "#{signC}Char"
513 cast_str = "#{sign}char_t"
514 when -2
515 type_str = "#{signC}Short"
516 cast_str = "#{sign}short_t"
517 when -3
518 type_str = "#{signC}Int"
519 cast_str = "#{sign}int_t"
520 when -4
521 type_str = "#{signC}Long"
522 cast_str = "#{sign}long_t"
523 when -5
524 type_str = "Intptr"
525 cast_str = "intptr_t"
526 when 8, 16, 32, 64, 128
527 type_str = "#{signC}Int#{bit_size}"
528 cast_str = "#{sign}int#{bit_size}_t"
529 else
530 raise "unknown bit_size '#{bit_size}' for int type "
531 end
532
533 when FloatType
534 bit_size = type.get_bit_size
535 if bit_size == 32 then
536 type_str = "Float32"
537 cast_str = "float32_t"
538 else
539 type_str = "Double64"
540 cast_str = "double64_t"
541 end
542
543 when PtrType
544 type_str = "Intptr"
545 cast_str = "intptr_t"
546 when ArrayType
547 type_str = "Intptr"
548 cast_str = "intptr_t"
549 end
550
551 if type.get_type_str == cast_str then
552 cast_str = ""
553 else
554 cast_str = "(" + cast_str + ")"
555 end
556
557 if( b_get )then
558 cast_str.gsub!( /\)$/, "*)" )
559 file.print " " * nest
560=begin
561 file.print "if( ( ercd_ = cTDR_get#{type_str}( #{cast_str}&(#{outer}#{name}#{outer2}) ) ) != E_OK )\n"
562 file.print " " * nest
563 file.print " goto error_reset;\n"
564=end
565 file.print "#{name} = *((#{type.get_type_str} *)(&msg[#{@index}]));\n"
566 if bit_size.nil?
567 raise "HRP2 RPC supports only specified bit_size"
568 else
569 case bit_size
570 when 8, 16, 32, 64, 128
571 else
572 raise "HRP2 RPC supports only specified bit_size"
573 end
574 end
575 @index += bit_size / 8
576 else
577 file.print " " * nest
578=begin
579 file.print "if( ( ercd_ = cTDR_put#{type_str}( #{cast_str}#{outer}#{name}#{outer2} ) ) != E_OK )\n"
580 file.print " " * nest
581 file.print " goto error_reset;\n"
582=end
583 file.print "*((#{type.get_type_str} *)(&msg[#{@index}])) = #{name};\n"
584 if bit_size.nil?
585 raise "HRP2 RPC supports only specified bit_size"
586 else
587 case bit_size
588 when 8, 16, 32, 64, 128
589 else
590 raise "HRP2 RPC supports only specified bit_size"
591 end
592 end
593 @index += bit_size / 8
594 end
595
596 when StructType
597 members_decl =type.get_members_decl
598 members_decl.get_items.each { |m|
599 if m.is_referenced? then
600 print_param_nc( m.get_name, m.get_type, file, nest, b_marshal, "#{outer}#{name}#{outer2}.", nil, b_get )
601 end
602 }
603 members_decl.get_items.each { |m|
604 if ! m.is_referenced? then
605 print_param_nc( m.get_name, m.get_type, file, nest, b_marshal, "#{outer}#{name}#{outer2}.", nil, b_get )
606 end
607 }
608
609 when VoidType
610 when EnumType # mikan EnumType
611 when FuncType # mikan FuncType
612 end
613 end
614
615
616 #=== PREAMBLE 部のコード生成
617 # アンマーシャラセルタイプの場合、アンマーシャラ関数のプロトタイプ宣言を生成
618 def gen_preamble file, b_singleton, ct_name, global_name
619 if ct_name != @unmarshaler_celltype_name.to_sym then
620 return
621 end
622
623 file.print "/* アンマーシャラ関数のプロトタイプ宣言 */\n"
624 # signature に含まれる すべての関数について
625 @signature.get_function_head_array.each { |f|
626 f_name = f.get_name
627 f_type = f.get_declarator.get_type
628 id = @signature.get_id_from_func_name( f_name )
629 file.print "static ER tTransparentUnmarshaler_#{@signature.get_name}_#{f_name}();\t/* func_id: #{id} */\n"
630 }
631 file.print "\n"
632 file.print "static uint8_t msg[256];\n"
633 file.print "\n"
634 end
635
636 #=== POSTAMBLE 部のコード生成
637 # アンマーシャラセルタイプの場合、アンマーシャラ関数の生成
638 def gen_postamble file, b_singleton, ct_name, global_name
639 if ct_name != @unmarshaler_celltype_name.to_sym then
640 return
641 end
642
643 file.print "\n/*** アンマーシャラ関数 ***/\n\n"
644 @signature.get_function_head_array.each { |f|
645 f_name = f.get_name
646 f_type = f.get_declarator.get_type
647 id = @signature.get_id_from_func_name( f_name )
648
649 # 関数は返り値を持つか?
650 if f_type.get_type.kind_of?( VoidType ) then
651 b_void = true
652 else
653 b_void = false
654 end
655
656 file.print <<EOT
657/*
658 * name: #{f_name}
659 * func_id: #{id}
660 */
661EOT
662 file.print "static ER\n"
663 file.print "tTransparentUnmarshaler_#{@signature.get_name}_#{f_name}()\n"
664 file.print "{\n"
665 file.print " ER ercd_;\n"
666
667 # 引数を受取る変数の定義
668 param_list = f.get_declarator.get_type.get_paramlist.get_items
669 # FuncHead-> Decl-> FuncType->ParamList
670 param_list.each{ |par|
671 name = par.get_name
672 type = par.get_type
673 if type.kind_of? ArrayType then
674 type = type.get_type
675 aster = "(*"
676 aster2 = ")"
677 else
678 aster = ""
679 aster2 = ""
680 end
681
682 type_str = type.get_type_str.gsub( /\bconst\b */, "" ) # "const" を外す
683
684 file.printf( " %-12s %s%s%s%s;\n", type_str, aster, name, aster2, type.get_type_str_post )
685 }
686
687 # 戻り値を受け取る変数の定義
688 if ! b_void then
689 if f.is_oneway? then
690 retval_ptr = "" # oneway の場合、受け取るが捨てられる
691 else
692 # =begin ishikawa modified
693 # retval_ptr = "*"
694 retval_ptr = ""
695 # =end ishikawa modified
696 end
697 file.printf( " %-12s #{retval_ptr}retval_%s;\n", f_type.get_type.get_type_str, f_type.get_type.get_type_str_post )
698 end
699
700 # in 方向の入出力を入力
701 file.print "\n /* 入力引数受取 */\n"
702 b_get = true # unmarshal では get
703 b_marshal = false
704 @index = 2
705 print_params( param_list, file, 1, b_marshal, b_get, true, f.is_oneway? )
706 print_params( param_list, file, 1, b_marshal, b_get, false, f.is_oneway? )
707=begin
708 if ! b_void && ! f.is_oneway? then
709 ret_ptr_type = PtrType.new( f_type.get_type )
710 print_param_nc( "retval_", ret_ptr_type, file, 2, :RETURN, nil, nil, b_get )
711 end
712=end
713 # パケットの受信完了
714 # mikan 本当は、対象関数を呼出す後に実施したい.呼出しパケットの使用終わりを宣言する目的として
715 file.print " /* パケット終わりをチェック */\n"
716 if ! f.is_oneway? then
717 b_continue = "true"
718 else
719 b_continue = "false"
720 end
721=begin
722 file.print " if( (ercd_=cTDR_receiveEOP(#{b_continue})) != E_OK )\n"
723 file.print " goto error_reset;\n\n"
724=end
725 # 対象関数を呼出す
726 file.print " /* 対象関数の呼出し */\n"
727 if b_void then
728 file.print( " cServerCall_#{f_name}(" )
729 else
730 file.print( " #{retval_ptr}retval_ = cServerCall_#{f_name}(" )
731 end
732
733 delim = " "
734 param_list.each{ |par|
735 file.print delim
736 delim = ", "
737 file.print "#{par.get_name}"
738 }
739 file.print( " );\n" )
740
741 # 戻り値、出力引数の受取コードの生成
742
743 if ! b_void && ! f.is_oneway? then
744 file.print " if( (ercd_ = cMessageBuffer_send(&retval_, sizeof(#{f_type.get_type.get_type_str})) != E_OK ) )\n"
745 file.print " goto error_reset;\n"
746
747 end
748 # oneway の場合出力、戻り値が無く、受取を待たない(非同期な呼出し)
749 if ! f.is_oneway? then
750 file.print <<EOT
751 /* 関数処理の終了を通知 */
752 if( ( ercd_ = cEventflag_set( 0x01 ) ) != E_OK ){
753 goto error_reset;
754 }
755EOT
756 end # ! f.is_oneway?
757 file.print <<EOT
758 return E_OK;
759error_reset:
760 return ercd_;
761}
762
763EOT
764
765 }
766
767 end
768
769end
Note: See TracBrowser for help on using the repository browser.