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: SharedRPCPlugin.rb 1011 2016-07-11 02:20:01Z coas-nagasima $
|
---|
53 | #++
|
---|
54 |
|
---|
55 | require_tecsgen_lib "lib/GenTransparentMarshaler.rb"
|
---|
56 | require_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 |
|
---|
76 | class 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, 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
|
---|
170 | import( "#{@marshaler_celltype_file_name}" );
|
---|
171 |
|
---|
172 | composite #{@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 | };
|
---|
197 | EOT
|
---|
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]
|
---|
208 | composite #{@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 | };
|
---|
244 | EOT
|
---|
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
|
---|
257 | import( "#{@rpc_channel_celltype_file_name}" );
|
---|
258 | import( "#{$gen}/#{@shared_channel_ct_name}.cdl" );
|
---|
259 | EOT
|
---|
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 |
|
---|
265 | # ã»ã«ãæ¢ã
|
---|
266 | # path =["::",@next_cell.get_name]
|
---|
267 | # cell = Namespace.find( path )
|
---|
268 | cell = Namespace.find( @next_cell.get_namespace_path )
|
---|
269 |
|
---|
270 | # PPAllocator ãå¿
|
---|
271 | è¦ã?
|
---|
272 | if @signature.need_PPAllocator? then
|
---|
273 | if @sub_channel_no == 0 then
|
---|
274 | file.print <<EOT
|
---|
275 | #{indent_str}cell tPPAllocator PPAllocator_#{@shared_channel_cell}{
|
---|
276 | #{indent_str} heapSize = #{@PPAllocatorSize};
|
---|
277 | #{indent_str}};
|
---|
278 | EOT
|
---|
279 | end
|
---|
280 |
|
---|
281 | ppallocator_join = "#{indent_str} cPPAllocator = PPAllocator_#{@shared_channel_cell}.ePPAllocator;\n"
|
---|
282 | else
|
---|
283 | ppallocator_join = ""
|
---|
284 | end
|
---|
285 |
|
---|
286 | # å
|
---|
287 | ±æãããéä¿¡ãã£ã³ãã«ã®çæã®ãããã¿ã¤ã宣è¨
|
---|
288 | file.print <<EOT
|
---|
289 | #{indent_str}cell #{@shared_channel_ct_name} #{@shared_channel_cell};
|
---|
290 | EOT
|
---|
291 |
|
---|
292 | # ããããåçµåãã¨ã®ã»ã«ãçæ
|
---|
293 |
|
---|
294 | # ã¢ãã±ã¼ã¿ã®æå®ããããï¼
|
---|
295 | if cell.get_allocator_list.length > 0 then
|
---|
296 |
|
---|
297 | file.print "#{indent_str}[allocator("
|
---|
298 |
|
---|
299 | delim = ""
|
---|
300 | cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
|
---|
301 |
|
---|
302 | file.print delim
|
---|
303 | delim = ",\n#{indent_str} " # æçµè¡ã«ã¯åºããªã
|
---|
304 |
|
---|
305 | if subsc then # é
|
---|
306 | åæ·»æ°
|
---|
307 | subsc_str = '[#{subsc}]'
|
---|
308 | else
|
---|
309 | subsc_str = ""
|
---|
310 | end
|
---|
311 |
|
---|
312 | eport = "eThroughEntry" #RPCã®åãå£åã«å¤æ´
|
---|
313 | file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc}"
|
---|
314 | end
|
---|
315 |
|
---|
316 | file.puts ")]"
|
---|
317 | end
|
---|
318 |
|
---|
319 | # ã»ã«æ¬ä½ã®çæ
|
---|
320 | file.print <<EOT
|
---|
321 | #{indent_str}cell #{@rpc_channel_celltype_name} #{@cell_name} {
|
---|
322 | #{indent_str} #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name};
|
---|
323 | #{indent_str} cTDR = #{@shared_channel_cell}.eTDR;
|
---|
324 | #{indent_str} cEventflag = #{@shared_channel_cell}.eEventflag;
|
---|
325 | #{indent_str} cLockChannel = #{@shared_channel_cell}.eSemaphore[#{@sub_channel_no}];
|
---|
326 | #{ppallocator_join}#{indent_str}};
|
---|
327 | EOT
|
---|
328 | @region.gen_region_str_post file
|
---|
329 | end
|
---|
330 |
|
---|
331 | #=== å¾ãã®ã³ã¼ããçæ
|
---|
332 | #ãã©ã°ã¤ã³ã®å¾ãã®ã³ã¼ããçæ
|
---|
333 | #file:: File:
|
---|
334 | def self.gen_post_code( file )
|
---|
335 | file.print "/* '#{self.name}' post code */\n"
|
---|
336 | @@shared_channel_list.each{ |chan_name,plugin_obj|
|
---|
337 | plugin_obj[0].gen_post_code( file, plugin_obj )
|
---|
338 | }
|
---|
339 | end
|
---|
340 |
|
---|
341 | #=== å¾ãã®ã³ã¼ããçæ
|
---|
342 | # plugin_obj[0] ã代表ãã¦åºåããï¼ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã«ã¢ã¯ã»ã¹ãããããï¼
|
---|
343 | def gen_post_code( file, plugin_obj )
|
---|
344 |
|
---|
345 | chan_name = @shared_channel_cell
|
---|
346 |
|
---|
347 | nest = @region.gen_region_str_pre file
|
---|
348 | indent_str = " " * nest
|
---|
349 |
|
---|
350 | # å
|
---|
351 | ±æããã¦ããéä¿¡ãã£ã³ãã«ã®çæ
|
---|
352 | # åãã©ã°ã¤ã³ã¤ã³ã¹ã¿ã³ã¹ã§ã¯ @shared_channel_ct_name ã¨ãã¦è¨æ¶ãã¦ãã
|
---|
353 | file.print "#{indent_str}cell tSharedRPCPlugin_#{@channelCelltype} #{chan_name} {\n"
|
---|
354 | plugin_obj.each{ |po|
|
---|
355 | file.print <<EOT
|
---|
356 | #{indent_str} cUnmarshalAndCallFunction[] = #{@cell_name}.eUnmarshalAndCallFunction;
|
---|
357 | EOT
|
---|
358 | }
|
---|
359 | file.printf "#{indent_str} priority = #{@task_priority};\n#{indent_str}};\n"
|
---|
360 | @region.gen_region_str_post file
|
---|
361 |
|
---|
362 | end
|
---|
363 |
|
---|
364 | end
|
---|
365 |
|
---|