Module: Syskit::Models::PortAccess

Included in:
BoundDataService, Composition, DataServiceModel, TaskContext
Defined in:
lib/syskit/models/port_access.rb

Overview

Mixin used to define common methods to enumerate ports on objects that have an attribute #orogen_model of type Orocos::Spec::TaskContext

Instance Method Summary collapse

Instance Method Details

#each_input_portObject

Enumerates this component's input ports



67
68
69
70
71
72
# File 'lib/syskit/models/port_access.rb', line 67

def each_input_port
    return enum_for(:each_input_port) if !block_given?
    orogen_model.each_input_port do |p|
        yield(ports[p.name] ||= InputPort.new(self, p))
    end
end

#each_output_portObject

Enumerates this component's output ports



59
60
61
62
63
64
# File 'lib/syskit/models/port_access.rb', line 59

def each_output_port
    return enum_for(:each_output_port) if !block_given?
    orogen_model.each_output_port do |p|
        yield(ports[p.name] ||= OutputPort.new(self, p))
    end
end

#each_port(&block) ⇒ Object

Enumerates all of this component's ports



52
53
54
55
56
# File 'lib/syskit/models/port_access.rb', line 52

def each_port(&block)
    return enum_for(:each_port) if !block_given?
    each_output_port(&block)
    each_input_port(&block)
end

#find_input_port(name) ⇒ Object

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



44
45
46
47
48
49
# File 'lib/syskit/models/port_access.rb', line 44

def find_input_port(name)
    name = name.to_str
    if port_model = orogen_model.find_input_port(name)
        ports[name] ||= InputPort.new(self, port_model)
    end
end

#find_output_port(name) ⇒ Object

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



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

def find_output_port(name)
    name = name.to_str
    if port_model = orogen_model.find_output_port(name)
        ports[name] ||= OutputPort.new(self, port_model)
    end
end

#find_port(name) ⇒ Object

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



21
22
23
24
# File 'lib/syskit/models/port_access.rb', line 21

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

#find_through_method_missing(m, args) ⇒ Object



14
15
16
17
# File 'lib/syskit/models/port_access.rb', line 14

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

#has_dynamic_input_port?(name, type = nil) ⇒ Boolean

True if name could be a dynamic input port name.

Dynamic input ports are declared on the task models using the #dynamic_input_port statement, e.g.:

data_service do
    dynamic_input_port /name_pattern\w+/, "/std/string"
end

One can then match if a given string (name) matches one of the dynamic input port declarations using this predicate.

Returns:

  • (Boolean)


128
129
130
131
132
133
# File 'lib/syskit/models/port_access.rb', line 128

def has_dynamic_input_port?(name, type = nil)
    if type
        type = Roby.app.default_loader.opaque_type_for(type)
    end
    orogen_model.has_dynamic_input_port?(name, type)
end

#has_dynamic_output_port?(name, type = nil) ⇒ Boolean

True if name could be a dynamic output port name.

Dynamic output ports are declared on the task models using the #dynamic_output_port statement, e.g.:

data_service do
    dynamic_output_port /name_pattern\w+/, "/std/string"
end

One can then match if a given string (name) matches one of the dynamic output port declarations using this predicate.

Returns:

  • (Boolean)


110
111
112
113
114
115
# File 'lib/syskit/models/port_access.rb', line 110

def has_dynamic_output_port?(name, type = nil)
    if type
        type = Roby.app.default_loader.opaque_type_for(type)
    end
    orogen_model.has_dynamic_output_port?(name, type)
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)


92
93
94
95
96
97
# File 'lib/syskit/models/port_access.rb', line 92

def has_input_port?(name, including_dynamic = true)
    return true if find_input_port(name)
    if including_dynamic
        has_dynamic_input_port?(name)
    end
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)


82
83
84
85
86
87
# File 'lib/syskit/models/port_access.rb', line 82

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

#has_port?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


10
11
12
13
# File 'lib/syskit/models/port_access.rb', line 10

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

#port_by_name(name) ⇒ Object



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

def port_by_name(name)
    if p = find_port(name)
        p
    else raise ArgumentError, "#{self} has no port called #{name}, known ports are: #{each_port.map(&:name).sort.join(", ")}"
    end
end