Class: HRP2RPCPlugin

Inherits:
ThroughPlugin show all
Includes:
GenTransparentMarshaler
Defined in:
lib/tecsgen/plugin/HRP2RPCPlugin.rb

Overview

RPCを用いたドメイン間通信のthroughプラグインHRP2ドメインプラグインによって挿入される

Constant Summary collapse

TransparentRPCPluginArgProc =

RPCPlugin 専用のオプション

RPCPluginArgProc.dup

Constants included from GenTransparentMarshaler

GenTransparentMarshaler::RPCPluginArgProc

Constants inherited from Plugin

Plugin::PluginArgProc

Instance Method Summary collapse

Methods included from GenTransparentMarshaler

#gen_ep_func_body, #gen_ep_func_body_marshal, #gen_ep_func_body_unmarshal, #gen_marshaler_celltype, #gen_postamble, #gen_preamble, #initialize_transparent_marshaler, #print_param_nc, #print_params, #set_PPAllocatorSize, #set_TDRCelltype, #set_channelCellName, #set_channelCelltype, #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) ⇒ HRP2RPCPlugin

RPCPlugin の initialize

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


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
# File 'lib/tecsgen/plugin/HRP2RPCPlugin.rb', line 71

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_transparent_marshaler cell_name

  # オプション:GenTransparentMarshaler 参照
  @plugin_arg_check_proc_tab = TransparentRPCPluginArgProc
  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.need_PPAllocator?
    if @PPAllocatorSize.nil?
      cdl_error("PPAllocatorSize must be speicified for oneway [in] array")
      # @PPAllocatorSize = 0   # 仮に 0 としておく (cdl の構文エラーを避けるため)
    end
  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
#    }
end

Instance Method Details

#gen_plugin_decl_code(file) ⇒ Object

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



103
104
105
106
107
108
109
110
111
112
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
152
153
154
155
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
# File 'lib/tecsgen/plugin/HRP2RPCPlugin.rb', line 103

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

  gen_marshaler_celltype

  if @PPAllocatorSize
    alloc_cell = "  cell tPPAllocator PPAllocator {\n    heapSize = #{@PPAllocatorSize};\n  };\n"
    alloc_call_port_join = "    cPPAllocator = PPAllocator.ePPAllocator;\n"
  else
    alloc_cell = ""
    alloc_call_port_join = ""
  end

  if @b_noClientSemaphore == false
    semaphore1 = <<EOT
// Semaphore for Multi-task use ("specify noClientSemaphore" option to delete this)
cell #{@semaphoreCelltype} Semaphore {
  count = 1;
  attribute = C_EXP( "TA_NULL" );
};
EOT
    semaphore2 = "    cLockChannel = Semaphore.eSemaphore;\n"
  else
    semaphore1 = ""
    semaphore2 = ""
  end

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

  f.print <<EOT
import( "#{@marshaler_celltype_file_name}" );

composite #{@rpc_channel_celltype_name}Client {
/* Interface */
entry #{@signature.get_name} eThroughEntry;
//call sTDR       cTDR;
call sEventflag cEventflag;
call sSemaphore cSemaphore;
call sMessageBuffer cMessageBuffer;

/* Implementation */
#{semaphore1}
cell #{@marshaler_celltype_name} #{@signature.get_name}_marshaler{
  //cTDR         => composite.cTDR;
  cEventflag   => composite.cEventflag;
  cSemaphore   => composite.cSemaphore;
  cMessageBuffer => composite.cMessageBuffer;
#{semaphore2}  };
composite.eThroughEntry => #{@signature.get_name}_marshaler.eClientEntry;
};

[active]
composite #{@rpc_channel_celltype_name}Server {
/* Interface */
attr {
  PRI taskPriority;
};
call #{@signature.get_name} #{@call_port_name};
//call sTDR       cTDR;
call sEventflag cEventflag;
call sSemaphore cSemaphore;
call sMessageBuffer cMessageBuffer;

