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: RPCPlugin.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 | #= Transparent RPC ãã©ã°ã¤ã³
|
---|
59 | # Transparent RPC ãã£ã³ãã«ãçæãã
|
---|
60 | # ãã©ã°ã¤ã³å¼æ°ã¯ä»¥ä¸ã® RPCPluginArgProc ãåç
|
---|
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 RPCPlugin < ThroughPlugin
|
---|
77 |
|
---|
78 | include GenTransparentMarshaler
|
---|
79 | include GenParamCopy
|
---|
80 |
|
---|
81 | # RPCPlugin å°ç¨ã®ãªãã·ã§ã³
|
---|
82 | TransparentRPCPluginArgProc = RPCPluginArgProc.dup # è¤è£½ãä½ã£ã¦å
|
---|
83 | ãå¤æ´ããªãããã«ãã
|
---|
84 | TransparentRPCPluginArgProc[ "noClientSemaphore" ] = Proc.new { |obj,rhs| obj.set_noClientSemaphore rhs }
|
---|
85 | TransparentRPCPluginArgProc[ "semaphoreCelltype" ] = Proc.new { |obj,rhs| obj.set_semaphoreCelltype rhs }
|
---|
86 |
|
---|
87 | #=== RPCPlugin ã® initialize
|
---|
88 | # 説æ㯠ThroughPlugin (plugin.rb) ãåç
|
---|
89 | §
|
---|
90 | def initialize( cell_name, plugin_arg, next_cell, next_cell_port_name, signature, celltype, caller_cell )
|
---|
91 | super
|
---|
92 | @b_noClientSemaphore = false
|
---|
93 | @semaphoreCelltype = "tSemaphore"
|
---|
94 | initialize_transparent_marshaler cell_name
|
---|
95 |
|
---|
96 | # ãªãã·ã§ã³ï¼GenTransparentMarshaler åç
|
---|
97 | §
|
---|
98 | @plugin_arg_check_proc_tab = TransparentRPCPluginArgProc
|
---|
99 | parse_plugin_arg
|
---|
100 |
|
---|
101 | @rpc_channel_celltype_name = "tRPCPlugin_#{@TDRCelltype}_#{@channelCelltype}_#{@signature.get_global_name}"
|
---|
102 | @rpc_channel_celltype_file_name = "#{$gen}/#{@rpc_channel_celltype_name}.cdl"
|
---|
103 |
|
---|
104 | if @signature.need_PPAllocator? then
|
---|
105 | if @PPAllocatorSize == nil then
|
---|
106 | cdl_error( "PPAllocatorSize must be speicified for oneway [in] array" )
|
---|
107 | # @PPAllocatorSize = 0 # 仮㫠0 ã¨ãã¦ãã (cdl ã®æ§æã¨ã©ã¼ãé¿ãããã)
|
---|
108 | end
|
---|
109 | end
|
---|
110 |
|
---|
111 | # @signature.each_param{ |func_decl, param_decl|
|
---|
112 | # if func_decl.get_type.is_oneway? then
|
---|
113 | # if ( param_decl.get_size || param_decl.get_count ) && param_decl.get_string then
|
---|
114 | # cdl_error( "array of string not supported for oneway function in Transparent RPC" ) # mikan æååã®é
|
---|
115 | å
|
---|
116 | # elsif param_decl.get_string == -1 then
|
---|
117 | # cdl_error( "length unspecified string is not permited for oneway function in Transparent RPC" ) # mikan é·ãæªæå®æåå
|
---|
118 | # end
|
---|
119 | # end
|
---|
120 | # }
|
---|
121 | end
|
---|
122 |
|
---|
123 | #=== plugin ã®å®£è¨ã³ã¼ã (celltype ã®å®ç¾©) çæ
|
---|
124 | def gen_plugin_decl_code( file )
|
---|
125 |
|
---|
126 | ct_name = "#{@ct_name}_#{@channelCelltype}"
|
---|
127 |
|
---|
128 | # ãã®ã»ã«ã¿ã¤ãï¼åãã·ã°ããã£ï¼ã¯æ¢ã«çæããã¦ãããï¼
|
---|
129 | if @@generated_celltype[ ct_name ] == nil then
|
---|
130 | @@generated_celltype[ ct_name ] = [ self ]
|
---|
131 | else
|
---|
132 | @@generated_celltype[ ct_name ] << self
|
---|
133 | return
|
---|
134 | end
|
---|
135 |
|
---|
136 | gen_marshaler_celltype
|
---|
137 |
|
---|
138 | if @PPAllocatorSize then
|
---|
139 | alloc_cell = " cell tPPAllocator PPAllocator {\n heapSize = #{@PPAllocatorSize};\n };\n"
|
---|
140 | alloc_call_port_join = " cPPAllocator = PPAllocator.ePPAllocator;\n"
|
---|
141 | else
|
---|
142 | alloc_cell = ""
|
---|
143 | alloc_call_port_join = ""
|
---|
144 | end
|
---|
145 |
|
---|
146 | if @b_noClientSemaphore == false then
|
---|
147 | semaphore1 = <<EOT
|
---|
148 | // Semaphore for Multi-task use ("specify noClientSemaphore" option to delete this)
|
---|
149 | cell #{@semaphoreCelltype} Semaphore {
|
---|
150 | count = 1;
|
---|
151 | attribute = C_EXP( "TA_NULL" );
|
---|
152 | };
|
---|
153 | EOT
|
---|
154 | semaphore2 = " cLockChannel = Semaphore.eSemaphore;\n"
|
---|
155 | else
|
---|
156 | semaphore1 = ""
|
---|
157 | semaphore2 = ""
|
---|
158 | end
|
---|
159 |
|
---|
160 | f = CFile.open( @rpc_channel_celltype_file_name, "w" )
|
---|
161 | # åãå
|
---|
162 | 容ãäºåº¦æ¸ãå¯è½æ§ãã (AppFile ã¯ä¸å¯)
|
---|
163 |
|
---|
164 | f.print <<EOT
|
---|
165 | import( "#{@marshaler_celltype_file_name}" );
|
---|
166 |
|
---|
167 | [active]
|
---|
168 | composite #{@rpc_channel_celltype_name} {
|
---|
169 | /* Interface */
|
---|
170 | attr {
|
---|
171 | PRI taskPriority;
|
---|
172 | };
|
---|
173 | call #{@signature.get_namespace_path} #{@call_port_name};
|
---|
174 | entry #{@signature.get_namespace_path} eThroughEntry;
|
---|
175 | call sTDR cTDR;
|
---|
176 | call sEventflag cEventflag;
|
---|
177 |
|
---|
178 | /* Implementation */
|
---|
179 | #{semaphore1}
|
---|
180 | cell #{@marshaler_celltype_name} #{@signature.get_global_name}_marshaler{
|
---|
181 | cTDR => composite.cTDR;
|
---|
182 | cEventflag => composite.cEventflag;
|
---|
183 | #{semaphore2} };
|
---|
184 | #{alloc_cell} cell #{@unmarshaler_celltype_name} #{@signature.get_global_name}_unmarshaler{
|
---|
185 | cTDR => composite.cTDR;
|
---|
186 | cEventflag => composite.cEventflag;
|
---|
187 | cServerCall => composite.#{@call_port_name};
|
---|
188 | #{alloc_call_port_join} };
|
---|
189 | cell tRPCDedicatedTaskMain RPCTaskMain{
|
---|
190 | cMain = #{@signature.get_global_name}_unmarshaler.eUnmarshalAndCallFunction;
|
---|
191 | };
|
---|
192 | cell tTask Task {
|
---|
193 | cBody = RPCTaskMain.eMain;
|
---|
194 | priority = taskPriority;
|
---|
195 | taskAttribute = C_EXP( "TA_ACT" ); /* mikan : marshaler starts at the beginning */
|
---|
196 | stackSize = 4096;
|
---|
197 | };
|
---|
198 | composite.eThroughEntry => #{@signature.get_global_name}_marshaler.eClientEntry;
|
---|
199 | };
|
---|
200 | EOT
|
---|
201 | # mikan stackSize option & ææ° tecs_package 対å¿
|
---|
202 |
|
---|
203 | f.close
|
---|
204 | end
|
---|
205 |
|
---|
206 | #=== through cell ã³ã¼ããçæ
|
---|
207 | #
|
---|
208 | #
|
---|
209 | def gen_through_cell_code( file )
|
---|
210 |
|
---|
211 | gen_plugin_decl_code( file )
|
---|
212 |
|
---|
213 | # ã»ã«ãæ¢ã
|
---|
214 | # path =["::",@next_cell.get_global_name]
|
---|
215 | # cell = Namespace.find( path )
|
---|
216 | cell = Namespace.find( @next_cell.get_namespace_path )
|
---|
217 |
|
---|
218 | file.print <<EOT
|
---|
219 | import( "#{@rpc_channel_celltype_file_name}" );
|
---|
220 |
|
---|
221 | EOT
|
---|
222 |
|
---|
223 | nest = @region.gen_region_str_pre file
|
---|
224 | indent_str = " " * nest
|
---|
225 |
|
---|
226 | file.print <<EOT
|
---|
227 | #{indent_str}// ä¸æ¹åãã£ã³ãã«ã»ã«
|
---|
228 | #{indent_str}cell #{@channelCelltype} #{@channelCellName} {
|
---|
229 | #{indent_str}};
|
---|
230 |
|
---|
231 | #{indent_str}// RPC ãã£ã³ãã«ã»ã«
|
---|
232 | EOT
|
---|
233 |
|
---|
234 | # #473 ã解決ãããå ´åãcomposite ãªã¬ã¼ã¢ãã±ã¼ã¿ã«å¤æ´ãã¹ã
|
---|
235 | # ã¢ãã±ã¼ã¿ã®æå®ããããï¼
|
---|
236 | if cell.get_allocator_list.length > 0 then
|
---|
237 |
|
---|
238 | file.print "#{indent_str}[allocator("
|
---|
239 |
|
---|
240 | delim = ""
|
---|
241 | cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
|
---|
242 |
|
---|
243 | file.print delim
|
---|
244 | delim = ",\n#{indent_str} " # æçµè¡ã«ã¯åºããªã
|
---|
245 |
|
---|
246 | if subsc then # é
|
---|
247 | åæ·»æ°
|
---|
248 | subsc_str = '[#{subsc}]'
|
---|
249 | else
|
---|
250 | subsc_str = ""
|
---|
251 | end
|
---|
252 |
|
---|
253 | eport = "eThroughEntry" #RPCã®åãå£åã«å¤æ´
|
---|
254 | file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc}"
|
---|
255 | end
|
---|
256 |
|
---|
257 | file.puts ")]"
|
---|
258 | end
|
---|
259 |
|
---|
260 | file.print <<EOT
|
---|
261 | #{indent_str}cell #{@rpc_channel_celltype_name} #{@cell_name} {
|
---|
262 | #{indent_str} #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name};
|
---|
263 | #{indent_str} cTDR = #{@channelCellName}.eTDR;
|
---|
264 | #{indent_str} cEventflag = #{@channelCellName}.eEventflag;
|
---|
265 | #{indent_str} taskPriority = #{@task_priority};
|
---|
266 | #{indent_str}};
|
---|
267 | EOT
|
---|
268 | @region.gen_region_str_post file
|
---|
269 | end
|
---|
270 |
|
---|
271 |
|
---|
272 | #=== ãã©ã°ã¤ã³å¼æ° noClientSemaphore ã®ãã§ãã¯
|
---|
273 | def set_noClientSemaphore rhs
|
---|
274 | rhs = rhs.to_sym
|
---|
275 | if rhs == :true then
|
---|
276 | @b_noClientSemaphore = true
|
---|
277 | elsif rhs == :false then
|
---|
278 | @b_noClientSemaphore = false
|
---|
279 | else
|
---|
280 | cdl_error( "RPCPlugin: specify true or false for noClientSemaphore" )
|
---|
281 | end
|
---|
282 | end
|
---|
283 |
|
---|
284 | #=== ãã©ã°ã¤ã³å¼æ° semaphoreCelltype ã®ãã§ãã¯
|
---|
285 | def set_semaphoreCelltype rhs
|
---|
286 | @semaphoreCelltype = rhs.to_sym
|
---|
287 | nsp = NamespacePath.analyze( @semaphoreCelltype.to_s )
|
---|
288 | obj = Namespace.find( nsp )
|
---|
289 | if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
|
---|
290 | cdl_error( "RPCPlugin: semaphoreCelltype '#{rhs}' not celltype or not defined" )
|
---|
291 | end
|
---|
292 | end
|
---|
293 | end
|
---|
294 |
|
---|
295 |
|
---|