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