Class: Syskit::Port

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

Overview

Representation of a component port on a component instance.

The sibling class Syskit::Models::Port represents a port on a component model. For instance, an object of class Syskit::Models::Port could be used to represent a port on a subclass of TaskContext while Syskit::Port would represent it for an object of that subclass.

Direct Known Subclasses

InputPort, OutputPort

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, component) ⇒ Port

Returns a new instance of Port



25
26
27
# File 'lib/syskit/port.rb', line 25

def initialize(model, component)
    @model, @component = model, component
end

Instance Attribute Details

#componentObject (readonly)

The component model this port is part of



13
14
15
# File 'lib/syskit/port.rb', line 13

def component
  @component
end

#modelModels::Port (readonly)

The port model

Returns:



11
12
13
# File 'lib/syskit/port.rb', line 11

def model
  @model
end

Instance Method Details

#==(other_port) ⇒ Object



19
20
21
22
23
# File 'lib/syskit/port.rb', line 19

def ==(other_port)
    other_port.class == self.class &&
        other_port.model == self.model &&
        other_port.component == self.component
end

#connect_to(in_port, policy = Hash.new) ⇒ Object

Connects this port to the other given port, using the given policy



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/syskit/port.rb', line 75

def connect_to(in_port, policy = Hash.new)
    out_port = self.to_component_port
    if out_port == self
        if in_port.respond_to?(:to_component_port)
            in_port = in_port.to_component_port
            if !output?
                raise WrongPortConnectionDirection.new(self, in_port), "cannot connect #{self} to #{in_port}: #{self} is not an output port"
            elsif !in_port.input?
                raise WrongPortConnectionDirection.new(self, in_port), "cannot connect #{self} to #{in_port}: #{in_port} is not an input port"
            elsif component == in_port.component
                raise SelfConnection.new(self, in_port), "cannot connect #{self} to #{in_port}: they are both ports of the same component"
            elsif self.type != in_port.type
                raise WrongPortConnectionTypes.new(self, in_port), "cannot connect #{self} to #{in_port}: types mismatch"
            end
            component.connect_ports(in_port.component, [name, in_port.name] => policy)
        else
            Syskit.connect self, in_port, policy
        end

    else
        out_port.connect_to(in_port, policy)
    end
end

#connected?Boolean

Returns:

  • (Boolean)


135
136
137
138
# File 'lib/syskit/port.rb', line 135

def connected?
    each_connection { return true }
    false
end

#connected_to?(in_port) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
113
114
115
116
117
118
# File 'lib/syskit/port.rb', line 109

def connected_to?(in_port)
    out_port = self.to_component_port
    if out_port == self
        in_port = in_port.to_component_port
        component.child_object?(in_port.component, Flows::DataFlow) &&
            component[in_port.component, Flows::DataFlow].has_key?([out_port.name, in_port.name])
    else
        out_port.connected_to?(in_port)
    end
end

#disconnect_from(in_port) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/syskit/port.rb', line 99

def disconnect_from(in_port)
    out_port = self.to_component_port
    if out_port == self
        in_port = in_port.to_component_port
        component.disconnect_ports(in_port.component, [[out_port.name, in_port.name]])
    else
        out_port.disconnect_from(in_port)
    end
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/syskit/port.rb', line 30

def eql?(other)
    self == other
end

#hashObject



29
# File 'lib/syskit/port.rb', line 29

def hash; component.hash | name.hash end

#input?Boolean

Returns true if this is an input port, false otherwise. The default implementation returns false

Returns:

  • (Boolean)

    true if this is an input port, false otherwise. The default implementation returns false



129
# File 'lib/syskit/port.rb', line 129

def input?; false end

#inspectObject



34
# File 'lib/syskit/port.rb', line 34

def inspect; to_s end

#nameObject

The port name



15
# File 'lib/syskit/port.rb', line 15

def name; model.name end

#new_sampleObject



120
121
122
# File 'lib/syskit/port.rb', line 120

def new_sample
    model.new_sample
end

#output?Boolean

Returns true if this is an output port, false otherwise. The default implementation returns false

Returns:

  • (Boolean)

    true if this is an output port, false otherwise. The default implementation returns false



126
# File 'lib/syskit/port.rb', line 126

def output?; false end

#pretty_print(pp) ⇒ Object



35
36
37
38
# File 'lib/syskit/port.rb', line 35

def pretty_print(pp)
    pp.text "port #{name} of "
    component.pretty_print(pp)
end

#static?Boolean

Returns:

  • (Boolean)


140
# File 'lib/syskit/port.rb', line 140

def static?; model.orogen_model.static? end

#to_actual_portPort

Returns the port attached to a TaskContext instance that corresponds to self

Returns:

  • (Port)

    the resolved port

Raises:

  • (ArgumentError)

    if it is not possible (for instance, ports on InstanceRequirements are not associated with a component port)



59
60
61
62
# File 'lib/syskit/port.rb', line 59

def to_actual_port
    component_port = to_component_port
    component_port.component.self_port_to_actual_port(component_port)
end

#to_component_portPort

Returns the port attached to a proper Component instance that corresponds to self

Returns:

  • (Port)

    the resolved port

Raises:

  • (ArgumentError)

    if it is not possible (for instance, ports on InstanceRequirements are not associated with a component port)



46
47
48
49
50
51
# File 'lib/syskit/port.rb', line 46

def to_component_port
    if !component.respond_to?(:self_port_to_component_port)
        raise ArgumentError, "cannot call #to_component_port on ports of #{component}"
    end
    component.self_port_to_component_port(self)
end

#to_orocos_portOrocos::Port

Returns the orocos port attached that corresponds to self

Returns:

  • (Orocos::Port)

    the resolved port

Raises:

  • (ArgumentError)

    if it is not possible (for instance, ports on InstanceRequirements are not associated with a component port)



69
70
71
72
# File 'lib/syskit/port.rb', line 69

def to_orocos_port
    component_port = to_actual_port
    component_port.component.self_port_to_orocos_port(component_port)
end

#to_sObject



131
132
133
# File 'lib/syskit/port.rb', line 131

def to_s
    "#{component}.#{name}"
end

#typeObject

The port type



17
# File 'lib/syskit/port.rb', line 17

def type; model.type end