module Syskit::DataFlow::Extension

Methods that are mixed-in Syskit::Component to help with connection management

Public Instance Methods

all_inputs_connected?(only_static: false) click to toggle source

Returns true if all the declared connections to the inputs of task have been applied. A given module won't be started until it is the case.

If the only_static flag is set to true, only ports that require static connections will be considered

# File lib/syskit/data_flow.rb, line 418
def all_inputs_connected?(only_static: false)
    logger = Runtime::ConnectionManagement
    each_concrete_input_connection do |source_task, source_port, sink_port, policy|
        # Our source may not be initialized at all
        if !source_task.orocos_task
            logger.debug do
                logger.debug "missing input connection because the source task is not ready on port #{sink_port} of"
                logger.log_pp :debug, self
                logger.log_nest(2) do
                    logger.debug "connection expected to port #{source_port} of"
                    logger.log_pp :debug, source_task
                end
                break
            end
            return false
        end
        if only_static && !concrete_model.find_input_port(sink_port)
            next
        end

        is_connected =
            ActualDataFlow.has_edge?(source_task.orocos_task, orocos_task) &&
            ActualDataFlow.edge_info(source_task.orocos_task, orocos_task).
                has_key?([source_port, sink_port])

        if !is_connected
            logger.debug do
                logger.debug "missing input connection on port #{sink_port} of"
                logger.log_pp :debug, self
                logger.log_nest(2) do
                    logger.debug "  connection expected to port #{source_port} of"
                    logger.log_pp :debug, source_task
                end
                break
            end
            return false
        end
    end
    true
end
connect_ports(sink_task, mappings) click to toggle source

Connect a set of ports between self and target_task.

mappings describes the connections. It is a hash of the form

[source_port_name, sink_port_name] => connection_policy

where source_port_name is a port of self and sink_port_name a port of target_task

Raises ArgumentError if one of the ports do not exist.

# File lib/syskit/data_flow.rb, line 304
def connect_ports(sink_task, mappings)
    return if mappings.empty?

    mappings.each do |(out_port, in_port), options|
        ensure_has_output_port(out_port)
        sink_task.ensure_has_input_port(in_port)
    end
    add_sink(sink_task, mappings)
end
connected?(port_name) click to toggle source

Returns true if port_name is connected

# File lib/syskit/data_flow.rb, line 281
def connected?(port_name)
    dataflow_graph = relation_graph_for(Flows::DataFlow)
    dataflow_graph.has_out_connections?(self, port_name) ||
        dataflow_graph.has_in_connections?(self, port_name)
end
connected_to?(port_name, other_task, other_port) click to toggle source

Tests if port_name is connected to other_port on other_task

# File lib/syskit/data_flow.rb, line 289
def connected_to?(port_name, other_task, other_port)
    relation_graph_for(Flows::DataFlow).
        connected?(self, port_name, other_task, other_port)
end
disconnect_port(port_name) click to toggle source
# File lib/syskit/data_flow.rb, line 323
def disconnect_port(port_name)
    if port_name.respond_to?(:name)
        port_name = port_name.name
    end

    each_source do |parent_task|
        current = parent_task[self, Flows::DataFlow]
        current.delete_if { |(from, to), pol| to == port_name }
        parent_task[self, Flows::DataFlow] = current
    end
    each_sink do |child_task|
        current = self[child_task, Flows::DataFlow]
        current.delete_if { |(from, to), pol| from == port_name }
        self[child_task, Flows::DataFlow] = current
    end
end
disconnect_ports(sink_task, mappings) click to toggle source
# File lib/syskit/data_flow.rb, line 314
def disconnect_ports(sink_task, mappings)
    mappings.each do |out_port, in_port|
        ensure_has_output_port(out_port)
        sink_task.ensure_has_input_port(in_port)
    end
    relation_graph_for(Flows::DataFlow).
        remove_connections(self, sink_task, mappings)
end
each_concrete_input_connection(port = nil, &block) click to toggle source
# File lib/syskit/data_flow.rb, line 364
def each_concrete_input_connection(port = nil, &block)
    relation_graph_for(Flows::DataFlow).
        each_concrete_in_connection(self, port, &block)
