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