Class: Syskit::BoundDataService
- Includes:
- MetaRuby::DSLs::FindThroughMethodMissing, PortAccess
- Defined in:
- lib/syskit/bound_data_service.rb
Overview
Representation of a data service as provided by an actual component
It is usually created from a Models::BoundDataService instance using Models::BoundDataService#bind(component), or simply by calling the task's service access (i.e. the _srv helpers or
The model-level bound data service corresponding to self is {#model. The data service model is therefore #model.#model. The component instance this data service is bound to is #component.
#component.#model is guaranteed to be #model.#component
Defined Under Namespace
Classes: DRoby
Instance Attribute Summary collapse
-
#component ⇒ Component
readonly
The component instance we are bound to.
-
#model ⇒ Models::BoundDataService
readonly
The data service model we are an instance of.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as(service) ⇒ Object
- #as_plan ⇒ Object
-
#connect_to(port_or_component, policy = Hash.new) ⇒ Object
Automatically computes connections from the output ports of self to the given port or to the input ports of the given component.
- #data_reader(*names) ⇒ Object
- #data_writer(*names) ⇒ Object
- #droby_dump(peer) ⇒ Object
- #each_fullfilled_model(&block) ⇒ Object
- #each_slave_data_service(&block) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#find_data_service(name) ⇒ Object
Looks for a slave data service by name.
- #find_through_method_missing(m, args) ⇒ Object
- #fullfills?(*args) ⇒ Boolean
- #has_data_service?(name) ⇒ Boolean
- #has_through_method_missing?(m) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(component, model) ⇒ BoundDataService
constructor
A new instance of BoundDataService.
- #inspect ⇒ Object
-
#name ⇒ String
The data service name.
-
#self_port_to_component_port(port) ⇒ Syskit::Port
Resolves the given Syskit::Port object into a Port object where #component is guaranteed to be a proper component instance.
-
#service_model ⇒ Object
Returns the data service model.
- #short_name ⇒ Object
-
#to_instance_requirements ⇒ Syskit::InstanceRequirements
Generates the InstanceRequirements object that represents
self
best. - #to_s ⇒ Object
- #to_task ⇒ Object
Methods included from PortAccess
#each_input_port, #each_output_port, #each_port, #find_input_port, #find_output_port, #find_port, #has_input_port?, #has_output_port?, #has_port?
Constructor Details
#initialize(component, model) ⇒ BoundDataService
Returns a new instance of BoundDataService
54 55 56 57 58 59 60 61 62 |
# File 'lib/syskit/bound_data_service.rb', line 54 def initialize(component, model) @component, @model = component, model if !component.kind_of?(Component) raise "expected a component instance, got #{component}" end if !model.kind_of?(Models::BoundDataService) raise "expected a model of a bound data service, got #{model}" end end |
Instance Attribute Details
#component ⇒ Component (readonly)
Returns The component instance we are bound to
18 19 20 |
# File 'lib/syskit/bound_data_service.rb', line 18 def component @component end |
#model ⇒ Models::BoundDataService (readonly)
The data service model we are an instance of.
self is basically model.bind(component)
25 26 27 |
# File 'lib/syskit/bound_data_service.rb', line 25 def model @model end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 |
# File 'lib/syskit/bound_data_service.rb', line 43 def ==(other) eql?(other) end |
#as(service) ⇒ Object
128 129 130 131 132 |
# File 'lib/syskit/bound_data_service.rb', line 128 def as(service) result = self.dup result.instance_variable_set(:@model, model.as(service)) result end |
#as_plan ⇒ Object
120 121 122 |
# File 'lib/syskit/bound_data_service.rb', line 120 def as_plan component end |
#connect_to(port_or_component, policy = Hash.new) ⇒ Object
Automatically computes connections from the output ports of self to the given port or to the input ports of the given component
(see Syskit.connect)
73 74 75 |
# File 'lib/syskit/bound_data_service.rb', line 73 def connect_to(port_or_component, policy = Hash.new) Syskit.connect(self, port_or_component, policy) end |
#data_reader(*names) ⇒ Object
116 117 118 |
# File 'lib/syskit/bound_data_service.rb', line 116 def data_reader(*names) component.data_reader(model.port_mappings_for_task[names.first], *names[1..-1]) end |
#data_writer(*names) ⇒ Object
112 113 114 |
# File 'lib/syskit/bound_data_service.rb', line 112 def data_writer(*names) component.data_writer(model.port_mappings_for_task[names.first], *names[1..-1]) end |
#droby_dump(peer) ⇒ Object
167 168 169 |
# File 'lib/syskit/bound_data_service.rb', line 167 def droby_dump(peer) DRoby.new(peer.dump(component), peer.dump(model)) end |
#each_fullfilled_model(&block) ⇒ Object
104 105 106 |
# File 'lib/syskit/bound_data_service.rb', line 104 def each_fullfilled_model(&block) model.each_fullfilled_model(&block) end |
#each_slave_data_service(&block) ⇒ Object
81 82 83 84 85 |
# File 'lib/syskit/bound_data_service.rb', line 81 def each_slave_data_service(&block) component.model.each_slave_data_service(self.model) do |slave_m| yield(slave_m.bind(component)) end end |
#eql?(other) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/syskit/bound_data_service.rb', line 37 def eql?(other) other.kind_of?(self.class) && other.component == component && other.model == model end |
#find_data_service(name) ⇒ Object
Looks for a slave data service by name
95 96 97 98 99 100 101 102 |
# File 'lib/syskit/bound_data_service.rb', line 95 def find_data_service(name) component.model.each_slave_data_service(self.model) do |slave_m| if slave_m.name == name return slave_m.bind(component) end end nil end |
#find_through_method_missing(m, args) ⇒ Object
156 157 158 159 160 |
# File 'lib/syskit/bound_data_service.rb', line 156 def find_through_method_missing(m, args) MetaRuby::DSLs.find_through_method_missing( self, m, args, '_srv'.freeze => :find_data_service) || super end |
#fullfills?(*args) ⇒ Boolean
108 109 110 |
# File 'lib/syskit/bound_data_service.rb', line 108 def fullfills?(*args) model.fullfills?(*args) end |
#has_data_service?(name) ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/syskit/bound_data_service.rb', line 87 def has_data_service?(name) component.model.each_slave_data_service(self.model) do |slave_m| return true if slave_m.name == name end false end |
#has_through_method_missing?(m) ⇒ Boolean
150 151 152 153 154 |
# File 'lib/syskit/bound_data_service.rb', line 150 def has_through_method_missing?(m) MetaRuby::DSLs.has_through_method_missing?( self, m, '_srv'.freeze => :has_data_service?) || super end |
#hash ⇒ Object
33 34 35 |
# File 'lib/syskit/bound_data_service.rb', line 33 def hash [self.class, component, model].hash end |
#inspect ⇒ Object
138 |
# File 'lib/syskit/bound_data_service.rb', line 138 def inspect; to_s end |
#name ⇒ String
The data service name
29 30 31 |
# File 'lib/syskit/bound_data_service.rb', line 29 def name; model.name end |
#self_port_to_component_port(port) ⇒ Syskit::Port
Resolves the given Syskit::Port object into a Port object where #component is guaranteed to be a proper component instance
It should not be used directly. One should usually use Port#to_component_port
65 66 67 |
# File 'lib/syskit/bound_data_service.rb', line 65 def self_port_to_component_port(port) return component.find_port(model.port_mappings_for_task[port.name]) end |
#service_model ⇒ Object
Returns the data service model
50 51 52 |
# File 'lib/syskit/bound_data_service.rb', line 50 def service_model model.model end |
#short_name ⇒ Object
77 78 79 |
# File 'lib/syskit/bound_data_service.rb', line 77 def short_name "#{component}:#{model.short_name}" end |
#to_instance_requirements ⇒ Syskit::InstanceRequirements
Generates the InstanceRequirements object that represents self
best
144 145 146 147 148 |
# File 'lib/syskit/bound_data_service.rb', line 144 def to_instance_requirements req = component.to_instance_requirements req.select_service(model) req end |
#to_s ⇒ Object
134 135 136 |
# File 'lib/syskit/bound_data_service.rb', line 134 def to_s "#<BoundDataService: #{component.name}.#{model.name}>" end |
#to_task ⇒ Object
124 125 126 |
# File 'lib/syskit/bound_data_service.rb', line 124 def to_task component end |