Class: OroGen::Loaders::Files

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

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

#added_child, #define_dummy_types?, #deployed_task_model_from_name, #find_deployments_from_deployed_task_name, #has_loaded_project?, #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_name, #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, #task_model_from_name, #typekit_model_from_name, #typelib_type_for

Constructor Details

#initialize(root_loader = self) ⇒ Files


7
8
9
10
11
# File 'lib/orogen/loaders/files.rb', line 7

def initialize(root_loader = self)
    @available_projects = Hash.new
    @available_typekits = Hash.new
    super
end

Instance Attribute Details

#available_projectsObject (readonly)

Returns the value of attribute available_projects


4
5
6
# File 'lib/orogen/loaders/files.rb', line 4

def available_projects
  @available_projects
end

#available_typekitsObject (readonly)

Returns the value of attribute available_typekits


5
6
7
# File 'lib/orogen/loaders/files.rb', line 5

def available_typekits
  @available_typekits
end

Instance Method Details

#clearObject


13
14
15
16
17
# File 'lib/orogen/loaders/files.rb', line 13

def clear
    @available_projects.clear
    @available_typekits.clear
    super
end

#deployment_model_from_name(name) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/orogen/loaders/files.rb', line 55

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

    each_project do |project|
        if m = project.find_deployment_by_name(name)
            loaded_deployment_models[name] = m
            return m
        end
    end
    raise DeploymentModelNotFound, "there is no deployment called #{name} on #{self}"
end

#each_available_deployment_name(&block) ⇒ Object


119
120
121
122
123
124
125
126
127
# File 'lib/orogen/loaders/files.rb', line 119

def each_available_deployment_name(&block)
    return enum_for(__method__) if !block_given?
    each_project do |project|
        project.each_deployment do |spec|
            yield(spec.name)
        end
    end
    nil
end

#each_available_project_name(&block) ⇒ Object


111
112
113
# File 'lib/orogen/loaders/files.rb', line 111

def each_available_project_name(&block)
    return available_projects.each_key(&block)
end

#each_available_typekit_name(&block) ⇒ Object


115
116
117
# File 'lib/orogen/loaders/files.rb', line 115

def each_available_typekit_name(&block)
    return available_typekits.each_key(&block)
end

#each_projectObject


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/orogen/loaders/files.rb', line 77

def each_project
    return enum_for(__method__) if !block_given?

    available_projects.each_key do |project_name|
        project = begin
                      root_loader.project_model_from_name(project_name)
                  rescue Exception => e
                      OroGen.warn "could not load #{project_name}: #{e.message}"
                      next
                  end

        yield(project)
    end
    nil
end

#find_project_from_deployment_name(name) ⇒ Object


102
103
104
105
106
107
108
109
# File 'lib/orogen/loaders/files.rb', line 102

def find_project_from_deployment_name(name)
    each_project do |project|
        if project.find_deployment_by_name(name)
            return project.name
        end
    end
    nil
end

#find_task_library_from_task_model_name(name) ⇒ Object


93
94
95
96
97
98
99
100
# File 'lib/orogen/loaders/files.rb', line 93

def find_task_library_from_task_model_name(name)
    each_project do |project|
        if project.find_task_context(name)
            return project.name
        end
    end
    nil
end

#has_project?(name) ⇒ Boolean


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

def has_project?(name)
    available_projects.has_key?(name)
end

#has_typekit?(name) ⇒ Boolean


37
38
39
# File 'lib/orogen/loaders/files.rb', line 37

def has_typekit?(name)
    available_typekits.has_key?(name)
end

#project_model_text_from_name(name) ⇒ Object


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

def project_model_text_from_name(name)
    path = available_projects[name]
    if !path
        raise ProjectNotFound, "no project called #{name} on #{self}"
    end

    return File.read(path), path
end

#register_orogen_file(path, name = nil) ⇒ Object


19
20
21
22
# File 'lib/orogen/loaders/files.rb', line 19

def register_orogen_file(path, name = nil)
    name ||= File.basename(path, ".orogen")
    available_projects[name] = path
end

#register_typekit(path, name) ⇒ Object


41
42
43
44
45
# File 'lib/orogen/loaders/files.rb', line 41

def register_typekit(path, name)
    typelist = File.join(path, "#{name}.typelist")
    tlb      = File.join(path, "#{name}.tlb")
    available_typekits[name] = [typelist, tlb]
end

#to_sObject


73
74
75
# File 'lib/orogen/loaders/files.rb', line 73

def to_s;
    "#<OroGen::Loaders::Files(#{object_id.to_s(16)}) projects=#{available_projects.keys.sort.join(",")} typekits=#{available_typekits.keys.sort.join(",")}>"
end

#typekit_model_text_from_name(name) ⇒ Object


47
48
49
50
51
52
53
# File 'lib/orogen/loaders/files.rb', line 47

def typekit_model_text_from_name(name)
    typelist, tlb = available_typekits[name]
    if !typelist
        raise TypekitNotFound, "#{self} has not typekit named #{name}"
    end
    return File.read(tlb), File.read(typelist)
end