end
each_concrete_output_connection(port = nil, &block) click to toggle source
# File lib/syskit/data_flow.rb, line 383
def each_concrete_output_connection(port = nil, &block)
    relation_graph_for(Flows::DataFlow).
        each_concrete_out_connection(self, port, &block)
end
each_input_connection(port = nil, &block) click to toggle source

Yield or enumerates the connections that exist towards the input ports of self.

@param [#name,String,nil] port if non-nil, the port for

which we want to enumerate the connections (in which case
the sink_port yield parameter is guaranteed to be this name).
Otherwise, all ports are enumerated.

@yield each connections @yieldparam [Syskit::TaskContext] source_task the source task in

the connection

@yieldparam [String] source_port the source port name on source_task @yieldparam [String] sink_port the sink port name on self. If

the port argument is non-nil, it is guaranteed to be the
same.

@yieldparam [Hash] policy the connection policy

@see #each_concrete_input_connection #each_concrete_output_connection

each_output_connection
# File lib/syskit/data_flow.rb, line 359
def each_input_connection(port = nil, &block)
    relation_graph_for(Flows::DataFlow).
        each_in_connection(self, port, &block)
end
each_output_connection(port = nil, &block) click to toggle source

Yield or enumerates the connections that exist from the output ports of self.

@param (see Syskit::ConnectionGraph#each_out_connection) @yield (see Syskit::ConnectionGraph#each_out_connection) @yieldparam (see Syskit::ConnectionGraph#each_out_connection)

# File lib/syskit/data_flow.rb, line 408
def each_output_connection(port = nil, &block)
    relation_graph_for(Flows::DataFlow).
        each_out_connection(self, port, &block)
end
ensure_has_input_port(name) click to toggle source

Makes sure that self has an input port called name. It will instanciate a dynamic port if needed.

Raises ArgumentError if no such port can ever exist on self

# File lib/syskit/data_flow.rb, line 245
def ensure_has_input_port(name)
    if !model.find_input_port(name)
        raise NotInputPort, "#{self} has no input port called #{name}"
    end
end
ensure_has_output_port(name) click to toggle source

Makes sure that self has an output port called name. It will instanciate a dynamic port if needed.

Raises ArgumentError if no such port can ever exist on self

# File lib/syskit/data_flow.rb, line 235
def ensure_has_output_port(name)
    if !model.find_output_port(name)
        raise NotOutputPort, "#{self} has no output port called #{name}"
    end
end
forward_input_ports(task, mappings) click to toggle source

Forward an input of self to an input port of another task

# File lib/syskit/data_flow.rb, line 252
def forward_input_ports(task, mappings)
    if !fullfills?(Composition)
        raise NotComposition, "#{self} is not a composition"
    elsif mappings.empty?
        return
    end

    mappings.each do |(from, to), options|
        ensure_has_input_port(from)
        task.ensure_has_input_port(to)
    end
    add_sink(task, mappings)
end
forward_output_ports(task, mappings) click to toggle source
# File lib/syskit/data_flow.rb, line 266
def forward_output_ports(task, mappings)
    if !task.fullfills?(Composition)
        raise NotComposition, "#{self} is not a composition"
    elsif mappings.empty?
        return
    end

    mappings.each do |(from, to), options|
        ensure_has_output_port(from)
        task.ensure_has_output_port(to)
    end
    add_sink(task, mappings)
end
has_concrete_input_connection?(port) click to toggle source

Tests if an input port or any input ports is connected to an actual task (ignoring composition exports)

@param [#name,String,nil] port if non-nil, only

connections involving this port will be tested against.
Otherwise, the method tests for any inbound connection to
self

@return [Boolean] true if the given port, or the task, is

connected to something by an inbound connection
# File lib/syskit/data_flow.rb, line 378
def has_concrete_input_connection?(port)
    each_concrete_input_connection(port) { return true }
    false
end
has_concrete_output_connection?(port) click to toggle source

Tests if an output port or any output ports is connected to an actual task (ignoring composition exports)

@param [#name,String,nil] port if non-nil, only

connections involving this port will be tested against.
Otherwise, the method tests for any outbound connection to
self

@return [Boolean] true if the given port, or the task, is

connected to something by an outbound connection
# File lib/syskit/data_flow.rb, line 397
def has_concrete_output_connection?(port)
    each_concrete_output_connection(port) { return true }
    false
end