Class: Rock::Inspect
- Inherits:
-
Object
- Object
- Rock::Inspect
- Defined in:
- lib/rock/rock_inspect.rb
Class Attribute Summary collapse
-
.debug ⇒ Object
Returns the value of attribute debug.
Class Method Summary collapse
- .deployment_match?(deployment, pattern, filter = Hash.new) ⇒ Boolean
- .find(pattern, filter = Hash.new) ⇒ Object
- .find_deployments(pattern, filter = Hash.new) ⇒ Object
- .find_plugins(pattern, filter = Hash.new) ⇒ Object
- .find_ports(pattern, filter = Hash.new) ⇒ Object
- .find_projects(pattern, filter = Hash.new) ⇒ Object
- .find_tasks(pattern, filter = Hash.new) ⇒ Object
- .find_types(pattern, filter = Hash.new) ⇒ Object
- .load_orogen_project(loader, name, debug) ⇒ Object
- .load_orogen_typekit(loader, name, debug) ⇒ Object
- .orogen_loader ⇒ Object
- .port_match?(port, pattern, filter = Hash.new) ⇒ Boolean
- .project_match?(project_name, pattern, filter = Hash.new) ⇒ Boolean
- .task_match?(task, pattern, filter = Hash.new) ⇒ Boolean
- .type_match?(type, pattern, filter = Hash.new) ⇒ Boolean
Class Attribute Details
.debug ⇒ Object
Returns the value of attribute debug
35 36 37 |
# File 'lib/rock/rock_inspect.rb', line 35 def debug @debug end |
Class Method Details
.deployment_match?(deployment, pattern, filter = Hash.new) ⇒ Boolean
258 259 260 261 262 263 |
# File 'lib/rock/rock_inspect.rb', line 258 def self.deployment_match?(deployment,pattern,filter = Hash.new) return false if (!(deployment.name =~ pattern)) return false if (filter.has_key?(:deployments) && !(deployment.name =~ filter[:deployments])) return false if (deployment.task_activities.all?{|t| !( task_match?(t.task_model,//,filter))}) true end |
.find(pattern, filter = Hash.new) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rock/rock_inspect.rb', line 79 def self.find(pattern,filter = Hash.new) , filter = Kernel::(filter,[:no_types,:no_ports,:no_tasks,:no_deployments,:no_projects,:no_plugins,:no_plugins,:no_widgets]) result = Array.new #search for types #we are not searching for types all the time if ![:no_types] reg = filter.has_key?(:types) ? filter[:types] : pattern reg = /./ unless reg result += Rock::Inspect::find_types(/#{reg}/,filter) end #search for ports if ![:no_ports] reg = filter.has_key?(:ports) ? filter[:ports] : pattern reg = /./ unless reg result += Rock::Inspect::find_ports(/#{reg}/,filter) end #search for tasks if ![:no_tasks] reg = (filter[:tasks] || pattern || /./) result += Rock::Inspect::find_tasks(/#{reg}/, filter) end #search for deployments if ![:no_deployments] reg = filter.has_key?(:deployments) ? filter[:deployments] : pattern reg = /./ unless reg result += Rock::Inspect::find_deployments(/#{reg}/,filter) end #search for plugins if ![:no_plugins] reg = filter.has_key?(:plugins) ? filter[:plugins] : pattern reg = /./ unless reg result += Rock::Inspect::find_plugins(/#{reg}/, filter) end # Search for projects that have no tasks, but only deployments defined # Last entry before producing the result, to allow operation on the # already contrained project list if ![:no_projects] reg = filter.has_key?(:projects) ? filter[:projects] : pattern reg = /./ unless reg result += Rock::Inspect::find_projects(/#{reg}/,filter) end result.uniq.sort_by(&:name) end |
.find_deployments(pattern, filter = Hash.new) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/rock/rock_inspect.rb', line 191 def self.find_deployments(pattern,filter=Hash.new) found = [] filter,unkown = Kernel::(filter,[:types,:ports,:tasks,:deployments]) return found if !unkown.empty? orogen_loader.each_available_project_name do |project_name| project = load_orogen_project(orogen_loader, project_name, Rock::Inspect::debug) project.deployers.values.each do |deployer| if pattern === deployer.name || pattern === project.name || deployer.task_activities.find { |t| pattern === t.name || pattern === t.task_model.name } found << SearchItem.new(:name => "Deployment::#{deployer.name}", :project_name => project_name, :object => deployer) end end end found.sort_by{|t|t.name} end |
.find_plugins(pattern, filter = Hash.new) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/rock/rock_inspect.rb', line 243 def self.find_plugins(pattern,filter=Hash.new) found = [] filter,unkown = Kernel::(filter,[:plugin_name,:types]) return found if !unkown.empty? specs = Vizkit.default_loader.plugin_specs specs.each_value do |spec| next if filter.has_key?(:plugin_name) && nil == (spec.plugin_name =~ filter[:plugin_name]) if((spec2 = spec.callback_specs.find(){|callback|callback.argument =~ pattern}) || spec.plugin_name =~ pattern) next if filter.has_key?(:types) && (!spec2 ||nil == (spec2.argument =~ filter[:types])) found << SearchItem.new(:name => spec.plugin_name, :object => spec) end end found.sort_by{|t|t.name} end |
.find_ports(pattern, filter = Hash.new) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/rock/rock_inspect.rb', line 151 def self.find_ports(pattern,filter = Hash.new) found = [] filter,unkown = Kernel::(filter,[:types,:ports]) return found if !unkown.empty? #find all tasks which are matching the pattern orogen_loader.each_available_task_model_name.each do |name, project_name| if tasklib = load_orogen_project(orogen_loader, project_name, Rock::Inspect::debug) tasklib.self_tasks.each_value do |task| task.each_port do |port| if(port_match?(port,pattern,filter)) found << SearchItem.new(:name => "Port::#{port.name}", :project_name => project_name, :object => port) break end end end end end found.sort_by{|t|t.name} end |
.find_projects(pattern, filter = Hash.new) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/rock/rock_inspect.rb', line 210 def self.find_projects(pattern, filter=Hash.new) found = [] filter,unknown = Kernel::(filter,[:types,:ports,:tasks,:deployments,:projects]) return found if !unknown.empty? # Check whether there have been already search filters set, # meaning that the resulting project list should be a subset of those use_whitelist = false if !(filter.has_key?(:projects) && filter.size == 1) use_whitelist = true end # Either use all available projects or subset, as defined by the previous contrains if use_whitelist projects = found.map(&:name) else projects = orogen_loader.each_available_project_name.to_a end projects.each do |name| if project_match?(name,pattern,filter) if tasklib = load_orogen_project(orogen_loader, name, Rock::Inspect::debug) tasklib.deployers.each do |deployment| found << SearchItem.new(:name => "Deployment::#{deployment.name}", :project_name => name, :object => deployment) end end end end found.sort_by{|t|t.name} end |
.find_tasks(pattern, filter = Hash.new) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rock/rock_inspect.rb', line 130 def self.find_tasks(pattern,filter = Hash.new) found = [] filter,unkown = Kernel::(filter,[:types,:ports,:tasks]) return found if !unkown.empty? #find all tasks which are matching the pattern orogen_loader.each_available_task_model_name do |name, project_name| if name =~ pattern || project_name =~ pattern if tasklib = load_orogen_project(orogen_loader, project_name, Rock::Inspect::debug) task = tasklib.self_tasks.values.find { |t| t.name == name } if(task_match?(task,pattern,filter)) found << SearchItem.new(:name => "TaskContext::#{task.name}", :project_name => project_name, :object => task) end end end end found.sort_by{|t|t.name} end |
.find_types(pattern, filter = Hash.new) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/rock/rock_inspect.rb', line 173 def self.find_types(pattern,filter = Hash.new) found = Array.new filter,unkown = Kernel::(filter,[:types]) return found if !unkown.empty? orogen_loader.each_available_type_name do |type_name, typekit_name, exported| if pattern === type_name orogen_loader.typekit_model_from_name(typekit_name) object = orogen_loader.resolve_type(type_name) if type_match?(object,pattern,filter) found << SearchItem.new(:name => "Type::#{type_name}", :project_name => typekit_name, :object => object) end end end found.sort_by{|t|t.name} end |
.load_orogen_project(loader, name, debug) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rock/rock_inspect.rb', line 65 def self.load_orogen_project(loader, name, debug) begin loader.project_model_from_name(name) rescue Interrupt; raise rescue Exception => e if Rock::Inspect::debug raise end Orocos.warn "cannot load the installed oroGen project #{name}" Orocos.warn " #{e.}" nil end end |
.load_orogen_typekit(loader, name, debug) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rock/rock_inspect.rb', line 51 def self.load_orogen_typekit(loader, name, debug) begin loader.typekit_model_from_name(name) rescue Interrupt; raise rescue Exception => e if Rock::Inspect::debug raise end Orocos.warn "cannot load the installed oroGen typekit #{name}" Orocos.warn " #{e.}" nil end end |
.orogen_loader ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/rock/rock_inspect.rb', line 42 def self.orogen_loader if !@orogen_loader loader = OroGen::Loaders::PkgConfig.new(OroGen.orocos_target) OroGen::Loaders::RTT.setup_loader(loader) @orogen_loader = loader end @orogen_loader end |
.port_match?(port, pattern, filter = Hash.new) ⇒ Boolean
275 276 277 278 279 280 281 |
# File 'lib/rock/rock_inspect.rb', line 275 def self.port_match?(port,pattern,filter = Hash.new) return false if (!(port.name =~ pattern) && !(port.type_name =~ pattern)) return false if (filter.has_key?(:tasks) && !(port.task.name =~ filter[:tasks])) return false if (filter.has_key?(:ports) && !(port.name =~ filter[:ports])) return false if (filter.has_key?(:types) && !(port.type_name =~ filter[:types])) true end |
.project_match?(project_name, pattern, filter = Hash.new) ⇒ Boolean
265 266 267 268 269 |
# File 'lib/rock/rock_inspect.rb', line 265 def self.project_match?(project_name,pattern,filter = Hash.new) return true if (project_name =~ pattern) return true if (filter.has_key?(:projects) && (project_name =~ filter[:projects])) false end |
.task_match?(task, pattern, filter = Hash.new) ⇒ Boolean
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/rock/rock_inspect.rb', line 283 def self.task_match?(task,pattern,filter= Hash.new) return false unless task.name =~ pattern return false if(filter.has_key?(:tasks) && !(task.name =~ filter[:tasks])) has_port = false #we have to disable the filter :task otherwise there will be trouble with subclasses old = filter.delete :tasks task.each_port {|port| has_port = true if(port_match?(port,//,filter))} return false if !has_port filter[:tasks] = old if old if filter.has_key? :types has_type= false task.each_port {|port| has_type = true if(port.type_name =~ filter[:types])} task.each_property {|property| has_type = true if(property.type_name.to_s =~ filter[:types])} task.each_attribute {|attribute| has_type = true if(attribute.type_name.to_s =~ filter[:types])} return false if !has_type end #return false if(filter.has_key?(:deployments) && !(task.name =~ filter[:tasks])) true end |
.type_match?(type, pattern, filter = Hash.new) ⇒ Boolean
271 272 273 |
# File 'lib/rock/rock_inspect.rb', line 271 def self.type_match?(type,pattern,filter = Hash.new) true end |