Class: HRPRPCPlugin

Inherits:
ThroughPlugin show all
Includes:
GenOpaqueMarshaler, GenParamCopy
Defined in:
lib/tecsgen/plugin/HRPRPCPlugin.rb

Overview

HRPRPCPlugin プラグイン

スループラグイン (through) ・OpaqueMarshalerPlugin を使用してマーシャラセルタイプを生成する ・マーシャラ、TDR、チャンネル、メッセージバッファを生成する

Constant Summary collapse

HRPRPCPluginArgProc =

RPCPlugin 専用のオプション

RPCPluginArgProc.dup
@@isFirstInstance =
true

Constants included from GenOpaqueMarshaler

GenOpaqueMarshaler::RPCPluginArgProc

Constants inherited from Plugin

Plugin::PluginArgProc

Instance Method Summary collapse

Methods included from GenParamCopy

#print_nullable_post, #print_nullable_pre, #print_param, #print_param0

Methods included from GenOpaqueMarshaler

#alloc_for_out_param, #alloc_for_out_params, #check_PPAllocator, #check_opener_code, #dealloc_for_params, #gen_ep_func_body, #gen_ep_func_body_marshal, #gen_ep_func_body_unmarshal, #gen_marshaler_celltype, #gen_postamble, #gen_preamble, #get_cell_name, #initialize_opaque_marshaler, #optparse, #print_out_nullable, #print_params, #set_PPAllocatorSize, #set_TDRCelltype, #set_clientChannelCell, #set_clientChannelCelltype, #set_clientChannelInitializer, #set_clientErrorHandler, #set_clientSemaphoreCelltype, #set_clientSemaphoreInitializer, #set_noServerChannelOpenerCode, #set_serverChannelCell, #set_serverChannelCelltype, #set_serverChannelInitializer, #set_serverErrorHandler, #set_stackSize, #set_substituteAllocator, #set_taskCelltype, #set_taskPriority

Methods inherited from ThroughPlugin

#check_plugin_arg, #gen_cdl_file, #gen_ep_func_body, gen_post_code, #get_cell_name, #get_through_entry_port_name, #get_through_entry_port_subscript, #set_through_info, #show_tree, #subst_name

Methods inherited from Plugin

#cdl_error, #check_plugin_arg, #gen_cdl_file, #gen_ep_func?, #gen_postamble, #gen_preamble, #new_cell, #parse_plugin_arg, #print_msg, #set_locale, #set_silent

Methods inherited from Node

#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale

Constructor Details

#initialize(cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell) ⇒ HRPRPCPlugin

RPCPlugin の initialize

説明は ThroughPlugin (plugin.rb) を参照


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/tecsgen/plugin/HRPRPCPlugin.rb', line 59

def initialize(cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell)
  super
  @b_noClientSemaphore = false
  @semaphoreCelltype = "tSemaphore"
  initialize_opaque_marshaler

  # オプション:GenOpaqueMarshaler 参照
  @plugin_arg_check_proc_tab = HRPRPCPluginArgProc
  parse_plugin_arg

  @rpc_channel_celltype_name = "tRPCPlugin_#{@TDRCelltype}_#{@channelCelltype}_#{@signature.get_name}"
  @rpc_channel_celltype_file_name = "#{$gen}/#{@rpc_channel_celltype_name}.cdl"

  if @signature.get_context == "non-task"
    cdl_error("HRP9999 RPC cannot be applied to non-task context signature '$1'", @signature.get_name)
  elsif @signature.get_context == "any"
    cdl_info("HRP9999 RPC is applied to any context signature '$1'", @signature.get_name)
  end

  if @signature.need_PPAllocator?(true)
    if @PPAllocatorSize.nil?
      cdl_error("HRP9999 PPAllocatorSize must be speicified for pointer argments")
      # @PPAllocatorSize = 0   # 仮に 0 としておく (cdl の構文エラーを避けるため)
    end
  elsif @PPAllocatorSize
    cdl_warning("HRP9999 PPAllocatorSize speicified in spite of PPAllocator unnecessary")
    @PPAllocatorSize = nil
  end

