Class: SharedRPCPlugin

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

Overview

以下を仮定(制限事項)

呼び元、呼び先のエンディアン、char, short, int_t, long_t, intptr_t のサイズが同じ
有符号、無符号でサイズが同じ

Constant Summary collapse

@@shared_channel_list =
{}

Constants included from GenTransparentMarshaler

GenTransparentMarshaler::RPCPluginArgProc

Constants inherited from Plugin

Plugin::PluginArgProc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GenParamCopy

#print_nullable_post, #print_nullable_pre, #print_param, #print_param0

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, #get_cell_name, #get_cell_namespace_path, #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) ⇒ SharedRPCPlugin

RPCPlugin の initialize

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


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

def initialize(cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell)
  # mikan プラグインオプション指定の不一致のチェック task_priority,

  super
  initialize_transparent_marshaler cell_name

  # オプション:GenTransparentMarshaler 参照
  @plugin_arg_check_proc_tab = RPCPluginArgProc
  @channelCellName = "" # nil にしておく
  parse_plugin_arg

  @shared_channel_ct_name = :"tSharedRPCPlugin_#{@channelCelltype}"
  @shared_channel_ct_file_name = "#{$gen}/#{@shared_channel_ct_name}.cdl"
  @rpc_channel_celltype_name = :"tSharedRPCPlugin_#{@TDRCelltype}_#{@channelCelltype}_#{@signature.get_global_name}"
  @rpc_channel_celltype_file_name = "#{$gen}/#{@rpc_channel_celltype_name}.cdl"

  @shared_channel_cell = @channelCellName
  if @shared_channel_cell == ""
    cdl_error("SharedRPCPlugin: need channelCellName option")
  end

  if @@shared_channel_list[@shared_channel_cell].nil?
    # 初出
    @@shared_channel_list[@shared_channel_cell] = [self]
  else
    # 二番目以降
    @@shared_channel_list[@shared_channel_cell] << self
  end
  @sub_channel_no = @@shared_channel_list[@shared_channel_cell].length - 1

  if @region != @@shared_channel_list[@shared_channel_cell][0].region
    # 初出とリージョン不一致 (初出は、自分自身とチェックされる。無駄だが小さいので放置)
    cdl_error("SharedRPCPlugin: preferred region mismatch current: #{@region.get_name} previous: #{@@shared_channel_list[@shared_channel_cell][0].region.get_name}")
  else
    dbgPrint "SahredRPCPlugin: Region: #{@region.get_name}, #{@@shared_channel_list[@shared_channel_cell][0].region.get_name}\n"
  end

  if @signature.need_PPAllocator?
    if @PPAllocatorSize.nil?
      cdl_error("PPAllocatorSize must be speicified for oneway [in] array")
    end
  end
end

Instance Attribute Details

#regionObject (readonly)

Returns the value of attribute region.



55
56
57
# File 'lib/tecsgen/plugin/SharedRPCPlugin.rb', line 55

def region
  @region
end

Class Method Details

.gen_post_code(file) ⇒ Object

後ろのコードを生成

プラグインの後ろのコードを生成

file

File:



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

def self.gen_post_code(file)
  file.print "/* '#{self.name}' post code */\n"
  @@shared_channel_list.each{|chan_name, plugin_obj|
    plugin_obj[0].gen_post_code(file, plugin_obj)
  }
end

Instance Method Details

#gen_plugin_decl_code(file) ⇒ Object

def set_through_info( start_region, end_region, through_type )

super

end



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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/tecsgen/plugin/SharedRPCPlugin.rb', line 111

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

  if @@generated_celltype[@ct_name].nil?
    @@generated_celltype[@ct_name] = [self]
  else
    @@generated_celltype[@ct_name] << self
  end

  gen_marshaler_celltype
  # 同じ内容を二度書く可能性あり (AppFile は不可)

  if @signature.need_PPAllocator?
    alloc_call_port = "  call sPPAllocator cPPAllocator;\n"
    alloc_call_port_join = "  cPPAllocator => composite.cPPAllocator;\n"
  else
    alloc_call_port = ""
    alloc_call_port_join = ""
  end

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

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

composite #{@rpc_channel_celltype_name} {
/* Interface */
call  #{@signature.get_namespace_path} #{@call_port_name};
entry #{@signature.get_namespace_path} eThroughEntry;
call  sTDR       cTDR;
call  sEventflag cEventflag;
entry sUnmarshalerMain  eUnmarshalAndCallFunction;
#{alloc_call_port}
[optional]
  call sSemaphore cLockChannel;

/* Implementation */
cell #{@marshaler_celltype_name} #{@signature.get_global_name}_marshaler{
  cTDR         => composite.cTDR;
  cEventflag   => composite.cEventflag;
  cLockChannel => composite.cLockChannel;
};
cell #{@unmarshaler_celltype_name} #{@signature.get_global_name}_unmarshaler{
  cTDR         => composite.cTDR;
  cEventflag   => composite.cEventflag;
  cServerCall  => composite.#{@call_port_name};
