Class: OroGen::Loaders::Aggregate

Inherits:
Base
  • Object
show all
Defined in:
lib/orogen/loaders/aggregate.rb

Overview

A launcher that aggregates other launchers

Defined Under Namespace

Classes: DuplicateLoader

Instance Attribute Summary collapse

Attributes inherited from Base

#interface_typelist, #loaded_deployment_models, #loaded_projects, #loaded_task_models, #loaded_typekits, #project_load_callbacks, #registry, #root_loader, #typekit_load_callbacks, #typekits_by_type_name

Instance Method Summary collapse

Methods inherited from Base

#define_dummy_types=, #define_dummy_types?, #deployed_task_model_from_name, #has_loaded_project?, #has_loaded_typekit?, #imported_typekits_for, #inspect, #interface_type?, #intermediate_type?, #intermediate_type_for, #m_type?, #on_project_load, #on_typekit_load, #opaque_type_for, #project_model_from_text, #register_deployment_model, #register_project_model, #register_task_context_model, #register_type_model, #register_typekit_model, #remove_project_load_callback, #resolve_interface_type, #resolve_type, #task_library_model_from_name, #typekit_model_text_from_name, #typelib_type_for

Constructor Details

#initialize(root_loader = self) ⇒ Aggregate

Returns a new instance of Aggregate



10
11
12
13
# File 'lib/orogen/loaders/aggregate.rb', line 10

def initialize(root_loader = self)
    @loaders = Array.new
    super(root_loader)
end

Instance Attribute Details

#loadersArray (readonly)

Returns:

  • (Array)


8
9
10
# File 'lib/orogen/loaders/aggregate.rb', line 8

def loaders
  @loaders
end

Instance Method Details

#add(loader) ⇒ Object



26
27
28
29
30
31
# File 'lib/orogen/loaders/aggregate.rb', line 26

def add(loader)
    if loaders.include?(loader)
        raise DuplicateLoader, "#{loader} is already a child of #{self}"
    end
    @loaders << loader
end

#added_child(loader) ⇒ Object



15
16
17
# File 'lib/orogen/loaders/aggregate.rb', line 15

def added_child(loader)
    add(loader)
end

#clearObject



19
20
21
22
23
24
# File 'lib/orogen/loaders/aggregate.rb', line 19

def clear
    super
    loaders.each do |l|
        l.clear
    end
end

#deployment_model_from_name(name) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/orogen/loaders/aggregate.rb', line 182

def deployment_model_from_name(name)
    if deployment = loaded_deployment_models[name]
        return deployment
    end

    OroGen::Loaders.debug do
        "Aggregate: resolving deployment #{name} on #{loaders.map(&:to_s).join(",")}"
    end

    loaders.each do |l|
        begin
            # We assume that the sub-loaders are created with self
            # as root loader. They will therefore register
            # themselves on self
            return l.deployment_model_from_name(name)
        rescue DeploymentModelNotFound => e
            Loaders.debug "  not available on #{l}: #{e}"
        end
    end
    raise DeploymentModelNotFound, "there is no deployment named #{name} on #{self}"
end

#each_available_project_name {|project_name| ... } ⇒ Object

Enumerates the names of all available projects

Yield Parameters:

  • project_name (String)


168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/orogen/loaders/aggregate.rb', line 168

def each_available_project_name
    return enum_for(__method__) if !block_given?
    seen = Set.new
    loaders.each do |l|
        l.each_available_project_name do |name|
            if !seen.include?(name)
                seen << name
                yield(name)
            end
        end
    end
    nil
end

#find_deployments_from_deployed_task_name(name) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/orogen/loaders/aggregate.rb', line 104

def find_deployments_from_deployed_task_name(name)
    loaders.each do |l|
        next if !l.respond_to?(:find_deployments_from_deployed_task_name)
        if deployment_name = l.find_deployments_from_deployed_task_name(name)
            return deployment_name
        end
    end
    nil
end

#find_project_from_deployment_name(name) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/orogen/loaders/aggregate.rb', line 94

def find_project_from_deployment_name(name)
    loaders.each do |l|
        next if !l.respond_to?(:find_project_from_deployment_name)
        if project_name = l.find_project_from_deployment_name(name)
            return project_name
        end
    end
    nil
end

#find_task_library_from_task_model_name(name) ⇒ Object

