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

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

arm向けASP3版ECNLを追加

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