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