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 |
|
---|
40 | require_tecsgen_lib "lib/GenTransparentMarshaler.rb"
|
---|
41 | require_tecsgen_lib "lib/GenParamCopy.rb"
|
---|
42 |
|
---|
43 | #= SharedRPC プラグイン
|
---|
44 | # SharedRPC チャンネルを生成する
|
---|
45 | # プラグイン引数は GenTransparentMarshaler 参照
|
---|
46 |
|
---|
47 | # mikan through plugin: namespace が考慮されていない
|
---|
48 | # これを利用する場合、以下のように toppers_jsp.cdl sChannel.cdl を指定する必要がある
|
---|
49 | # tecsgen toppers_jsp.cdl sChannel.cdl your_description.cdl
|
---|
50 |
|
---|
51 | # 以下を仮定(制限事項)
|
---|
52 | # 呼び元、呼び先のエンディアン、char, short, int_t, long_t, intptr_t のサイズが同じ
|
---|
53 | # 有符号、無符号でサイズが同じ
|
---|
54 |
|
---|
55 | class SharedRPCPlugin < ThroughPlugin
|
---|
56 |
|
---|
57 | attr_reader :region
|
---|
58 | @@shared_channel_list = {}
|
---|
59 | include GenTransparentMarshaler
|
---|
60 | include GenParamCopy
|
---|
61 |
|
---|
62 | #=== RPCPlugin の initialize
|
---|
63 | # 説明は ThroughPlugin (plugin.rb) を参照
|
---|
64 | def initialize( cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell )
|
---|
65 |
|
---|
66 | # mikan プラグインオプション指定の不一致のチェック task_priority,
|
---|
67 |
|
---|
68 | super
|
---|
69 | initialize_transparent_marshaler cell_name
|
---|
70 |
|
---|
71 | # オプション:GenTransparentMarshaler 参照
|
---|
72 | @plugin_arg_check_proc_tab = RPCPluginArgProc
|
---|
73 | @channelCellName = "" # nil にしておく
|
---|
74 | parse_plugin_arg
|
---|
75 |
|
---|
76 | @shared_channel_ct_name = :"tSharedRPCPlugin_#{@channelCelltype}"
|
---|
77 | @shared_channel_ct_file_name = "#{$gen}/#{@shared_channel_ct_name}.cdl"
|
---|
78 | @rpc_channel_celltype_name = :"tSharedRPCPlugin_#{@TDRCelltype}_#{@channelCelltype}_#{@signature.get_global_name}"
|
---|
79 | @rpc_channel_celltype_file_name = "#{$gen}/#{@rpc_channel_celltype_name}.cdl"
|
---|
80 |
|
---|
81 | @shared_channel_cell = @channelCellName
|
---|
82 | if @shared_channel_cell == "" then
|
---|
83 | cdl_error( "SharedRPCPlugin: need channelCellName option" )
|
---|
84 | end
|
---|
85 |
|
---|
86 | if @@shared_channel_list[ @shared_channel_cell ] == nil then
|
---|
87 | # 初出
|
---|
88 | @@shared_channel_list[ @shared_channel_cell ] = [ self ]
|
---|
89 | else
|
---|
90 | # 二番目以降
|
---|
91 | @@shared_channel_list[ @shared_channel_cell ] << self
|
---|
92 | end
|
---|
93 | @sub_channel_no = ( @@shared_channel_list[ @shared_channel_cell ].length ) -1
|
---|
94 |
|
---|
95 | if @region != @@shared_channel_list[ @shared_channel_cell ][0].region then
|
---|
96 | # 初出とリージョン不一致 (初出は、自分自身とチェックされる。無駄だが小さいので放置)
|
---|
97 | cdl_error( "SharedRPCPlugin: preferred region mismatch current: #{@region.get_name} previous: #{@@shared_channel_list[ @shared_channel_cell ][0].region.get_name}")
|
---|
98 | else
|
---|
99 | dbgPrint "SahredRPCPlugin: Region: #{@region.get_name}, #{@@shared_channel_list[ @shared_channel_cell ][0].region.get_name}\n"
|
---|
100 | end
|
---|
101 |
|
---|
102 | if @signature.need_PPAllocator? then
|
---|
103 | if @PPAllocatorSize == nil then
|
---|
104 | cdl_error( "PPAllocatorSize must be speicified for oneway [in] array" )
|
---|
105 | end
|
---|
106 | end
|
---|
107 |
|
---|
108 | end
|
---|
109 |
|
---|
110 | # def set_through_info( start_region, end_region, through_type )
|
---|
111 | # super
|
---|
112 | #
|
---|
113 | # end
|
---|
114 |
|
---|
115 | def gen_plugin_decl_code( file )
|
---|
116 |
|
---|
117 | # このセルタイプ(同じシグニチャ)は既に生成されているか?
|
---|
118 | if @@generated_celltype[ @shared_channel_ct_name ] == nil then
|
---|
119 | @@generated_celltype[ @shared_channel_ct_name ] = [ self ]
|
---|
120 | else
|
---|
121 | @@generated_celltype[ @shared_channel_ct_name ] << self
|
---|
122 | end
|
---|
123 |
|
---|
124 | if @@generated_celltype[ @ct_name ] == nil then
|
---|
125 | @@generated_celltype[ @ct_name ] = [ self ]
|
---|
126 | else
|
---|
127 | @@generated_celltype[ @ct_name ] << self
|
---|
128 | end
|
---|
129 |
|
---|
130 | gen_marshaler_celltype
|
---|
131 | # 同じ内容を二度書く可能性あり (AppFile は不可)
|
---|
132 |
|
---|
133 | if @signature.need_PPAllocator? then
|
---|
134 | alloc_call_port = " call sPPAllocator cPPAllocator;\n"
|
---|
135 | alloc_call_port_join = " cPPAllocator => composite.cPPAllocator;\n"
|
---|
136 | else
|
---|
137 | alloc_call_port = ""
|
---|
138 | alloc_call_port_join = ""
|
---|
139 | end
|
---|
140 |
|
---|
141 | f = CFile.open( @rpc_channel_celltype_file_name, "w" )
|
---|
142 | # 同じ内容を二度書く可能性あり (AppFile は不可)
|
---|
143 |
|
---|
144 | f.print <<EOT
|
---|
145 | import( "#{@marshaler_celltype_file_name}" );
|
---|
146 |
|
---|
147 | composite #{@rpc_channel_celltype_name} {
|
---|
148 | /* Interface */
|
---|
149 | call #{@signature.get_namespace_path} #{@call_port_name};
|
---|
150 | entry #{@signature.get_namespace_path} eThroughEntry;
|
---|
151 | call sTDR cTDR;
|
---|
152 | call sEventflag cEventflag;
|
---|
153 | entry sUnmarshalerMain eUnmarshalAndCallFunction;
|
---|
154 | #{alloc_call_port}
|
---|
155 | [optional]
|
---|
156 | call sSemaphore cLockChannel;
|
---|
157 |
|
---|
158 | /* Implementation */
|
---|
159 | cell #{@marshaler_celltype_name} #{@signature.get_global_name}_marshaler{
|
---|
160 | cTDR => composite.cTDR;
|
---|
161 | cEventflag => composite.cEventflag;
|
---|
162 | cLockChannel => composite.cLockChannel;
|
---|
163 | };
|
---|
164 | cell #{@unmarshaler_celltype_name} #{@signature.get_global_name}_unmarshaler{
|
---|
165 | cTDR => composite.cTDR;
|
---|
166 | cEventflag => composite.cEventflag;
|
---|
167 | cServerCall => composite.#{@call_port_name};
|
---|
168 | #{alloc_call_port_join} };
|
---|
169 | composite.eThroughEntry => #{@signature.get_global_name}_marshaler.eClientEntry;
|
---|
170 | composite.eUnmarshalAndCallFunction => #{@signature.get_global_name}_unmarshaler.eUnmarshalAndCallFunction;
|
---|
171 | };
|
---|
172 | EOT
|
---|
173 | # mikan stackSize option & 最新 tecs_package 対応
|
---|
174 |
|
---|
175 | f.close
|
---|
176 |
|
---|
177 | f = CFile.open( "#{$gen}/#{@shared_channel_ct_name}.cdl", "w" )
|
---|
178 | # 同じ内容を二度書く可能性あり (AppFile は不可)
|
---|
179 |
|
---|
180 | f.print <<EOT
|
---|
181 | [active]
|
---|
182 | composite #{@shared_channel_ct_name} {
|
---|
183 | /* Interface */
|
---|
184 | entry sSemaphore eSemaphore[];
|
---|
185 | call sUnmarshalerMain cUnmarshalAndCallFunction[];
|
---|
186 |
|
---|
187 | entry sDataqueue eDataqueue;
|
---|
188 | entry sTDR eTDR;
|
---|
189 | entry sEventflag eEventflag;
|
---|
190 |
|
---|
191 | attr {
|
---|
192 | PRI priority;
|
---|
193 | };
|
---|
194 |
|
---|
195 | /* Implementation */
|
---|
196 | cell #{@channelCelltype} Channel{
|
---|
197 | };
|
---|
198 | cell tSemaphore Semaphore {count = 1; attribute = C_EXP("TA_NULL");};
|
---|
199 | cell tRPCSharedTaskMain RPCSharedTaskMain {
|
---|
200 | cUnmarshalAndCallFunction => composite.cUnmarshalAndCallFunction;
|
---|
201 | cServerSideTDR = Channel.eTDR;
|
---|
202 | };
|
---|
203 | cell tRPCSharedChannelMan RPCChannelMan {
|
---|
204 | cSemaphore = Semaphore.eSemaphore;
|
---|
205 | cClientSideTDR = Channel.eTDR;
|
---|
206 | };
|
---|
207 | cell tTask RPCSharedTask {
|
---|
208 | cBody = RPCSharedTaskMain.eMain;
|
---|
209 | taskAttribute = C_EXP("TA_ACT");
|
---|
210 | stackSize = 4096;
|
---|
211 | priority = composite.priority;
|
---|
212 | };
|
---|
213 | composite.eTDR => Channel.eTDR;
|
---|
214 | composite.eEventflag => Channel.eEventflag;
|
---|
215 | composite.eSemaphore => RPCChannelMan.eSemaphore;
|
---|
216 | composite.eDataqueue => Channel.eDataqueue;
|
---|
217 | };
|
---|
218 | EOT
|
---|
219 | f.close
|
---|
220 |
|
---|
221 | end
|
---|
222 |
|
---|
223 | #=== through cell コードを生成
|
---|
224 | #
|
---|
225 | #
|
---|
226 | def gen_through_cell_code( file )
|
---|
227 |
|
---|
228 | gen_plugin_decl_code( file )
|
---|
229 |
|
---|
230 | file.print <<EOT
|
---|
231 | import( "#{@rpc_channel_celltype_file_name}" );
|
---|
232 | import( "#{$gen}/#{@shared_channel_ct_name}.cdl" );
|
---|
233 | EOT
|
---|
234 |
|
---|
235 | # nest = @next_cell.get_region.gen_region_str_pre file
|
---|
236 | nest = @region.gen_region_str_pre file
|
---|
237 | indent_str = " " * nest
|
---|
238 | if @next_cell_port_subscript then
|
---|
239 | subscript = '[' + @next_cell_port_subscript.to_s + ']'
|
---|
240 | else
|
---|
241 | subscript = ""
|
---|
242 | end
|
---|
243 |
|
---|
244 | # セルを探す
|
---|
245 | # path =["::",@next_cell.get_name]
|
---|
246 | # cell = Namespace.find( path )
|
---|
247 | cell = Namespace.find( @next_cell.get_namespace_path )
|
---|
248 |
|
---|
249 | # PPAllocator が必要か?
|
---|
250 | if @signature.need_PPAllocator? then
|
---|
251 | if @sub_channel_no == 0 then
|
---|
252 | file.print <<EOT
|
---|
253 | #{indent_str}cell tPPAllocator PPAllocator_#{@shared_channel_cell}{
|
---|
254 | #{indent_str} heapSize = #{@PPAllocatorSize};
|
---|
255 | #{indent_str}};
|
---|
256 | EOT
|
---|
257 | end
|
---|
258 |
|
---|
259 | ppallocator_join = "#{indent_str} cPPAllocator = PPAllocator_#{@shared_channel_cell}.ePPAllocator;\n"
|
---|
260 | else
|
---|
261 | ppallocator_join = ""
|
---|
262 | end
|
---|
263 |
|
---|
264 | # 共有される通信チャンネルの生成のプロトタイプ宣言
|
---|
265 | file.print <<EOT
|
---|
266 | #{indent_str}cell #{@shared_channel_ct_name} #{@shared_channel_cell};
|
---|
267 | EOT
|
---|
268 |
|
---|
269 | # ここから各結合ごとのセルを生成
|
---|
270 |
|
---|
271 | # アロケータの指定があるか?
|
---|
272 | if cell.get_allocator_list.length > 0 then
|
---|
273 |
|
---|
274 | file.print "#{indent_str}[allocator("
|
---|
275 |
|
---|
276 | delim = ""
|
---|
277 | cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
|
---|
278 |
|
---|
279 | file.print delim
|
---|
280 | delim = ",\n#{indent_str} " # 最終行には出さない
|
---|
281 |
|
---|
282 | if subsc then # 配列添数
|
---|
283 | subsc_str = '[#{subsc}]'
|
---|
284 | else
|
---|
285 | subsc_str = ""
|
---|
286 | end
|
---|
287 |
|
---|
288 | eport = "eThroughEntry" #RPCの受け口名に変更
|
---|
289 | file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc}"
|
---|
290 | end
|
---|
291 |
|
---|
292 | file.puts ")]"
|
---|
293 | end
|
---|
294 |
|
---|
295 | # セル本体の生成
|
---|
296 | file.print <<EOT
|
---|
297 | #{indent_str}cell #{@rpc_channel_celltype_name} #{@cell_name} {
|
---|
298 | #{indent_str} #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name}#{subscript};
|
---|
299 | #{indent_str} cTDR = #{@shared_channel_cell}.eTDR;
|
---|
300 | #{indent_str} cEventflag = #{@shared_channel_cell}.eEventflag;
|
---|
301 | #{indent_str} cLockChannel = #{@shared_channel_cell}.eSemaphore[#{@sub_channel_no}];
|
---|
302 | #{ppallocator_join}#{indent_str}};
|
---|
303 | EOT
|
---|
304 | @region.gen_region_str_post file
|
---|
305 | end
|
---|
306 |
|
---|
307 | #=== 後ろのコードを生成
|
---|
308 | #プラグインの後ろのコードを生成
|
---|
309 | #file:: File:
|
---|
310 | def self.gen_post_code( file )
|
---|
311 | file.print "/* '#{self.name}' post code */\n"
|
---|
312 | @@shared_channel_list.each{ |chan_name,plugin_obj|
|
---|
313 | plugin_obj[0].gen_post_code( file, plugin_obj )
|
---|
314 | }
|
---|
315 | end
|
---|
316 |
|
---|
317 | #=== 後ろのコードを生成
|
---|
318 | # plugin_obj[0] が代表して出力する(インスタンス変数にアクセスしたいため)
|
---|
319 | def gen_post_code( file, plugin_obj )
|
---|
320 |
|
---|
321 | chan_name = @shared_channel_cell
|
---|
322 |
|
---|
323 | nest = @region.gen_region_str_pre file
|
---|
324 | indent_str = " " * nest
|
---|
325 |
|
---|
326 | # 共有されている通信チャンネルの生成
|
---|
327 | # 各プラグインインスタンスでは @shared_channel_ct_name として記憶している
|
---|
328 | file.print "#{indent_str}cell tSharedRPCPlugin_#{@channelCelltype} #{chan_name} {\n"
|
---|
329 | plugin_obj.each{ |po|
|
---|
330 | file.print <<EOT
|
---|
331 | #{indent_str} cUnmarshalAndCallFunction[] = #{@cell_name}.eUnmarshalAndCallFunction;
|
---|
332 | EOT
|
---|
333 | }
|
---|
334 | file.printf "#{indent_str} priority = #{@task_priority};\n#{indent_str}};\n"
|
---|
335 | @region.gen_region_str_post file
|
---|
336 |
|
---|
337 | end
|
---|
338 |
|
---|
339 | end
|
---|
340 |
|
---|