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 |
|
---|
55 | # 以ä¸ãä»®å®ï¼å¶éäºé
|
---|
56 | ï¼
|
---|
57 | # å¼ã³å
|
---|
58 | ãå¼ã³å
|
---|
59 | ã®ã¨ã³ãã£ã¢ã³ãchar, short, int_t, long_t, intptr_t ã®ãµã¤ãºãåã
|
---|
60 | # æ符å·ãç¡ç¬¦å·ã§ãµã¤ãºãåã
|
---|
61 |
|
---|
62 | require_tecsgen_lib "lib/GenOpaqueMarshaler.rb"
|
---|
63 | require_tecsgen_lib "lib/GenParamCopy.rb"
|
---|
64 |
|
---|
65 | class OpaqueRPCPlugin < ThroughPlugin
|
---|
66 |
|
---|
67 | include GenOpaqueMarshaler
|
---|
68 | include GenParamCopy
|
---|
69 |
|
---|
70 | # OpaqueRPCPlugin å°ç¨ã®ãªãã·ã§ã³
|
---|
71 | OpaqueRPCPluginArgProc = RPCPluginArgProc.dup # è¤è£½ãä½ã£ã¦å
|
---|
72 | ãå¤æ´ããªãããã«ãã
|
---|
73 | OpaqueRPCPluginArgProc[ "noClientSemaphore" ] = Proc.new { |obj,rhs| obj.set_noClientSemaphore rhs }
|
---|
74 |
|
---|
75 | #=== RPCPlugin ã® initialize
|
---|
76 | # 説æ㯠ThroughPlugin (plugin.rb) ãåç
|
---|
77 | §
|
---|
78 | def initialize( cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell )
|
---|
79 | super
|
---|
80 | @b_noClientSemaphore = false
|
---|
81 | initialize_opaque_marshaler
|
---|
82 |
|
---|
83 | @plugin_arg_check_proc_tab = OpaqueRPCPluginArgProc
|
---|
84 | parse_plugin_arg
|
---|
85 | check_opener_code
|
---|
86 | check_PPAllocator
|
---|
87 |
|
---|
88 | print "OpaqueRPCPlugin: #{@clientChannelCell}\n"
|
---|
89 |
|
---|
90 | @rpc_server_channel_celltype_name = "tOpaqueRPCPlugin_#{@TDRCelltype}_#{@serverChannelCelltype}_#{@signature.get_global_name}"
|
---|
91 | @rpc_server_channel_celltype_file_name = "#{$gen}/#{@rpc_server_channel_celltype_name}.cdl"
|
---|
92 | @rpc_client_channel_celltype_name = "tOpaqueRPCPlugin_#{@TDRCelltype}_#{@clientChannelCelltype}_#{@signature.get_global_name}"
|
---|
93 | @rpc_client_channel_celltype_file_name = "#{$gen}/#{@rpc_client_channel_celltype_name}.cdl"
|
---|
94 | end
|
---|
95 |
|
---|
96 | def gen_plugin_decl_code( file )
|
---|
97 |
|
---|
98 | gen_marshaler_celltype
|
---|
99 |
|
---|
100 | # ãã£ã³ãã« composite ã»ã«ã¿ã¤ãã®çæ
|
---|
101 | # ããã§çæããã CDL ãã¡ã¤ã«ã¯ãtecsgen ãç´æ¥ import ããã®ã§ã¯ãªã
|
---|
102 | # ã»ã«ã³ã¼ãã® CDL ãã import ããã
|
---|
103 |
|
---|
104 | f = CFile.open( @rpc_client_channel_celltype_file_name, "w" )
|
---|
105 | # åãå
|
---|
106 | 容ãäºåº¦æ¸ãå¯è½æ§ãã (AppFile ã¯ä¸å¯)
|
---|
107 |
|
---|
108 | f.print <<EOT
|
---|
109 | import( "#{@marshaler_celltype_file_name}" );
|
---|
110 |
|
---|
111 | /* RPC Client side composite celltype */
|
---|
112 | composite #{@rpc_client_channel_celltype_name} {
|
---|
113 | /* marshaler entry port */
|
---|
114 | entry #{@signature.get_namespace_path} eThroughEntry;
|
---|
115 | call sChannel cChannel;
|
---|
116 | [optional]
|
---|
117 | call sRPCErrorHandler cErrorHandler;
|
---|
118 | [optional]
|
---|
119 | call sSemaphore cLockChannel;
|
---|
120 |
|
---|
121 | cell #{@TDRCelltype} TDR {
|
---|
122 | cChannel => composite.cChannel;
|
---|
123 | };
|
---|
124 | cell #{@marshaler_celltype_name} Marshaler{
|
---|
125 | cTDR = TDR.eTDR;
|
---|
126 | cErrorHandler => composite.cErrorHandler;
|
---|
127 | cLockChannel => composite.cLockChannel;
|
---|
128 | };
|
---|
129 |
|
---|
130 | composite.eThroughEntry => Marshaler.eClientEntry;
|
---|
131 | };
|
---|
132 | EOT
|
---|
133 | f.close
|
---|
134 |
|
---|
135 | if @PPAllocatorSize then
|
---|
136 | alloc_cell = " cell tPPAllocator PPAllocator {\n heapSize = #{@PPAllocatorSize};\n };\n"
|
---|
137 | alloc_call_port_join = " cPPAllocator = PPAllocator.ePPAllocator;\n"
|
---|
138 | else
|
---|
139 | alloc_cell = ""
|
---|
140 | alloc_call_port_join = ""
|
---|
141 | end
|
---|
142 |
|
---|
143 | f = CFile.open( @rpc_server_channel_celltype_file_name, "w" )
|
---|
144 | # åãå
|
---|
145 | 容ãäºåº¦æ¸ãå¯è½æ§ãã (AppFile ã¯ä¸å¯)
|
---|
146 |
|
---|
147 | f.print <<EOT
|
---|
148 | import( "#{@marshaler_celltype_file_name}" );
|
---|
149 |
|
---|
150 | /* RPC Server side composite celltype */
|
---|
151 | composite #{@rpc_server_channel_celltype_name} {
|
---|
152 | /* Interface */
|
---|
153 | call #{@signature.get_namespace_path} #{@call_port_name};
|
---|
154 | call sChannel cChannel;
|
---|
155 | [optional]
|
---|
156 | call sRPCErrorHandler cErrorHandler;
|
---|
157 | entry sUnmarshalerMain eService;
|
---|
158 |
|
---|
159 | /* Implementation */
|
---|
160 | cell #{@TDRCelltype} TDR {
|
---|
161 | cChannel => composite.cChannel;
|
---|
162 | };
|
---|
163 | #{alloc_cell} cell #{@unmarshaler_celltype_name} Unmarshaler{
|
---|
164 | cTDR = TDR.eTDR;
|
---|
165 | cErrorHandler => composite.cErrorHandler;
|
---|
166 | cServerCall => composite.#{@call_port_name};
|
---|
167 | #{alloc_call_port_join} };
|
---|
168 | composite.eService => Unmarshaler.eService;
|
---|
169 | };
|
---|
170 | EOT
|
---|
171 |
|
---|
172 | f.close
|
---|
173 | end
|
---|
174 |
|
---|
175 | #=== through cell ã³ã¼ããçæ
|
---|
176 | #
|
---|
177 | #
|
---|
178 | def gen_through_cell_code( file )
|
---|
179 |
|
---|
180 | gen_plugin_decl_code( file )
|
---|
181 |
|
---|
182 | # ã»ã«ãæ¢ã
|
---|
183 | # path =["::",@next_cell.get_name] # mikan namespace
|
---|
184 | # cell = Namespace.find( path )
|
---|
185 | cell = Namespace.find( @next_cell.get_namespace_path )
|
---|
186 |
|
---|
187 | file.print <<EOT
|
---|
188 | import( "#{@rpc_client_channel_celltype_file_name}" );
|
---|
189 | import( "#{@rpc_server_channel_celltype_file_name}" );
|
---|
190 |
|
---|
191 | EOT
|
---|
192 |
|
---|
193 | ##### ã¯ã©ã¤ã¢ã³ãå´ã®ã»ã«ã®çæ #####
|
---|
194 | nest = @start_region.gen_region_str_pre file
|
---|
195 | nest_str = " " * nest
|
---|
196 |
|
---|
197 | # ã»ããã©ã®çæ
|
---|
198 | if @b_noClientSemaphore == false then
|
---|
199 | file.print <<EOT
|
---|
200 |
|
---|
201 | #{nest_str} // Semaphore for Multi-task use ("specify noClientSemaphore" option to delete this)
|
---|
202 | #{nest_str} cell #{@semaphoreCelltype} #{@serverChannelCell}_Semaphore{
|
---|
203 | #{nest_str} #{@semaphoreInitializer}
|
---|
204 | #{nest_str} };
|
---|
205 | EOT
|
---|
206 | end
|
---|
207 |
|
---|
208 | # ã¯ã©ã¤ã¢ã³ãå´ãã£ã³ãã« (TINET, Socket ãªã©)ã®çæ
|
---|
209 | file.print <<EOT
|
---|
210 | #{nest_str} // Client Side Channel
|
---|
211 | #{nest_str} cell #{@clientChannelCelltype} #{@clientChannelCell}{
|
---|
212 | #{nest_str} #{@clientChannelInitializer}
|
---|
213 | #{nest_str} };
|
---|
214 |
|
---|
215 | #{nest_str} // Marshaler
|
---|
216 | EOT
|
---|
217 |
|
---|
218 | # ã»ããã©ã®çµåæ
|
---|
219 | if @b_noClientSemaphore == false then
|
---|
220 | semaphore = "#{nest_str} cLockChannel = #{@serverChannelCell}_Semaphore.eSemaphore;\n"
|
---|
221 | else
|
---|
222 | semaphore = ""
|
---|
223 | end
|
---|
224 |
|
---|
225 | ### ã¯ã©ã¤ã¢ã³ãå´ãã£ã³ãã« (ãã¼ã·ã£ã©+TDR)ã®çæ ###
|
---|
226 | # ã¢ãã±ã¼ã¿ã®æå®ããããï¼
|
---|
227 | if cell.get_allocator_list.length > 0 then
|
---|
228 |
|
---|
229 | file.print nest_str
|
---|
230 | file.print "[allocator("
|
---|
231 |
|
---|
232 | delim = ""
|
---|
233 | cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
|
---|
234 |
|
---|
235 | alloc_str = alloc.to_s
|
---|
236 | subst = @substituteAllocator[alloc_str.to_sym]
|
---|
237 | if subst then
|
---|
238 | alloc_str = subst[2]+"."+subst[3]
|
---|
239 | end
|
---|
240 |
|
---|
241 | file.print delim
|
---|
242 | delim = ",\n" # æçµè¡ã«ã¯åºããªã
|
---|
243 |
|
---|
244 | if subsc then # é
|
---|
245 | åæ·»æ°
|
---|
246 | subsc_str = '[#{subsc}]'
|
---|
247 | else
|
---|
248 | subsc_str = ""
|
---|
249 | end
|
---|
250 |
|
---|
251 | eport = "eThroughEntry" #RPCã®åãå£åã«å¤æ´
|
---|
252 | file.print nest_str
|
---|
253 | file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc_str}"
|
---|
254 | end
|
---|
255 |
|
---|
256 | file.puts ")]"
|
---|
257 | end
|
---|
258 |
|
---|
259 | if @clientErrorHandler then
|
---|
260 | clientErrorHandler_str = "#{nest_str} cErrorHandler = #{@clientErrorHandler};\n"
|
---|
261 | else
|
---|
262 | clientErrorHandler_str = ""
|
---|
263 | end
|
---|
264 |
|
---|
265 | file.print <<EOT
|
---|
266 | #{nest_str} cell #{@rpc_client_channel_celltype_name} #{@cell_name} {
|
---|
267 | #{nest_str} cChannel = #{@clientChannelCell}.eC0;
|
---|
268 | #{clientErrorHandler_str}#{semaphore}#{nest_str} };
|
---|
269 |
|
---|
270 | EOT
|
---|
271 | ### END: ã¯ã©ã¤ã¢ã³ãå´ãã£ã³ãã« (ãã¼ã·ã£ã©+TDR)ã®çæ ###
|
---|
272 |
|
---|
273 | @start_region.gen_region_str_post file
|
---|
274 | file.print "\n\n"
|
---|
275 |
|
---|
276 | ##### ãµã¼ãã¼å´ã®ã»ã«ã®çæ #####
|
---|
277 | nest = @end_region.gen_region_str_pre file
|
---|
278 | nest_str = " " * nest
|
---|
279 | if @next_cell_port_subscript then
|
---|
280 | subscript = '[' + @next_cell_port_subscript.to_s + ']'
|
---|
281 | else
|
---|
282 | subscript = ""
|
---|
283 | end
|
---|
284 |
|
---|
285 | if @serverErrorHandler then
|
---|
286 | serverErrorHandler_str = "#{nest_str} cErrorHandler = #{@serverErrorHandler};\n"
|
---|
287 | else
|
---|
288 | serverErrorHandler_str = ""
|
---|
289 | end
|
---|
290 |
|
---|
291 | if @b_genOpener then
|
---|
292 | opener = "#{nest_str} cOpener = #{@serverChannelCell}.eOpener;\n"
|
---|
293 | else
|
---|
294 | opener = ""
|
---|
295 | end
|
---|
296 |
|
---|
297 | # ãµã¼ãã¼å´ãã£ã³ãã« (TINET, Socket ãªã©)
|
---|
298 | file.print <<EOT
|
---|
299 |
|
---|
300 | #{nest_str} // Server Side Channel
|
---|
301 | #{nest_str} cell #{@serverChannelCelltype} #{@serverChannelCell}{
|
---|
302 | #{nest_str} #{@serverChannelInitializer}
|
---|
303 | #{nest_str} };
|
---|
304 | EOT
|
---|
305 |
|
---|
306 | # ãµã¼ãã¼å´ãã£ã³ãã« (ã¢ã³ãã¼ã·ã£ã©+TDR)
|
---|
307 | file.print <<EOT
|
---|
308 |
|
---|
309 | #{nest_str} // Unmarshaler
|
---|
310 | #{nest_str} cell #{@rpc_server_channel_celltype_name} #{@serverChannelCell}_Unmarshaler {
|
---|
311 | #{nest_str} cChannel = #{@serverChannelCell}.eC1;
|
---|
312 | #{nest_str} #{@call_port_name} = #{@next_cell.get_namespace_path.get_path_str}.#{@next_cell_port_name}#{subscript};
|
---|
313 | #{serverErrorHandler_str}#{nest_str} };
|
---|
314 | EOT
|
---|
315 |
|
---|
316 | # ãµã¼ãã¼å´ã¿ã¹ã¯ã¡ã¤ã³
|
---|
317 | file.print <<EOT
|
---|
318 |
|
---|
319 | #{nest_str} // Unmarshaler Task Main
|
---|
320 | #{nest_str} cell #{@taskMainCelltype} #{@serverChannelCell}_TaskMain {
|
---|
321 | #{nest_str} cMain = #{@serverChannelCell}_Unmarshaler.eService;
|
---|
322 | #{opener}#{nest_str} };
|
---|
323 | EOT
|
---|
324 |
|
---|
325 | # ãµã¼ãã¼å´ã¿ã¹ã¯
|
---|
326 | file.print <<EOT
|
---|
327 |
|
---|
328 | #{nest_str} // Unmarshaler Task
|
---|
329 | #{nest_str} cell #{@taskCelltype} #{@serverChannelCell}_Task {
|
---|
330 | #{nest_str} cBody = #{@serverChannelCell}_TaskMain.eMain;
|
---|
331 | #{nest_str} priority = #{@taskPriority};
|
---|
332 | #{nest_str} stackSize = #{@stackSize};
|
---|
333 | #{nest_str} taskAttribute = C_EXP( "TA_ACT" ); /* mikan : marshaler task starts at beginning */
|
---|
334 | #{nest_str} };
|
---|
335 | EOT
|
---|
336 | @end_region.gen_region_str_post file
|
---|
337 | end
|
---|
338 |
|
---|
339 | #=== ãã©ã°ã¤ã³å¼æ° noClientSemaphore ã®ãã§ãã¯
|
---|
340 | def set_noClientSemaphore rhs
|
---|
341 | rhs = rhs.to_sym
|
---|
342 | if rhs == :true then
|
---|
343 | @b_noClientSemaphore = true
|
---|
344 | elsif rhs == :false then
|
---|
345 | @b_noClientSemaphore = false
|
---|
346 | else
|
---|
347 | cdl_error( "RPCPlugin: specify true or false for noClientSemaphore" )
|
---|
348 | end
|
---|
349 | end
|
---|
350 | end
|
---|
351 |
|
---|
352 |
|
---|