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