#    @signature.each_param{ |func_decl, param_decl|
#      if func_decl.get_type.is_oneway? then
#        if ( param_decl.get_size || param_decl.get_count ) && param_decl.get_string then
#          cdl_error( "array of string not supported for oneway function in Transparent RPC" )  # mikan 文字列の配列
#        elsif param_decl.get_string == -1 then
#          cdl_error( "length unspecified string is not permited for oneway function in Transparent RPC" )  # mikan 長さ未指定文字列
#        end
#      end
#    }

  #
  #  tecsgen/tecs/rpcにincludeパスを通す
  #  #include "tecs_rpc.h" を実現するために必要
  #    大山:削除 Makefile.tecsgen に vpath, INCLUDES を入れるのは、よくない考え
  #             TECSGEN.add_search_path で Makefile_templ に入れるのがよい
  # if @@isFirstInstance
  #     f = AppFile.open( "#{$gen}/Makefile.tecsgen" )
  #     f.puts "INCLUDES := $(INCLUDES) -I $(TECSPATH) -I $(TECSPATH)/rpc"
  #     f.puts "vpath %.c $(TECSPATH) $(TECSPATH)/rpc"
  #     f.close()
  #     @@isFirstInstance = false
  # end
end

Instance Method Details

#gen_plugin_decl_code(file) ⇒ Object

plugin の宣言コード (celltype の定義) 生成



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/tecsgen/plugin/HRPRPCPlugin.rb', line 113

def gen_plugin_decl_code(file)
  ct_name = "#{@ct_name}_#{@channelCelltype}"

  # このセルタイプ(同じシグニチャ)は既に生成されているか?
  if @@generated_celltype[ct_name].nil?
    @@generated_celltype[ct_name] = [self]
  else
    @@generated_celltype[ct_name] << self
    return
  end

  f = CFile.open(@rpc_channel_celltype_file_name, "w")
  # 同じ内容を二度書く可能性あり (AppFile は不可)

  f.print <<EOT
import( <rpc.cdl> );
import( <tMessageBufferCEP.cdl> );
generate( OpaqueMarshalerPlugin, #{@signature.get_namespace_path}, "" );

composite tOpaqueMarshaler_#{@signature.get_global_name}_through {
entry #{@signature.get_namespace_path} eThroughEntry;
call sTDR       cTDR;
[optional]
  call sSemaphore cLockChannel;
[optional]
  call sRPCErrorHandler cErrorHandler;

cell tOpaqueMarshaler_#{@signature.get_global_name} Marshaler{
  cTDR          => composite.cTDR;
  cLockChannel  => composite.cLockChannel;
  cErrorHandler => composite.cErrorHandler;
};
composite.eThroughEntry => Marshaler.eClientEntry;
};

EOT

  f.close
end

#gen_through_cell_code(file) ⇒ Object

through cell コードを生成



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/tecsgen/plugin/HRPRPCPlugin.rb', line 156

def gen_through_cell_code(file)
  gen_plugin_decl_code(file)
  file.print <<EOT
