source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tecsgen/tecslib/plugin/HRP2RPCPlugin.rb@ 374

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

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 11.7 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# $Id$
38#++
39
40require_tecsgen_lib "lib/GenHRP2Marshaler.rb"
41
42# require_tecsgen_lib "GenParamCopy.rb"
43
44#= Transparent RPC プラグイン
45# Transparent RPC チャンネルを生成する
46# プラグイン引数は以下の RPCPluginArgProc を参照
47
48# mikan through plugin: namespace が考慮されていない
49# これを利用する場合、以下のように toppers_jsp.cdl sChannel.cdl を指定する必要がある
50# tecsgen toppers_jsp.cdl sChannel.cdl your_description.cdl
51
52# 以下を仮定(制限事項)
53# 呼び元、呼び先のエンディアン、char, short, int_t, long_t, intptr_t のサイズが同じ
54# 有符号、無符号でサイズが同じ
55
56#
57# RPCを用いたドメイン間通信の
58# throughプラグイン
59# HRP2ドメインプラグインによって挿入される
60#
61class HRP2RPCPlugin < ThroughPlugin
62
63 include GenTransparentMarshaler
64 # include GenParamCopy
65
66 # RPCPlugin 専用のオプション
67 TransparentRPCPluginArgProc = RPCPluginArgProc.dup # 複製を作って元を変更しないようにする
68 TransparentRPCPluginArgProc[ "noClientSemaphore" ] = Proc.new { |obj,rhs| obj.set_noClientSemaphore rhs }
69 TransparentRPCPluginArgProc[ "semaphoreCelltype" ] = Proc.new { |obj,rhs| obj.set_semaphoreCelltype rhs }
70
71 #=== RPCPlugin の initialize
72 # 説明は ThroughPlugin (plugin.rb) を参照
73 def initialize( cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell )
74 super
75 @b_noClientSemaphore = false
76 @semaphoreCelltype = "tSemaphore"
77 initialize_transparent_marshaler cell_name
78
79 # オプション:GenTransparentMarshaler 参照
80 @plugin_arg_check_proc_tab = TransparentRPCPluginArgProc
81 parse_plugin_arg
82
83 @rpc_channel_celltype_name = "tRPCPlugin_#{@TDRCelltype}_#{@channelCelltype}_#{@signature.get_name}"
84 @rpc_channel_celltype_file_name = "#{$gen}/#{@rpc_channel_celltype_name}.cdl"
85
86 if @signature.need_PPAllocator? then
87 if @PPAllocatorSize == nil then
88 cdl_error( "PPAllocatorSize must be speicified for oneway [in] array" )
89 # @PPAllocatorSize = 0 # 仮に 0 としておく (cdl の構文エラーを避けるため)
90 end
91 end
92
93# @signature.each_param{ |func_decl, param_decl|
94# if func_decl.get_type.is_oneway? then
95# if ( param_decl.get_size || param_decl.get_count ) && param_decl.get_string then
96# cdl_error( "array of string not supported for oneway function in Transparent RPC" ) # mikan 文字列の配列
97# elsif param_decl.get_string == -1 then
98# cdl_error( "length unspecified string is not permited for oneway function in Transparent RPC" ) # mikan 長さ未指定文字列
99# end
100# end
101# }
102 end
103
104 #=== plugin の宣言コード (celltype の定義) 生成
105 def gen_plugin_decl_code( file )
106
107 ct_name = "#{@ct_name}_#{@channelCelltype}"
108
109 # このセルタイプ(同じシグニチャ)は既に生成されているか?
110 if @@generated_celltype[ ct_name ] == nil then
111 @@generated_celltype[ ct_name ] = [ self ]
112 else
113 @@generated_celltype[ ct_name ] << self
114 return
115 end
116
117 gen_marshaler_celltype
118
119 if @PPAllocatorSize then
120 alloc_cell = " cell tPPAllocator PPAllocator {\n heapSize = #{@PPAllocatorSize};\n };\n"
121 alloc_call_port_join = " cPPAllocator = PPAllocator.ePPAllocator;\n"
122 else
123 alloc_cell = ""
124 alloc_call_port_join = ""
125 end
126
127 if @b_noClientSemaphore == false then
128 semaphore1 = <<EOT
129 // Semaphore for Multi-task use ("specify noClientSemaphore" option to delete this)
130 cell #{@semaphoreCelltype} Semaphore {
131 count = 1;
132 attribute = C_EXP( "TA_NULL" );
133 };
134EOT
135 semaphore2 = " cLockChannel = Semaphore.eSemaphore;\n"
136 else
137 semaphore1 = ""
138 semaphore2 = ""
139 end
140
141 f = CFile.open( @rpc_channel_celltype_file_name, "w" )
142 # 同じ内容を二度書く可能性あり (AppFile は不可)
143
144 f.print <<EOT
145import( "#{@marshaler_celltype_file_name}" );
146
147composite #{@rpc_channel_celltype_name}Client {
148 /* Interface */
149 entry #{@signature.get_name} eThroughEntry;
150 //call sTDR cTDR;
151 call sEventflag cEventflag;
152 call sSemaphore cSemaphore;
153 call sMessageBuffer cMessageBuffer;
154
155 /* Implementation */
156#{semaphore1}
157 cell #{@marshaler_celltype_name} #{@signature.get_name}_marshaler{
158 //cTDR => composite.cTDR;
159 cEventflag => composite.cEventflag;
160 cSemaphore => composite.cSemaphore;
161 cMessageBuffer => composite.cMessageBuffer;
162#{semaphore2} };
163 composite.eThroughEntry => #{@signature.get_name}_marshaler.eClientEntry;
164};
165
166[active]
167composite #{@rpc_channel_celltype_name}Server {
168 /* Interface */
169 attr {
170 PRI taskPriority;
171 };
172 call #{@signature.get_name} #{@call_port_name};
173 //call sTDR cTDR;
174 call sEventflag cEventflag;
175 call sSemaphore cSemaphore;
176 call sMessageBuffer cMessageBuffer;
177
178 /* Implementation */
179#{alloc_cell} cell #{@unmarshaler_celltype_name} #{@signature.get_name}_unmarshaler{
180 //cTDR => composite.cTDR;
181 cEventflag => composite.cEventflag;
182 cSemaphore => composite.cSemaphore;
183 cMessageBuffer => composite.cMessageBuffer;
184 cServerCall => composite.#{@call_port_name};
185#{alloc_call_port_join} };
186 cell tRPCDedicatedTaskMain RPCTaskMain{
187 cMain = #{@signature.get_name}_unmarshaler.eUnmarshalAndCallFunction;
188 };
189 cell tTask Task {
190 cBody = RPCTaskMain.eMain;
191 priority = taskPriority;
192 taskAttribute = C_EXP( "TA_ACT" ); /* mikan : marshaler starts at the beginning */
193 //stackSize = 4096;
194 userStackSize = 4096;
195 };
196};
197EOT
198 # mikan stackSize option & 最新 tecs_package 対応
199
200 f.close
201 end
202
203 #=== through cell コードを生成
204 #
205 #
206 def gen_through_cell_code( file )
207
208 gen_plugin_decl_code( file )
209
210 # セルを探す
211 # path =["::",@next_cell.get_name]
212 # cell = Namespace.find( path )
213 cell = Namespace.find( @next_cell.get_namespace_path )
214
215 file.print <<EOT
216import( "#{@rpc_channel_celltype_file_name}" );
217EOT
218
219 #nest = @end_region.gen_region_str_pre file
220 indent_str = ""
221
222 file.print <<EOT
223#{indent_str}// one way channel cell
224#{indent_str}cell #{@channelCelltype} #{@channelCellName} {
225#{indent_str}};
226
227#{indent_str}// RPC channel cell
228EOT
229
230 nest = @start_region.gen_region_str_pre file
231 indent_str = " " * nest
232
233 # #473 が解決された場合、composite リレーアロケータに変更すべき
234 # アロケータの指定があるか?
235 if cell.get_allocator_list.length > 0 then
236
237 dbgPrint "make allocator\n"
238 file.print "#{indent_str}[allocator("
239
240 delim = ""
241 cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
242
243 file.print delim
244 delim = ",\n#{indent_str} " # 最終行には出さない
245
246 if subsc then # 配列添数
247 subsc_str = '[#{subsc}]'
248 else
249 subsc_str = ""
250 end
251
252 eport = "eThroughEntry" #RPCの受け口名に変更
253 file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc}"
254 end
255
256 file.puts ")]"
257 end
258
259 file.print <<EOT
260#{indent_str}cell #{@rpc_channel_celltype_name}Client #{@cell_name} {
261#{indent_str} //cTDR = #{@channelCellName}.eTDR;
262#{indent_str} cEventflag = #{@channelCellName}.eEventflag;
263#{indent_str} cSemaphore = #{@channelCellName}.eSemaphore;
264#{indent_str} cMessageBuffer = #{@channelCellName}.eMessageBuffer;
265#{indent_str}};
266EOT
267
268 @start_region.gen_region_str_post file
269
270 nest = @end_region.gen_region_str_pre file
271 indent_str = " " * nest
272 nest_str = " " * nest
273 if @next_cell_port_subscript then
274 subscript = '[' + @next_cell_port_subscript.to_s + ']'
275 else
276 subscript = ""
277 end
278
279 file.print <<EOT
280#{indent_str}cell #{@rpc_channel_celltype_name}Server #{@cell_name}Body {
281#{indent_str} #{@call_port_name} = #{@next_cell.get_namespace_path.get_path_str}.#{@next_cell_port_name}#{subscript};
282//#{indent_str} #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name};
283#{indent_str} //cTDR = #{@channelCellName}.eTDR;
284#{indent_str} cEventflag = #{@channelCellName}.eEventflag;
285#{indent_str} cSemaphore = #{@channelCellName}.eSemaphore;
286#{indent_str} cMessageBuffer = #{@channelCellName}.eMessageBuffer;
287#{indent_str} taskPriority = #{@task_priority};
288#{indent_str}};
289EOT
290
291 @end_region.gen_region_str_post file
292 end
293
294
295 #=== プラグイン引数 noClientSemaphore のチェック
296 def set_noClientSemaphore rhs
297 rhs = rhs.to_sym
298 if rhs == :true then
299 @b_noClientSemaphore = true
300 elsif rhs == :false then
301 @b_noClientSemaphore = false
302 else
303 cdl_error( "RPCPlugin: specify true or false for noClientSemaphore" )
304 end
305 end
306
307 #=== プラグイン引数 semaphoreCelltype のチェック
308 def set_semaphoreCelltype rhs
309 @semaphoreCelltype = rhs.to_sym
310 nsp = NamespacePath.analyze( @semaphoreCelltype.to_s )
311 obj = Namespace.find( nsp )
312 if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
313 cdl_error( "RPCPlugin: semaphoreCelltype '#{rhs}' not celltype or not defined" )
314 end
315 end
316
317 #=== NamespacePath を得る
318 # 生成するセルの namespace path を生成する
319 def get_cell_namespace_path
320# nsp = @region.get_namespace.get_namespace_path
321 nsp = @start_region.get_namespace_path
322 return nsp.append( @cell_name )
323 end
324
325end
326
327
Note: See TracBrowser for help on using the repository browser.