Class: Syskit::BoundDataService

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#componentComponent (readonly)

Returns The component instance we are bound to

Returns:

  • (Component)

    The component instance we are bound to



18
19
20
# File 'lib/syskit/bound_data_service.rb', line 18

def component
  @component
end

#modelModels::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_planObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

#hashObject



33
34
35
# File 'lib/syskit/bound_data_service.rb', line 33

def hash
    [self.class, component, model].hash
end

#inspectObject



138
# File 'lib/syskit/bound_data_service.rb', line 138

def inspect; to_s end

#nameString

The data service name

Returns:

  • (String)


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

Parameters:

Returns:

  • (Syskit::Port)

    a port in which Port#component is guaranteed to be a proper component (e.g. not BoundDataService)



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_modelObject

Returns the data service model

See Also:



50
51
52
# File 'lib/syskit/bound_data_service.rb', line 50

def service_model
    model.model
end

#short_nameObject



77
78
79
# File 'lib/syskit/bound_data_service.rb', line 77

def short_name
    "#{component}:#{model.short_name}"
end

#to_instance_requirementsSyskit::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_sObject



134
135
136
# File 'lib/syskit/bound_data_service.rb', line 134

def to_s
    "#<BoundDataService: #{component.name}.#{model.name}>"
end

#to_taskObject



124
125
126
# File 'lib/syskit/bound_data_service.rb', line 124

def to_task
    component
end