Module: Syskit::PortAccess

Included in:
BoundDataService, Component, Composition
Defined in:
lib/syskit/port_access.rb

Overview

Mixin used to define common methods to enumerate ports on objects that have a model that includes Syskit::Models::PortAccess

Instance Method Summary collapse

Instance Method Details

#each_input_portObject

Enumerates this component's input ports



42
43
44
45
46
47
# File 'lib/syskit/port_access.rb', line 42

def each_input_port
    return enum_for(:each_input_port) if !block_given?
    model.each_input_port do |p|
        yield(p.bind(self))
    end
end

#each_output_portObject

Enumerates this component's output ports



34
35
36
37
38
39
# File 'lib/syskit/port_access.rb', line 34

def each_output_port
    return enum_for(:each_output_port) if !block_given?
    model.each_output_port do |p|
        yield(p.bind(self))
    end
end

#each_portObject

Enumerates all of this component's ports



50
51
52
53
54
# File 'lib/syskit/port_access.rb', line 50

def each_port
    return enum_for(:each_port) if !block_given?
    each_output_port { |p| yield(p) }
    each_input_port { |p| yield(p) }
end

#find_input_port(name) ⇒ Object

Returns the input port with the given name, or nil if it does not exist.



27
28
29
30
31
# File 'lib/syskit/port_access.rb', line 27

def find_input_port(name)
    if m = model.find_input_port(name)
        return m.bind(self)
    end
end

#find_output_port(name) ⇒ Object

Returns the output port with the given name, or nil if it does not exist.



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

def find_output_port(name)
    if m = model.find_output_port(name)
        return m.bind(self)
    end
end

#find_port(name) ⇒ Object

Returns the port object that maps to the given name, or nil if it does not exist.



7
8
9
10
# File 'lib/syskit/port_access.rb', line 7

def find_port(name)
    name = name.to_str
    find_output_port(name) || find_input_port(name)
end

#find_through_method_missing(m, args) ⇒ Object



75
76
77
78
# File 'lib/syskit/port_access.rb', line 75

def find_through_method_missing(m, args)
    MetaRuby::DSLs.find_through_method_missing(
        self, m, args, '_port' => :find_port) || super
end

#has_input_port?(name, including_dynamic = true) ⇒ Boolean

Returns true if name is a valid input port name for instances of self. If including_dynamic is set to false, only static ports will be considered

Returns:

  • (Boolean)


66
67
68
# File 'lib/syskit/port_access.rb', line 66

def has_input_port?(name, including_dynamic = true)
    return !!find_input_port(name)
end

#has_output_port?(name, including_dynamic = true) ⇒ Boolean

Returns true if name is a valid output port name for instances of self. If including_dynamic is set to false, only static ports will be considered

Returns:

  • (Boolean)


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

def has_output_port?(name, including_dynamic = true)
    return !!find_output_port(name)
end

#has_port?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_port?(name)
    name = name.to_str
    has_input_port?(name) || has_output_port?(name)
end

#has_through_method_missing?(m) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'lib/syskit/port_access.rb', line 70

def has_through_method_missing?(m)
    MetaRuby::DSLs.has_through_method_missing?(
        self, m, '_port' => :has_port?) || super
end