/* Implementation */
#{alloc_cell}  cell #{@unmarshaler_celltype_name} #{@signature.get_name}_unmarshaler{
  //cTDR        => composite.cTDR;
  cEventflag  => composite.cEventflag;
  cSemaphore  => composite.cSemaphore;
  cMessageBuffer => composite.cMessageBuffer;
  cServerCall => composite.#{@call_port_name};
#{alloc_call_port_join}  };
cell tRPCDedicatedTaskMain RPCTaskMain{
  cMain = #{@signature.get_name}_unmarshaler.eUnmarshalAndCallFunction;
};
cell tTask Task {
  cBody     = RPCTaskMain.eMain;
  priority  = taskPriority;
  taskAttribute = C_EXP( "TA_ACT" );  /* mikan : marshaler starts at the beginning */
  //stackSize     = 4096;
  userStackSize     = 4096;
};
};
EOT
  # mikan stackSize option & 最新 tecs_package 対応

  f.close
end

#gen_through_cell_code(file) ⇒ Object

through cell コードを生成



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
# File 'lib/tecsgen/plugin/HRP2RPCPlugin.rb', line 203

def gen_through_cell_code(file)
  gen_plugin_decl_code(file)

  # セルを探す
  # path =["::",@next_cell.get_name]
  # cell = Namespace.find( path )
  cell = Namespace.find(@next_cell.get_namespace_path)

  file.print <<EOT
import( "#{@rpc_channel_celltype_file_name}" );
EOT

  # nest = @end_region.gen_region_str_pre file
  indent_str = ""

  file.print <<EOT
#{indent_str}// one way channel cell
#{indent_str}cell #{@channelCelltype} #{@channelCellName} {
#{indent_str}};

#{indent_str}// RPC channel cell
EOT

  nest = @start_region.gen_region_str_pre file
  indent_str = "  " * nest

  # #473 が解決された場合、composite リレーアロケータに変更すべき
  # アロケータの指定があるか?
  if cell.get_allocator_list.length > 0

    dbgPrint "make allocator\n"
    file.print "#{indent_str}[allocator("

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

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

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

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

    file.puts ")]"
  end

  file.print <<EOT
#{indent_str}cell #{@rpc_channel_celltype_name}Client #{@cell_name} {
#{indent_str}  //cTDR         = #{@channelCellName}.eTDR;
#{indent_str}  cEventflag   = #{@channelCellName}.eEventflag;
#{indent_str}  cSemaphore   = #{@channelCellName}.eSemaphore;
#{indent_str}  cMessageBuffer   = #{@channelCellName}.eMessageBuffer;
#{indent_str}};
EOT

  @start_region.gen_region_str_post file

  nest = @end_region.gen_region_str_pre file
  indent_str = "  " * nest
  nest_str = "  " * nest
  if @next_cell_port_subscript
    subscript = "[" + @next_cell_port_subscript.to_s + "]"
  else
    subscript = ""
  end

  file.print <<EOT
#{indent_str}cell #{@rpc_channel_celltype_name}Server #{@cell_name}Body {
#{indent_str}    #{@call_port_name} = #{@next_cell.get_namespace_path.get_path_str}.#{@next_cell_port_name}#{subscript};
//#{indent_str}    #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name};
#{indent_str}  //cTDR         = #{@channelCellName}.eTDR;
#{indent_str}  cEventflag   = #{@channelCellName}.eEventflag;
#{indent_str}  cSemaphore   = #{@channelCellName}.eSemaphore;
#{indent_str}  cMessageBuffer  = #{@channelCellName}.eMessageBuffer;
#{indent_str}  taskPriority = #{@task_priority};
#{indent_str}};
EOT

  @end_region.gen_region_str_post file
end

#get_cell_namespace_pathObject

NamespacePath を得る

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



314
315
316
317
318
# File 'lib/tecsgen/plugin/HRP2RPCPlugin.rb', line 314

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 のチェック



291
292
293
294
295
296
297
298
299
300
# File 'lib/tecsgen/plugin/HRP2RPCPlugin.rb', line 291

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 のチェック



303
304
305
306
307
308
309
310
# File 'lib/tecsgen/plugin/HRP2RPCPlugin.rb', line 303

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