Class: Syskit::Composition::CompositionChildInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/syskit/composition.rb

Overview

Proxy returned by the child_name_child handler

This is used to perform port mapping if needed

Instance Method Summary collapse

Constructor Details

#initialize(composition_task, child_name, child_task) ⇒ CompositionChildInstance

Returns a new instance of CompositionChildInstance



295
296
297
# File 'lib/syskit/composition.rb', line 295

def initialize(composition_task, child_name, child_task)
    @composition_task, @child_name, @child_task = composition_task, child_name, child_task
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/syskit/composition.rb', line 323

def method_missing(m, *args, &block)
    if m =~ /_port$/
        port_name = $`
        mapped_port_name = @composition_task.map_child_port(@child_name, port_name)
        if port = @child_task.find_input_port(mapped_port_name)
            return port
        elsif port = @child_task.find_output_port(mapped_port_name)
            return port
        else raise NoMethodError, "task #{@child_task}, child #{@child_name} of #{@composition_task}, has no port called #{port_name}"
        end
    end
    @child_task.send(m, *args, &block)
end

Instance Method Details

#as_planObject



298
299
300
# File 'lib/syskit/composition.rb', line 298

def as_plan
    @child_task
end

#connect_ports(target_task, mappings) ⇒ Object



302
303
304
305
306
307
308
309
# File 'lib/syskit/composition.rb', line 302

def connect_ports(target_task, mappings)
    mapped_connections = Hash.new
    mappings.map do |(source, sink), policy|
        source = find_output_port(source).name
        mapped_connections[[source, sink]] = policy
    end
    @child_task.connect_ports(target_task, mapped_connections)
end

#disconnect_ports(target_task, mappings) ⇒ Object



311
312
313
314
315
316
317
# File 'lib/syskit/composition.rb', line 311

def disconnect_ports(target_task, mappings)
    mappings = mappings.map do |source, sink|
        source = find_output_port(source).name
        [source, sink]
    end
    @child_task.disconnect_ports(target_task, mappings)
end

#respond_to_missing?(m, include_private) ⇒ Boolean

Returns:

  • (Boolean)


319
320
321
# File 'lib/syskit/composition.rb', line 319

def respond_to_missing?(m, include_private)
    (m =~ /_port$/) || super
end