Class: Orocos::Async::SubPortProxy

Inherits:
PortProxy show all
Defined in:
lib/orocos/async/task_context_proxy.rb

Instance Attribute Summary

Attributes inherited from ObjectBase

#emitting, #event_loop, #options, #pending_adds

Instance Method Summary collapse

Methods inherited from PortProxy

#input?, #output?, #period, #period=, #reachable!, #reachable?, #really_add_listener, #task, #to_s, #type?, #unreachable!

Methods inherited from ObjectBase

#add_listener, define_event, define_events, #disable_emitting, #event, event_names, #event_names, #invalidate_delegator!, #listener?, #listeners, #number_of_listeners, #on_event, #proxy_event, #reachable!, #reachable?, #really_add_listener, #remove_all_listeners, #remove_listener, #remove_proxy_event, #unreachable!, #valid_delegator?, valid_event?, #valid_event?, validate_event, #validate_event, #wait

Constructor Details

#initialize(port_proxy, subfield = Array.new) ⇒ SubPortProxy

Returns a new instance of SubPortProxy



337
338
339
340
341
342
343
344
345
346
# File 'lib/orocos/async/task_context_proxy.rb', line 337

def initialize(port_proxy,subfield = Array.new)
    super(port_proxy)
    @subfield = Array(subfield).map do |field|
        if field.respond_to?(:to_i) && field.to_i.to_s == field
            field.to_i
        else
            field
        end
    end
end

Instance Method Details

#full_nameObject



374
375
376
# File 'lib/orocos/async/task_context_proxy.rb', line 374

def full_name
    super + "." + @subfield.join(".")
end

#last_sampleObject



390
391
392
# File 'lib/orocos/async/task_context_proxy.rb', line 390

def last_sample
    subfield(__getobj__.last_sample,@subfield)
end

#nameObject



378
379
380
# File 'lib/orocos/async/task_context_proxy.rb', line 378

def name
    super + "." + @subfield.join(".")
end

#new_sampleObject



386
387
388
# File 'lib/orocos/async/task_context_proxy.rb', line 386

def new_sample
    type.new
end

#on_data(policy = Hash.new) ⇒ Object



356
357
358
359
360
361
# File 'lib/orocos/async/task_context_proxy.rb', line 356

def on_data(policy = Hash.new)
    on_raw_data(policy) do |sample|
        sample = Typelib.to_ruby(sample) if sample
        yield(sample)
    end
end

#on_raw_data(policy = Hash.new, &block) ⇒ Object



363
364
365
366
367
368
# File 'lib/orocos/async/task_context_proxy.rb', line 363

def on_raw_data(policy = Hash.new,&block)
    p = proc do |sample|
        block.call subfield(sample,@subfield)
    end
    super(policy,&p)
end

#orocos_type_nameObject



382
383
384
# File 'lib/orocos/async/task_context_proxy.rb', line 382

def orocos_type_name
    type.name
end

#raw_last_sampleObject



394
395
396
# File 'lib/orocos/async/task_context_proxy.rb', line 394

def raw_last_sample
    subfield(__getobj__.raw_last_sample,@subfield)
end

#sub_port(subfield) ⇒ Object

Raises:

  • (RuntimeError)


398
399
400
401
# File 'lib/orocos/async/task_context_proxy.rb', line 398

def sub_port(subfield)
    raise RuntimeError , "Port #{name} is not an output port" if !output?
    SubPortProxy.new(__getobj__,@subfield+subfield)
end

#to_async(options = Hash.new) ⇒ Object



348
349
350
# File 'lib/orocos/async/task_context_proxy.rb', line 348

def to_async(options=Hash.new)
    task.to_async(options).port(port.name,:subfield => @subfield)
end

#to_proxy(options = Hash.new) ⇒ Object



352
353
354
# File 'lib/orocos/async/task_context_proxy.rb', line 352

def to_proxy(options=Hash.new)
    self
end

#typeObject



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/orocos/async/task_context_proxy.rb', line 403

def type
    @sub_type ||= if !@subfield.empty?
                  type ||= super
                  @subfield.each do |f|
                      type = if type.respond_to? :deference
                                 type.deference
                             else
                                 type[f]
                             end
                  end
                  type
              else
                  super
              end
end

#type_nameObject



370
371
372
# File 'lib/orocos/async/task_context_proxy.rb', line 370

def type_name
    type.name
end