#{alloc_call_port_join}  };
composite.eThroughEntry => #{@signature.get_global_name}_marshaler.eClientEntry;
composite.eUnmarshalAndCallFunction => #{@signature.get_global_name}_unmarshaler.eUnmarshalAndCallFunction;
};
EOT
  # mikan stackSize option & 最新 tecs_package 対応

  f.close

  f = CFile.open("#{$gen}/#{@shared_channel_ct_name}.cdl", "w")
  # 同じ内容を二度書く可能性あり (AppFile は不可)

  f.print <<EOT
[active]
composite #{@shared_channel_ct_name} {
/* Interface */
entry  sSemaphore eSemaphore[];
call   sUnmarshalerMain  cUnmarshalAndCallFunction[];

entry  sDataqueue eDataqueue;
entry  sTDR       eTDR;
entry  sEventflag eEventflag;

attr {
  PRI    priority;
};

/* Implementation */
cell #{@channelCelltype} Channel{
};
cell tSemaphore Semaphore {count = 1; attribute = C_EXP("TA_NULL");};
cell tRPCSharedTaskMain RPCSharedTaskMain {
  cUnmarshalAndCallFunction => composite.cUnmarshalAndCallFunction;
  cServerSideTDR            = Channel.eTDR;
};
cell tRPCSharedChannelMan RPCChannelMan {
  cSemaphore                = Semaphore.eSemaphore;
  cClientSideTDR            = Channel.eTDR;
};
cell tTask RPCSharedTask {
  cBody = RPCSharedTaskMain.eMain;
  taskAttribute = C_EXP("TA_ACT");
  stackSize = 4096;
  priority = composite.priority;
};
composite.eTDR           => Channel.eTDR;
composite.eEventflag     => Channel.eEventflag;
composite.eSemaphore     => RPCChannelMan.eSemaphore;
composite.eDataqueue     => Channel.eDataqueue;
};
EOT
  f.close
end

#gen_post_code(file, plugin_obj) ⇒ Object

後ろのコードを生成

plugin_obj が代表して出力する(インスタンス変数にアクセスしたいため)



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/tecsgen/plugin/SharedRPCPlugin.rb', line 312

def gen_post_code(file, plugin_obj)
  chan_name = @shared_channel_cell

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

  # 共有されている通信チャンネルの生成
  # 各プラグインインスタンスでは @shared_channel_ct_name として記憶している
  file.print "#{indent_str}cell tSharedRPCPlugin_#{@channelCelltype} #{chan_name} {\n"
  plugin_obj.each{|po|
    file.print <<EOT
#{indent_str}    cUnmarshalAndCallFunction[] = #{@cell_name}.eUnmarshalAndCallFunction;
EOT
  }
  file.printf "#{indent_str}    priority = #{@task_priority};\n#{indent_str}};\n"
  @region.gen_region_str_post file
end

#gen_through_cell_code(file) ⇒ Object

through cell コードを生成



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

def gen_through_cell_code(file)
  gen_plugin_decl_code(file)

  file.print <<EOT
import( "#{@rpc_channel_celltype_file_name}" );
import( "#{$gen}/#{@shared_channel_ct_name}.cdl" );
EOT

  # nest = @next_cell.get_region.gen_region_str_pre file
  nest = @region.gen_region_str_pre file
  indent_str = "  " * nest
  if @next_cell_port_subscript
    subscript = "[" + @next_cell_port_subscript.to_s + "]"
  else
    subscript = ""
  end

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

  # PPAllocator が必要か?
  if @signature.need_PPAllocator?
    if @sub_channel_no == 0
      file.print <<EOT
#{indent_str}cell tPPAllocator PPAllocator_#{@shared_channel_cell}{
#{indent_str}  heapSize = #{@PPAllocatorSize};
#{indent_str}};
EOT
    end

    ppallocator_join = "#{indent_str}  cPPAllocator = PPAllocator_#{@shared_channel_cell}.ePPAllocator;\n"
  else
    ppallocator_join = ""
  end

  # 共有される通信チャンネルの生成のプロトタイプ宣言
  file.print <<EOT
#{indent_str}cell #{@shared_channel_ct_name} #{@shared_channel_cell};
EOT

  # ここから各結合ごとのセルを生成

  # アロケータの指定があるか?
  if cell.get_allocator_list.length > 0

    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} #{@cell_name} {
#{indent_str}  #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name}#{subscript};
#{indent_str}  cTDR         = #{@shared_channel_cell}.eTDR;
#{indent_str}  cEventflag   = #{@shared_channel_cell}.eEventflag;
#{indent_str}  cLockChannel =  #{@shared_channel_cell}.eSemaphore[#{@sub_channel_no}];
#{ppallocator_join}#{indent_str}};
EOT
  @region.gen_region_str_post file
end