source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/plugin/SharedRPCPlugin.rb@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 12.2 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# 上記著作権者
9は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
10# ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
11# 変・再é…
12å¸ƒï¼ˆä»¥ä¸‹ï¼Œåˆ©ç”¨ã¨å‘¼ã¶ï¼‰ã™ã‚‹ã“とを無償で許諾する.
13# (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
14# 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
15# スコード中に含まれていること.
16# (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
17# 用できる形で再é…
18å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
19å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
20# 者
21マニュアルなど)に,上記の著作権表示,この利用条件および下記
22# の無保証規定を掲載すること.
23# (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
24# 用できない形で再é…
25å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
26# と.
27# (a) 再é…
28å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
29マニュアルなど)に,上記の著
30# 作権表示,この利用条件および下記の無保証規定を掲載すること.
31# (b) 再é…
32å¸ƒã®å½¢æ…
33‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
34# 報告すること.
35# (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
36# 害からも,上記著作権者
37およびTOPPERSプロジェクトをå…
38è²¬ã™ã‚‹ã“と.
39# また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
40# 由に基づく請求からも,上記著作権者
41およびTOPPERSプロジェクトを
42# å…
43è²¬ã™ã‚‹ã“と.
44#
45# 本ソフトウェアは,無保証で提供されているものである.上記著作権者
46お
47# よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
48# に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
49# アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
50# の責任を負わない.
51#
52# $Id$
53#++
54
55require_tecsgen_lib "lib/GenTransparentMarshaler.rb"
56require_tecsgen_lib "lib/GenParamCopy.rb"
57
58#= SharedRPC プラグイン
59# SharedRPC チャンネルを生成する
60# プラグイン引数は GenTransparentMarshaler 参ç…
61§
62
63# mikan through plugin: namespace が考æ…
64®ã•ã‚Œã¦ã„ない
65# これを利用する場合、以下のように toppers_jsp.cdl sChannel.cdl を指定する必
66要がある
67# tecsgen toppers_jsp.cdl sChannel.cdl your_description.cdl
68
69# 以下を仮定(制限事項
70)
71# 呼びå…
72ƒã€å‘¼ã³å…
73ˆã®ã‚¨ãƒ³ãƒ‡ã‚£ã‚¢ãƒ³ã€char, short, int_t, long_t, intptr_t のサイズが同じ
74# 有符号、無符号でサイズが同じ
75
76class SharedRPCPlugin < ThroughPlugin
77
78 attr_reader :region
79 @@shared_channel_list = {}
80 include GenTransparentMarshaler
81 include GenParamCopy
82
83 #=== RPCPlugin の initialize
84 # 説明は ThroughPlugin (plugin.rb) を参ç…
85§
86 def initialize( cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell )
87
88 # mikan プラグインオプション指定の不一致のチェック task_priority,
89
90 super
91 initialize_transparent_marshaler cell_name
92
93 # オプション:GenTransparentMarshaler 参ç…
94§
95 @plugin_arg_check_proc_tab = RPCPluginArgProc
96 @channelCellName = "" # nil にしておく
97 parse_plugin_arg
98
99 @shared_channel_ct_name = :"tSharedRPCPlugin_#{@channelCelltype}"
100 @shared_channel_ct_file_name = "#{$gen}/#{@shared_channel_ct_name}.cdl"
101 @rpc_channel_celltype_name = :"tSharedRPCPlugin_#{@TDRCelltype}_#{@channelCelltype}_#{@signature.get_global_name}"
102 @rpc_channel_celltype_file_name = "#{$gen}/#{@rpc_channel_celltype_name}.cdl"
103
104 @shared_channel_cell = @channelCellName
105 if @shared_channel_cell == "" then
106 cdl_error( "SharedRPCPlugin: need channelCellName option" )
107 end
108
109 if @@shared_channel_list[ @shared_channel_cell ] == nil then
110 # 初出
111 @@shared_channel_list[ @shared_channel_cell ] = [ self ]
112 else
113 # 二番目以降
114 @@shared_channel_list[ @shared_channel_cell ] << self
115 end
116 @sub_channel_no = ( @@shared_channel_list[ @shared_channel_cell ].length ) -1
117
118 if @region != @@shared_channel_list[ @shared_channel_cell ][0].region then
119 # 初出とリージョン不一致 (初出は、自分自身とチェックされる。無駄だが小さいので放置)
120 cdl_error( "SharedRPCPlugin: preferred region mismatch current: #{@region.get_name} previous: #{@@shared_channel_list[ @shared_channel_cell ][0].region.get_name}")
121 else
122 dbgPrint "SahredRPCPlugin: Region: #{@region.get_name}, #{@@shared_channel_list[ @shared_channel_cell ][0].region.get_name}\n"
123 end
124
125 if @signature.need_PPAllocator? then
126 if @PPAllocatorSize == nil then
127 cdl_error( "PPAllocatorSize must be speicified for oneway [in] array" )
128 end
129 end
130
131 end
132
133 # def set_through_info( start_region, end_region, through_type )
134 # super
135 #
136 # end
137
138 def gen_plugin_decl_code( file )
139
140 # このセルタイプ(同じシグニチャ)は既に生成されているか?
141 if @@generated_celltype[ @shared_channel_ct_name ] == nil then
142 @@generated_celltype[ @shared_channel_ct_name ] = [ self ]
143 else
144 @@generated_celltype[ @shared_channel_ct_name ] << self
145 end
146
147 if @@generated_celltype[ @ct_name ] == nil then
148 @@generated_celltype[ @ct_name ] = [ self ]
149 else
150 @@generated_celltype[ @ct_name ] << self
151 end
152
153 gen_marshaler_celltype
154 # 同じ内
155容を二度書く可能性あり (AppFile は不可)
156
157 if @signature.need_PPAllocator? then
158 alloc_call_port = " call sPPAllocator cPPAllocator;\n"
159 alloc_call_port_join = " cPPAllocator => composite.cPPAllocator;\n"
160 else
161 alloc_call_port = ""
162 alloc_call_port_join = ""
163 end
164
165 f = CFile.open( @rpc_channel_celltype_file_name, "w" )
166 # 同じ内
167容を二度書く可能性あり (AppFile は不可)
168
169 f.print <<EOT
170import( "#{@marshaler_celltype_file_name}" );
171
172composite #{@rpc_channel_celltype_name} {
173 /* Interface */
174 call #{@signature.get_namespace_path} #{@call_port_name};
175 entry #{@signature.get_namespace_path} eThroughEntry;
176 call sTDR cTDR;
177 call sEventflag cEventflag;
178 entry sUnmarshalerMain eUnmarshalAndCallFunction;
179#{alloc_call_port}
180 [optional]
181 call sSemaphore cLockChannel;
182
183 /* Implementation */
184 cell #{@marshaler_celltype_name} #{@signature.get_global_name}_marshaler{
185 cTDR => composite.cTDR;
186 cEventflag => composite.cEventflag;
187 cLockChannel => composite.cLockChannel;
188 };
189 cell #{@unmarshaler_celltype_name} #{@signature.get_global_name}_unmarshaler{
190 cTDR => composite.cTDR;
191 cEventflag => composite.cEventflag;
192 cServerCall => composite.#{@call_port_name};
193#{alloc_call_port_join} };
194 composite.eThroughEntry => #{@signature.get_global_name}_marshaler.eClientEntry;
195 composite.eUnmarshalAndCallFunction => #{@signature.get_global_name}_unmarshaler.eUnmarshalAndCallFunction;
196};
197EOT
198 # mikan stackSize option & 最新 tecs_package 対応
199
200 f.close
201
202 f = CFile.open( "#{$gen}/#{@shared_channel_ct_name}.cdl", "w" )
203 # 同じ内
204容を二度書く可能性あり (AppFile は不可)
205
206 f.print <<EOT
207[active]
208composite #{@shared_channel_ct_name} {
209 /* Interface */
210 entry sSemaphore eSemaphore[];
211 call sUnmarshalerMain cUnmarshalAndCallFunction[];
212
213 entry sDataqueue eDataqueue;
214 entry sTDR eTDR;
215 entry sEventflag eEventflag;
216
217 attr {
218 PRI priority;
219 };
220
221 /* Implementation */
222 cell #{@channelCelltype} Channel{
223 };
224 cell tSemaphore Semaphore {count = 1; attribute = C_EXP("TA_NULL");};
225 cell tRPCSharedTaskMain RPCSharedTaskMain {
226 cUnmarshalAndCallFunction => composite.cUnmarshalAndCallFunction;
227 cServerSideTDR = Channel.eTDR;
228 };
229 cell tRPCSharedChannelMan RPCChannelMan {
230 cSemaphore = Semaphore.eSemaphore;
231 cClientSideTDR = Channel.eTDR;
232 };
233 cell tTask RPCSharedTask {
234 cBody = RPCSharedTaskMain.eMain;
235 taskAttribute = C_EXP("TA_ACT");
236 stackSize = 4096;
237 priority = composite.priority;
238 };
239 composite.eTDR => Channel.eTDR;
240 composite.eEventflag => Channel.eEventflag;
241 composite.eSemaphore => RPCChannelMan.eSemaphore;
242 composite.eDataqueue => Channel.eDataqueue;
243};
244EOT
245 f.close
246
247 end
248
249 #=== through cell コードを生成
250 #
251 #
252 def gen_through_cell_code( file )
253
254 gen_plugin_decl_code( file )
255
256 file.print <<EOT
257import( "#{@rpc_channel_celltype_file_name}" );
258import( "#{$gen}/#{@shared_channel_ct_name}.cdl" );
259EOT
260
261 # nest = @next_cell.get_region.gen_region_str_pre file
262 nest = @region.gen_region_str_pre file
263 indent_str = " " * nest
264 if @next_cell_port_subscript then
265 subscript = '[' + @next_cell_port_subscript.to_s + ']'
266 else
267 subscript = ""
268 end
269
270 # セルを探す
271 # path =["::",@next_cell.get_name]
272 # cell = Namespace.find( path )
273 cell = Namespace.find( @next_cell.get_namespace_path )
274
275 # PPAllocator が必
276要か?
277 if @signature.need_PPAllocator? then
278 if @sub_channel_no == 0 then
279 file.print <<EOT
280#{indent_str}cell tPPAllocator PPAllocator_#{@shared_channel_cell}{
281#{indent_str} heapSize = #{@PPAllocatorSize};
282#{indent_str}};
283EOT
284 end
285
286 ppallocator_join = "#{indent_str} cPPAllocator = PPAllocator_#{@shared_channel_cell}.ePPAllocator;\n"
287 else
288 ppallocator_join = ""
289 end
290
291 # å…
292±æœ‰ã•ã‚Œã‚‹é€šä¿¡ãƒãƒ£ãƒ³ãƒãƒ«ã®ç”Ÿæˆã®ãƒ—ロトタイプ宣言
293 file.print <<EOT
294#{indent_str}cell #{@shared_channel_ct_name} #{@shared_channel_cell};
295EOT
296
297 # ここから各結合ごとのセルを生成
298
299 # アロケータの指定があるか?
300 if cell.get_allocator_list.length > 0 then
301
302 file.print "#{indent_str}[allocator("
303
304 delim = ""
305 cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
306
307 file.print delim
308 delim = ",\n#{indent_str} " # 最終行には出さない
309
310 if subsc then # é…
311åˆ—添数
312 subsc_str = '[#{subsc}]'
313 else
314 subsc_str = ""
315 end
316
317 eport = "eThroughEntry" #RPCの受け口名に変更
318 file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc}"
319 end
320
321 file.puts ")]"
322 end
323
324 # セル本体の生成
325 file.print <<EOT
326#{indent_str}cell #{@rpc_channel_celltype_name} #{@cell_name} {
327#{indent_str} #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name}#{subscript};
328#{indent_str} cTDR = #{@shared_channel_cell}.eTDR;
329#{indent_str} cEventflag = #{@shared_channel_cell}.eEventflag;
330#{indent_str} cLockChannel = #{@shared_channel_cell}.eSemaphore[#{@sub_channel_no}];
331#{ppallocator_join}#{indent_str}};
332EOT
333 @region.gen_region_str_post file
334 end
335
336 #=== 後ろのコードを生成
337 #プラグインの後ろのコードを生成
338 #file:: File:
339 def self.gen_post_code( file )
340 file.print "/* '#{self.name}' post code */\n"
341 @@shared_channel_list.each{ |chan_name,plugin_obj|
342 plugin_obj[0].gen_post_code( file, plugin_obj )
343 }
344 end
345
346 #=== 後ろのコードを生成
347 # plugin_obj[0] が代表して出力する(インスタンス変数にアクセスしたいため)
348 def gen_post_code( file, plugin_obj )
349
350 chan_name = @shared_channel_cell
351
352 nest = @region.gen_region_str_pre file
353 indent_str = " " * nest
354
355 # å…
356±æœ‰ã•ã‚Œã¦ã„る通信チャンネルの生成
357 # 各プラグインインスタンスでは @shared_channel_ct_name として記憶している
358 file.print "#{indent_str}cell tSharedRPCPlugin_#{@channelCelltype} #{chan_name} {\n"
359 plugin_obj.each{ |po|
360 file.print <<EOT
361#{indent_str} cUnmarshalAndCallFunction[] = #{@cell_name}.eUnmarshalAndCallFunction;
362EOT
363 }
364 file.printf "#{indent_str} priority = #{@task_priority};\n#{indent_str}};\n"
365 @region.gen_region_str_post file
366
367 end
368
369end
370
Note: See TracBrowser for help on using the repository browser.