import( <#{@rpc_channel_celltype_file_name}> );
EOT

  case @start_region.get_domain_root.get_domain_type.get_kind
  when :kernel
    tacp_str = "\"TACP_KERNEL"
  when :user
    tacp_str = "\"TACP(#{@start_region.get_domain_root.get_name})"
  when :OutOfDomain
    tacp_str = "\"TACP_SHARED"
  end
  # p "end_region=#{@end_region.get_name} kind=#{@end_region.get_domain_root.get_domain_type.get_kind}"
  case @end_region.get_domain_root.get_domain_type.get_kind
  when :kernel
    tacp_str += "|TACP_KERNEL\""
  when :user
    tacp_str += "|TACP(#{@end_region.get_domain_root.get_name})\""
  when :OutOfDomain
    tacp_str += "|TACP_SHARED\""
  end
  nest_str = ""
  file.print <<EOT
#{nest_str}  //  MessageBuffer client=>server
#{nest_str}  cell tMessageBuffer #{@clientChannelCell}Body0{
#{nest_str}      maxMessageSize = 64;      /* This value must be same as MessageBufferCEP's buffer size */
#{nest_str}      bufferSize     = 128;
#{nest_str}      accessPattern1 = C_EXP( #{tacp_str} );
#{nest_str}      accessPattern2 = C_EXP( #{tacp_str} );
#{nest_str}      accessPattern3 = C_EXP( #{tacp_str} );
#{nest_str}      accessPattern4 = C_EXP( #{tacp_str} );
#{nest_str}  };
EOT
  file.print <<EOT

#{nest_str}  //  MessageBuffer server=>client
#{nest_str}  cell tMessageBuffer #{@clientChannelCell}Body1{
#{nest_str}      maxMessageSize = 64;      /* This value must be same as MessageBufferCEP's buffer size */
#{nest_str}      bufferSize     = 128;
#{nest_str}      accessPattern1 = C_EXP( #{tacp_str} );
#{nest_str}      accessPattern2 = C_EXP( #{tacp_str} );
#{nest_str}      accessPattern3 = C_EXP( #{tacp_str} );
#{nest_str}      accessPattern4 = C_EXP( #{tacp_str} );
#{nest_str}  };
EOT

  ##### クライアント側のセルの生成 #####
  nest = @start_region.gen_region_str_pre file
  nest_str = "  " * nest

  # セマフォの生成
  if @b_noClientSemaphore == false
    file.print <<EOT
#{nest_str}  //  Semaphore for Multi-task use ("specify noClientSemaphore" option to delete this)
#{nest_str}  cell #{@semaphoreCelltype} #{@serverChannelCell}_Semaphore{
#{nest_str}    initialCount = 1;
#{nest_str}  };
EOT
  end

  # クライアント側チャンネル (tMessageBufferCEP)の生成
  # チャンネルは必ずリージョン下にあるので、 '::' でつなぐ (でなければ、ルートリージョンにないかチェックが必要)

  file.print <<EOT
#{nest_str}  //  Client Side Channel
#{nest_str}  cell tMessageBufferCEP #{@clientChannelCell}_CEP{
#{nest_str}      cMessageBuffer0 = #{@clientChannelCell}Body0.eMessageBuffer;
#{nest_str}      cMessageBuffer1 = #{@clientChannelCell}Body1.eMessageBuffer;
#{nest_str}  };

#{nest_str}  //  Client Side TDR
#{nest_str}  cell tTDR #{@clientChannelCell}_TDR{
#{nest_str}    cChannel = #{@clientChannelCell}_CEP.eChannel;
#{nest_str}  };

#{nest_str}  //  Marshaler
EOT

  # セマフォの結合文
  if @b_noClientSemaphore == false
    semaphore = "#{nest_str}    cLockChannel = #{@serverChannelCell}_Semaphore.eSemaphore;\n"
  else
    semaphore = ""
  end

  ### クライアント側チャンネル (マーシャラ+TDR)の生成 ###
  cell = @next_cell
  # アロケータの指定があるか?
  if cell.get_allocator_list.length > 0

    file.print nest_str
    file.print "[allocator("

    delim = ""
    cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|

      alloc_str = alloc.to_s
      subst = @substituteAllocator[alloc_str.to_sym]
      if subst
        alloc_str = subst[2] + "." + subst[3]
      end

      file.print delim
      delim = ",\n" # 最終行には出さない

      if subsc # 配列添数
        subsc_str = '[#{subsc}]'
      else
        subsc_str = ""
      end

      eport = "eThroughEntry" # RPCの受け口名に変更
      file.print nest_str
      file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc_str}"
    end

    file.puts ")]"
  end

  if @clientErrorHandler
    clientErrorHandler_str = "#{nest_str}    cErrorHandler = #{@clientErrorHandler};\n"
  else
    clientErrorHandler_str = ""
  end

  file.print <<EOT
#{nest_str}  cell tOpaqueMarshaler_#{@signature.get_global_name}_through #{@cell_name} {
#{nest_str}    cTDR = #{@clientChannelCell}_TDR.eTDR;
#{clientErrorHandler_str}#{semaphore}#{nest_str}  };
EOT
  ### END: クライアント側チャンネル (マーシャラ+TDR)の生成 ###
  @start_region.gen_region_str_post file
  file.print "\n\n"

  ##### サーバー側のセルの生成 #####
  nest = @end_region.gen_region_str_pre file
  nest_str = "  " * nest

  if @serverErrorHandler
    serverErrorHandler_str = "#{nest_str}    cErrorHandler = #{@serverErrorHandler};\n"
  else
    serverErrorHandler_str = ""
  end

  if @b_genOpener
    opener = "#{nest_str}    cOpener       = #{@serverChannelCell}.eOpener;\n"
  else
    opener = ""
  end

  # サーバー側チャンネル (tMessageBufferCEP)
  if @PPAllocatorSize
    alloc_cell = <<EOT