Raises:

  • (NotImplementedError)


90
91
92
# File 'lib/orogen/loaders/aggregate.rb', line 90

def find_task_library_from_task_model_name(name)
    raise NotImplementedError
end

#has_project?(name) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/orogen/loaders/aggregate.rb', line 161

def has_project?(name)
    super || loaders.any? { |l| l.has_project?(name) }
end

#has_typekit?(name) ⇒ Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/orogen/loaders/aggregate.rb', line 157

def has_typekit?(name)
    super || loaders.any? { |l| l.has_typekit?(name) }
end

#project_model_from_name(name) ⇒ Object

Raises:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/orogen/loaders/aggregate.rb', line 52

def project_model_from_name(name)
    if project = loaded_projects[name]
        return project
    end

    OroGen::Loaders.debug "Aggregate: resolving #{name} on #{loaders.map(&:to_s).join(",")}"
    loaders.each do |l|
        begin
            # We assume that the sub-loaders are created with self
            # as root loader. They will therefore register
            # themselves on self
            return l.project_model_from_name(name)
        rescue ProjectNotFound => e
            Loaders.debug "  not available on #{l}: #{e}"
        end
    end
    raise ProjectNotFound, "there is no project named #{name} on #{self}"
end

#project_model_text_from_name(name) ⇒ Object

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/orogen/loaders/aggregate.rb', line 37

def project_model_text_from_name(name)
    OroGen::Loaders.debug "Aggregate: resolving #{name} on #{loaders.map(&:to_s).join(",")}"
    loaders.each do |l|
        begin
            # We assume that the sub-loaders are created with self
            # as root loader. They will therefore register
            # themselves on self
            return l.project_model_text_from_name(name)
        rescue ProjectNotFound => e
            Loaders.debug "  not available on #{l}: #{e}"
        end
    end
    raise ProjectNotFound, "there is no project named #{name} on #{self}"
end

#remove(loader) ⇒ Object



33
34
35
# File 'lib/orogen/loaders/aggregate.rb', line 33

def remove(loader)
    @loaders.delete loader
end

#task_model_from_name(name) ⇒ Object

Raises:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/orogen/loaders/aggregate.rb', line 71

def task_model_from_name(name)
    if model = loaded_task_models[name]
        return model
    end

    OroGen::Loaders.debug "Aggregate: resolving task model #{name} on #{loaders.map(&:to_s).join(",")}"
    loaders.each do |l|
        begin
            # We assume that the sub-loaders are created with self
            # as root loader. They will therefore register
            # themselves on self
            return loaded_task_models[name] = l.task_model_from_name(name)
        rescue ProjectNotFound => e
            Loaders.debug "  not available on #{l}: #{e}"
        end
    end
    raise TaskModelNotFound, "there is no task model named #{name} on #{self}"
end

#to_sObject



204
205
206
# File 'lib/orogen/loaders/aggregate.rb', line 204

def to_s
    "#<#{self.class.name}(#{object_id.to_s(16)}): #{loaders.map(&:to_s).join(",")}>"
end

#typekit_for(type, exported = true) ⇒ Object

Raises:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/orogen/loaders/aggregate.rb', line 131

def typekit_for(type, exported = true)
    typename = if type.respond_to?(:name)
                   type.name
               else type
               end

    if typekits = typekits_by_type_name[typename]
        if exported
            if export_tk = typekits.find_all { |tk| tk.interface_type?(typename) }.first
                return export_tk
            end
        else
            return typekits.first
        end
    end

    loaders.each do |l|
        next if !l.respond_to?(:typekit_for)
        begin
            return l.typekit_for(type, exported)
        rescue NotExportedType, NotTypekitType
        end
    end
    raise NotTypekitType.new(type), "#{type} is not defined by any typekit known to #{self}"
end

#typekit_model_from_name(name) ⇒ Object

Raises:



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/orogen/loaders/aggregate.rb', line 114

def typekit_model_from_name(name)
    if typekit = loaded_typekits[name]
        return typekit
    end

    loaders.each do |l|
        begin
            # We assume that the sub-loaders are created with self
            # as root loader. They will therefore register
            # themselves on self
            return l.typekit_model_from_name(name)
        rescue TypekitNotFound
        end
    end
    raise TypekitNotFound, "there is no typekit named #{name} on #{self}"
end