-
Notifications
You must be signed in to change notification settings - Fork 15
chore: refactor handling of the actual dataflow #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: transition-to-runkit
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,17 +6,21 @@ module Runtime | |
| # | ||
| # I.e. this is the set of connections that really exist between our | ||
| # components | ||
| class ActualDataFlowGraph < ConnectionGraph | ||
| class ActualDataFlowGraph | ||
| # Information about which ports are static and which are not. This | ||
| # information is critical during disconnection to force | ||
| # reconfiguration of the associated tasks | ||
| # | ||
| # @return [Hash<(Orocos::TaskContext,String),Boolean>] | ||
| attr_reader :static_info | ||
|
|
||
| def initialize(*) | ||
| super | ||
| def initialize | ||
| @static_info = {} | ||
| @graph = ConnectionGraph.new | ||
| end | ||
|
|
||
| def name=(name) | ||
| @graph.name = name | ||
| end | ||
|
|
||
| # Registers a connection between two tasks | ||
|
|
@@ -76,13 +80,19 @@ def add_connections_process_mappings(source_task, sink_task, mappings) | |
| @static_info[[sink_task, sink_port]] = sink_static | ||
| connections[[source_port, sink_port]] = policy | ||
| end | ||
| connections | ||
| end | ||
|
|
||
| if !force_update || !has_edge?(source_task, sink_task) | ||
| super(source_task, sink_task, connections) | ||
| else | ||
| set_edge_info(source_task, sink_task, | ||
| edge_info(source_task, sink_task).merge(connections)) | ||
| end | ||
| def remove_connections(source_task, sink_task, connections) | ||
| @graph.remove_connections(source_task, sink_task, connections) | ||
| end | ||
|
|
||
| def clear | ||
| @graph.clear | ||
| end | ||
|
|
||
| def empty? | ||
| @graph.empty? | ||
| end | ||
|
|
||
| # Whether the given port is static (per {Port#static?} | ||
|
|
@@ -96,6 +106,127 @@ def static?(task, port) | |
| raise ArgumentError, | ||
| "no port #{port} on a task called #{task} is registered on #{self}" | ||
| end | ||
|
|
||
| # Returns whether two ports are connected | ||
| def tasks_connected?(source_task, sink_task) | ||
| @graph.has_edge?(source_task, sink_task) | ||
| end | ||
|
|
||
| # Returns information about the connections existing between two tasks | ||
| # | ||
| # @param [Orocos::TaskContext] source_task | ||
| # @param [Orocos::TaskContext] sink_task | ||
| # @return [{[String,String] => Hash}] mapping of (source_port,sink_port) pairs | ||
| # to the policy of the established connection | ||
| def connections_of_tasks(source_task, sink_task) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this isn't a heterogeneous graph, I would go with just |
||
| return {} unless @graph.has_edge?(source_task, sink_task) | ||
|
|
||
| @graph.edge_info(source_task, sink_task) | ||
| end | ||
|
|
||
| # Returns whether two ports are connected | ||
| def ports_connected?(source_task, source_port, sink_task, sink_port) | ||
| @graph.has_edge?(source_task, sink_task) && | ||
| @graph.edge_info(source_task, sink_task) | ||
| .key?([source_port, sink_port]) | ||
| end | ||
|
|
||
| # List connections to the given ports | ||
| # | ||
| # @param [Orocos::Task] orocos_task the task whose input port we're inspecting | ||
| # @param [Array<String>] port_name the name of the input port | ||
| # @return [{[Orocos::Task,Orocos::Task] => Array<[String,String]>}] matching | ||
| # connections, as a mapping of (source_task, sink_task) to the port | ||
| # pair (as names) | ||
| def input_connections_of_ports(orocos_task, port_names) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| @graph.each_in_neighbour(orocos_task) | ||
| .with_object({}) do |source_t, result| | ||
| mappings = @graph.edge_info(source_t, orocos_task) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At
|
||
| result[[source_t, orocos_task]] = | ||
| mappings.each_key.find_all do |_, sink_p| | ||
| port_names.include?(sink_p) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Lists the tasks that are present in the graph | ||
| def each_task | ||
| @graph.each_vertex | ||
| end | ||
|
|
||
| # List connections from the given task | ||
| # | ||
| # @param [Orocos::Task] orocos_task the task whose output connections are | ||
| # expected | ||
| # @return [{[Orocos::Task,Orocos::Task] => Array<[String,String]>}] matching | ||
| # connections, as a mapping of (source_task, sink_task) to the port | ||
| # pair (as names) | ||
| def output_connections_of_task(orocos_task) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the reason of these '_of_task' and 'of_ports' The input_connections is of_ports, that is is restricted to some ports. This gives all outputs of a given task. There's actually output_connections_of_ports that restricts to ports. I think not specifying it on all methods would be confusing. |
||
| @graph.each_out_neighbour(orocos_task).with_object({}) do |sink_t, result| | ||
| mappings = @graph.edge_info(orocos_task, sink_t) | ||
| result[[orocos_task, sink_t]] = mappings.keys | ||
| end | ||
| end | ||
|
|
||
| # List connections from the given ports | ||
| # | ||
| # @param [Orocos::Task] orocos_task the task whose output ports | ||
| # we are inspecting | ||
| # @param [Array<String>] port_names the names of the output ports | ||
| # @return [{[Orocos::Task,Orocos::Task] => Array<[String,String]>}] matching | ||
| # connections, as a mapping of (source_task, sink_task) to the port | ||
| # pair (as names) | ||
| def output_connections_of_ports(orocos_task, port_names) | ||
| @graph.each_out_neighbour(orocos_task).with_object({}) do |sink_t, result| | ||
| mappings = @graph.edge_info(orocos_task, sink_t) | ||
| result[[orocos_task, sink_t]] = | ||
| mappings.each_key.find_all do |source_p, _| | ||
| port_names.include?(source_p) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # List the connections to static input ports | ||
| # | ||
| # @param [Orocos::TaskContex] orocos_task | ||
| # @return [{String=>Set<(Orocos::TaskContext,String)>}] mapping from a | ||
| # static input port of orocos_task to its sources, as pairs of tasks and | ||
| # port name | ||
| def static_input_port_connections(orocos_task) | ||
| @graph.each_in_neighbour(orocos_task) | ||
| .with_object({}) do |source_t, result| | ||
| connections = @graph.edge_info(source_t, orocos_task) | ||
| connections.each_key do |source_p, sink_p| | ||
| if static?(orocos_task, sink_p) | ||
| sources = (result[sink_p] ||= Set.new) | ||
| sources << [source_t, source_p] | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # List the connections to static output ports | ||
| # | ||
| # @param [Orocos::TaskContex] orocos_task | ||
| # @return [{String=>Set<(Orocos::TaskContext,String)>}] mapping from a | ||
| # static output port of orocos_task to its sinks, as pairs of tasks and | ||
| # port name | ||
| def static_output_port_connections(orocos_task) | ||
| @graph.each_out_neighbour(orocos_task).with_object({}) do |sink_t, result| | ||
| connections = @graph.edge_info(orocos_task, sink_t) | ||
| connections.each_key do |source_p, sink_p| | ||
| if static?(orocos_task, source_p) | ||
| sinks = (result[source_p] ||= Set.new) | ||
| sinks << [sink_t, sink_p] | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Return the internal graph structure | ||
| def to_graph | ||
| @graph | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see from where
orocos_taskis from. Neither in this refactor or in the old code