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 | #= 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 | class 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, 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 | };
|
---|
128 | EOT
|
---|
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
|
---|
139 | import( "#{@marshaler_celltype_file_name}" );
|
---|
140 |
|
---|
141 | [active]
|
---|
142 | composite #{@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 | };
|
---|
174 | EOT
|
---|
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
|
---|
193 | import( "#{@rpc_channel_celltype_file_name}" );
|
---|
194 |
|
---|
195 | EOT
|
---|
196 |
|
---|
197 | nest = @region.gen_region_str_pre file
|
---|
198 | indent_str = " " * nest
|
---|
199 |
|
---|
200 | file.print <<EOT
|
---|
201 | #{indent_str}// 一方向チャンネルセル
|
---|
202 | #{indent_str}cell #{@channelCelltype} #{@channelCellName} {
|
---|
203 | #{indent_str}};
|
---|
204 |
|
---|
205 | #{indent_str}// RPC チャンネルセル
|
---|
206 | EOT
|
---|
207 |
|
---|
208 | # #473 が解決された場合、composite リレーアロケータに変更すべき
|
---|
209 | # アロケータの指定があるか?
|
---|
210 | if cell.get_allocator_list.length > 0 then
|
---|
211 |
|
---|
212 | file.print "#{indent_str}[allocator("
|
---|
213 |
|
---|
214 | delim = ""
|
---|
215 | cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
|
---|
216 |
|
---|
217 | file.print delim
|
---|
218 | delim = ",\n#{indent_str} " # 最終行には出さない
|
---|
219 |
|
---|
220 | if subsc then # 配列添数
|
---|
221 | subsc_str = '[#{subsc}]'
|
---|
222 | else
|
---|
223 | subsc_str = ""
|
---|
224 | end
|
---|
225 |
|
---|
226 | eport = "eThroughEntry" #RPCの受け口名に変更
|
---|
227 | file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc}"
|
---|
228 | end
|
---|
229 |
|
---|
230 | file.puts ")]"
|
---|
231 | end
|
---|
232 |
|
---|
233 | file.print <<EOT
|
---|
234 | #{indent_str}cell #{@rpc_channel_celltype_name} #{@cell_name} {
|
---|
235 | #{indent_str} #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name};
|
---|
236 | #{indent_str} cTDR = #{@channelCellName}.eTDR;
|
---|
237 | #{indent_str} cEventflag = #{@channelCellName}.eEventflag;
|
---|
238 | #{indent_str} taskPriority = #{@task_priority};
|
---|
239 | #{indent_str}};
|
---|
240 | EOT
|
---|
241 | @region.gen_region_str_post file
|
---|
242 | end
|
---|
243 |
|
---|
244 |
|
---|
245 | #=== プラグイン引数 noClientSemaphore のチェック
|
---|
246 | def set_noClientSemaphore rhs
|
---|
247 | rhs = rhs.to_sym
|
---|
248 | if rhs == :true then
|
---|
249 | @b_noClientSemaphore = true
|
---|
250 | elsif rhs == :false then
|
---|
251 | @b_noClientSemaphore = false
|
---|
252 | else
|
---|
253 | cdl_error( "RPCPlugin: specify true or false for noClientSemaphore" )
|
---|
254 | end
|
---|
255 | end
|
---|
256 |
|
---|
257 | #=== プラグイン引数 semaphoreCelltype のチェック
|
---|
258 | def set_semaphoreCelltype rhs
|
---|
259 | @semaphoreCelltype = rhs.to_sym
|
---|
260 | nsp = NamespacePath.analyze( @semaphoreCelltype.to_s )
|
---|
261 | obj = Namespace.find( nsp )
|
---|
262 | if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
|
---|
263 | cdl_error( "RPCPlugin: semaphoreCelltype '#{rhs}' not celltype or not defined" )
|
---|
264 | end
|
---|
265 | end
|
---|
266 | end
|
---|
267 |
|
---|
268 |
|
---|