#{nest_str}  cell tPPAllocator #{@serverChannelCell}_PPAllocator {
#{nest_str}    heapSize = #{@PPAllocatorSize};
#{nest_str}  };
EOT
    alloc_call_port_join = "#{nest_str}    cPPAllocator = #{@serverChannelCell}_PPAllocator.ePPAllocator;\n"
  else
    alloc_cell = ""
    alloc_call_port_join = ""
  end

  file.print <<EOT
#{nest_str}  //  Server Side Channel
#{nest_str}  cell tMessageBufferCEP #{@serverChannelCell}_CEP{
#{nest_str}      cMessageBuffer0 = #{@clientChannelCell}Body1.eMessageBuffer;
#{nest_str}      cMessageBuffer1 = #{@clientChannelCell}Body0.eMessageBuffer;
#{nest_str}  };
EOT

  # サーバー側TDR
  file.print <<EOT

#{nest_str}  //  Server Side TDR
#{nest_str}  cell tTDR #{@serverChannelCell}_TDR{
#{nest_str}    cChannel = #{@serverChannelCell}_CEP.eChannel;
#{nest_str}  };
EOT

  if @next_cell_port_subscript
    subscript = "[" + @next_cell_port_subscript.to_s + "]"
  else
    subscript = ""
  end

  # サーバー側チャンネル (アンマーシャラ)
  file.print <<EOT
#{alloc_cell}
#{nest_str}  //  Unmarshaler
#{nest_str}  cell tOpaqueUnmarshaler_#{@signature.get_global_name} #{@serverChannelCell}_Unmarshaler {
#{nest_str}    cTDR        = #{@serverChannelCell}_TDR.eTDR;
#{nest_str}    cServerCall = #{@next_cell.get_namespace_path.get_path_str}.#{@next_cell_port_name}#{subscript};
#{alloc_call_port_join}#{serverErrorHandler_str}#{nest_str}  };
EOT

  # サーバー側タスクメイン
  file.print <<EOT

#{nest_str}  //  Unmarshaler Task Main
#{nest_str}  cell #{@taskMainCelltype} #{@serverChannelCell}_TaskMain {
#{nest_str}    cMain         = #{@serverChannelCell}_Unmarshaler.eService;
#{opener}#{nest_str}  };
EOT

  # サーバー側タスク
  file.print <<EOT

#{nest_str}  //  Unmarshaler Task
#{nest_str}  cell #{@taskCelltype} #{@serverChannelCell}_Task {
#{nest_str}    cTaskBody = #{@serverChannelCell}_TaskMain.eMain;
#{nest_str}    priority  = #{@taskPriority};
#{nest_str}    stackSize = #{@stackSize};
#{nest_str}    attribute = C_EXP( "TA_ACT" );  /* mikan : marshaler task starts at beginning */
#{nest_str}  };
EOT
  @end_region.gen_region_str_post file
end

#get_cell_namespace_pathObject

NamespacePath を得る

生成するセルの namespace path を生成する



402
403
404
405
406
# File 'lib/tecsgen/plugin/HRPRPCPlugin.rb', line 402

def get_cell_namespace_path
#    nsp = @region.get_namespace.get_namespace_path
  nsp = @start_region.get_namespace_path
  return nsp.append(@cell_name)
end

#set_noClientSemaphore(rhs) ⇒ Object

プラグイン引数 noClientSemaphore のチェック



379
380
381
382
383
384
385
386
387
388
# File 'lib/tecsgen/plugin/HRPRPCPlugin.rb', line 379

def set_noClientSemaphore(rhs)
  rhs = rhs.to_sym
  if rhs == :true
    @b_noClientSemaphore = true
  elsif rhs == :false
    @b_noClientSemaphore = false
  else
    cdl_error("RPCPlugin: specify true or false for noClientSemaphore")
  end
end

#set_semaphoreCelltype(rhs) ⇒ Object

プラグイン引数 semaphoreCelltype のチェック



391
392
393
394
395
396
397
398
# File 'lib/tecsgen/plugin/HRPRPCPlugin.rb', line 391

def set_semaphoreCelltype(rhs)
  @semaphoreCelltype = rhs.to_sym
  nsp = NamespacePath.analyze(@semaphoreCelltype.to_s)
  obj = Namespace.find(nsp)
  if !obj.instance_of?(Celltype) && !obj.instance_of?(CompositeCelltype)
    cdl_error("RPCPlugin: semaphoreCelltype '#{rhs}' not celltype or not defined")
  end
end