Module: Syskit::Models

Extended by:
Logger::Forward, Logger::Hierarchy
Defined in:
lib/syskit/models/base.rb,
lib/syskit/models/port.rb,
lib/syskit/models/component.rb,
lib/syskit/models/deployment.rb,
lib/syskit/models/composition.rb,
lib/syskit/models/orogen_base.rb,
lib/syskit/models/placeholder.rb,
lib/syskit/models/port_access.rb,
lib/syskit/models/data_service.rb,
lib/syskit/models/task_context.rb,
lib/syskit/models/faceted_access.rb,
lib/syskit/models/deployment_group.rb,
lib/syskit/models/placeholder_task.rb,
lib/syskit/models/composition_child.rb,
lib/syskit/models/bound_data_service.rb,
lib/syskit/models/dynamic_data_service.rb,
lib/syskit/models/configured_deployment.rb,
lib/syskit/models/specialization_manager.rb,
lib/syskit/models/bound_dynamic_data_service.rb,
lib/syskit/models/composition_specialization.rb

Defined Under Namespace

Modules: Base, Component, Composition, Deployment, OrogenBase, Placeholder, PortAccess, ServiceModelsDefinitionDSL, TaskContext Classes: BoundDataService, BoundDynamicDataService, ComBusModel, CompositionChild, CompositionSpecialization, ConfiguredDeployment, DataServiceModel, DeploymentGroup, DeviceModel, DynamicDataService, FacetedAccess, InputPort, InputWriter, InvalidCompositionChildPort, OutputPort, OutputReader, Port, SpecializationManager

Constant Summary collapse

PlaceholderTask =
Placeholder

Class Method Summary collapse

Class Method Details

.create_orogen_deployment_model(*args) ⇒ Object



155
156
157
# File 'lib/syskit/models/base.rb', line 155

def self.create_orogen_deployment_model(*args)
    OroGen::Spec::Deployment.new(Roby.app.default_orogen_project, *args)
end

.create_orogen_task_context_model(*args) ⇒ Object



151
152
153
# File 'lib/syskit/models/base.rb', line 151

def self.create_orogen_task_context_model(*args)
    OroGen::Spec::TaskContext.new(Roby.app.default_orogen_project, *args)
end

.is_model?(m) ⇒ Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/syskit/models/base.rb', line 147

def self.is_model?(m)
    m.kind_of?(Syskit::Models::Base)
end

.merge_model_lists(a, b) ⇒ Object

Merges two lists of models into a single one.

The resulting list can only have a single class object. Modules that are already included in these classes get removed from the list as well

Raises:

  • (IncompatibleModelLists)

    if the two lists contain incompatible models



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/syskit/models/base.rb', line 119

def self.merge_model_lists(a, b)
    a_classes, a_modules = a.partition { |k| k.kind_of?(Class) }
    b_classes, b_modules = b.partition { |k| k.kind_of?(Class) }

    klass = a_classes.first || b_classes.first
    a_classes.concat(b_classes).each do |k|
        if k < klass
            klass = k
        elsif !(klass <= k)
            raise IncompatibleComponentModels.new(k, klass), "models #{k.short_name} and #{klass.short_name} are not compatible"
        end
    end

    result = Set.new
    result << klass if klass
    a_modules.concat(b_modules).each do |m|
        do_include = true
        result.delete_if do |other_m|
            do_include &&= !(other_m <= m)
            m < other_m
        end
        if do_include
            result << m
        end
    end
    result
end

.merge_orogen_task_context_models(target, interfaces, port_mappings = Hash.new) ⇒ Object

Merge the given orogen interfaces into one subclass



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/syskit/models/base.rb', line 97

def self.merge_orogen_task_context_models(target, interfaces, port_mappings = Hash.new)
    interfaces.each do |i|
        if i.name
            target.implements i.name
        end
        target.merge_ports_from(i, port_mappings)

        i.each_event_port do |port|
            target_name = port_mappings[port.name] || port.name
            target.port_driven target_name
        end
    end
end

.merge_port_mappings(a, b) ⇒ Object

Safe port mapping merging implementation

It verifies that there is no conflicting mappings, and if there are, raises Ambiguous



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

def self.merge_port_mappings(a, b)
    a.merge(b) do |source, target_a, target_b|
        if target_a != target_b
            raise Ambiguous, "merging conflicting port mappings: #{source} => #{target_a} and #{source} => #{target_b}"
        end
        target_a
    end
end

.update_port_mappings(result, new_mappings, old_mappings) ⇒ Object

Updates the port mappings in result by applying new_mappings on old_mappings

result and old_mappings map service models to the corresponding port mappings, of the form from => to

new_mappings is a new name mapping of the form from => to

The method updates result by applying new_mappings to the to fields in old_mappings, saving the resulting mappins in result



85
86
87
88
89
90
91
92
93
94
# File 'lib/syskit/models/base.rb', line 85

def self.update_port_mappings(result, new_mappings, old_mappings)
    old_mappings.each do |service, mappings|
        updated_mappings = Hash.new
        mappings.each do |from, to|
            updated_mappings[from] = new_mappings[to] || to
        end
        result[service] =
            Models.merge_port_mappings(result[service] || Hash.new, updated_mappings)
    end
end

.validate_model_name(name) ⇒ Object

Validates that the given name is a valid model name. Mainly, it makes sure that name is a valid constant Ruby name without namespaces

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/syskit/models/base.rb', line 49

def self.validate_model_name(name)
    if name =~ /::/
        raise ArgumentError, "model names cannot have sub-namespaces"
    end

    if !name.respond_to?(:to_str)
        raise ArgumentError, "expected a string as a model name, got #{name}"
    elsif !(name.camelcase(:upper) == name)
        raise ArgumentError, "#{name} is not a valid model name. Model names must start with an uppercase letter, and are usually written in UpperCamelCase"
    end
    name
end