Class: Orocos::ProcessBase
- Inherits:
-
Object
- Object
- Orocos::ProcessBase
- Defined in:
- lib/orocos/process.rb
Overview
Base class for process representation objects
Direct Known Subclasses
Process, ROS::LauncherProcess, RemoteProcesses::Process, RubyTasks::Process
Constant Summary collapse
- @@logfile_indexes =
Hash.new
Instance Attribute Summary collapse
-
#default_logger ⇒ #log, false
The logger object that should be used, by default, to log data coming out of this process, or false if none can be found.
-
#logged_ports ⇒ Object
readonly
The set of [task_name, port_name] that represent the ports being currently logged by this process' default logger.
-
#model ⇒ OroGen::Spec::Deployment
readonly
The deployment oroGen model.
-
#name ⇒ String
readonly
The process name.
-
#name_mappings ⇒ Object
A set of mappings from task names in the deployment model to the actual name in the running process.
-
#tasks ⇒ Object
readonly
The set of task contexts for this process.
Class Method Summary collapse
-
.resolve_prefix(model, prefix) ⇒ Hash<String,String>
private
Applies a prefix to this process' task names and returns the names.
Instance Method Summary collapse
-
#default_log_file_name(orocos_name) ⇒ Object
Computes the default log file name for a given orocos name.
-
#default_logger_name ⇒ String
private
The name of the default logger for this process.
-
#each_task ⇒ Object
Enumerate the TaskContext instances of the tasks that are running in this process.
-
#get_mapped_name(name) ⇒ Object
private
use a mapping if exists.
-
#initialize(name, model, name_mappings: Hash.new) ⇒ ProcessBase
constructor
A new instance of ProcessBase.
-
#log_all_ports(options = Hash.new) ⇒ Object
Requires all known ports of
self
to be logged by the default logger. -
#map_name(old, new) ⇒ Object
Require that to rename the task called
old
in this deployment tonew
during execution. - #orogen ⇒ Object deprecated Deprecated.
- #register_task(task) ⇒ Object
-
#setup_default_logger(logger = self.default_logger, log_file_name: default_log_file_name(logger.basename), remote: false, log_dir: Orocos.default_working_directory) ⇒ Object
private
Sets up the default logger of this process.
-
#task(task_name, name_service = Orocos.name_service) ⇒ Object
Returns the TaskContext instance for a task that runs in this process, or raises Orocos::NotFound.
-
#task_names ⇒ Object
Returns the name of the tasks that are running in this process.
Constructor Details
#initialize(name, model, name_mappings: Hash.new) ⇒ ProcessBase
Returns a new instance of ProcessBase
166 167 168 169 170 171 172 |
# File 'lib/orocos/process.rb', line 166 def initialize(name, model, name_mappings: Hash.new) @name, @model = name, model @name_mappings = Hash.new self.name_mappings = name_mappings @logged_ports = Set.new @tasks = [] end |
Instance Attribute Details
#default_logger ⇒ #log, false
Returns the logger object that should be used, by default, to log data coming out of this process, or false if none can be found
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/orocos/process.rb', line 296 def default_logger if !@default_logger.nil? return @default_logger end if logger_name = default_logger_name begin @default_logger = TaskContext.get logger_name rescue Orocos::NotFound Orocos.warn "no default logger defined on #{name}, tried #{logger_name}" @default_logger = false # use false to mark "can not find" end else if Orocos.warn_for_missing_default_loggers? Orocos.warn "cannot determine the default logger name for process #{name}" end @default_logger = false end @default_logger end |
#logged_ports ⇒ Object (readonly)
The set of [task_name, port_name] that represent the ports being currently logged by this process' default logger
161 162 163 |
# File 'lib/orocos/process.rb', line 161 def logged_ports @logged_ports end |
#model ⇒ OroGen::Spec::Deployment (readonly)
The deployment oroGen model
152 153 154 |
# File 'lib/orocos/process.rb', line 152 def model @model end |
#name ⇒ String (readonly)
The process name
149 150 151 |
# File 'lib/orocos/process.rb', line 149 def name @name end |
#name_mappings ⇒ Object
A set of mappings from task names in the deployment model to the actual name in the running process
158 159 160 |
# File 'lib/orocos/process.rb', line 158 def name_mappings @name_mappings end |
#tasks ⇒ Object (readonly)
The set of task contexts for this process. This is valid only after the process is actually started
164 165 166 |
# File 'lib/orocos/process.rb', line 164 def tasks @tasks end |
Class Method Details
.resolve_prefix(model, prefix) ⇒ Hash<String,String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Applies a prefix to this process' task names and returns the names
328 329 330 331 332 333 334 335 336 |
# File 'lib/orocos/process.rb', line 328 def self.resolve_prefix(model, prefix) name_mappings = Hash.new if prefix model.task_activities.each do |act| name_mappings[act.name] = "#{prefix}#{act.name}" end end return name_mappings end |
Instance Method Details
#default_log_file_name(orocos_name) ⇒ Object
Computes the default log file name for a given orocos name
251 252 253 |
# File 'lib/orocos/process.rb', line 251 def default_log_file_name(orocos_name) orocos_name[/.*(?=_[L|l]ogger)/] || orocos_name end |
#default_logger_name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the name of the default logger for this process
276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/orocos/process.rb', line 276 def default_logger_name candidates = model.task_activities. find_all { |d| d.task_model.name == "logger::Logger" }. map { |c| name_mappings[c.name] || c.name } if candidates.size > 1 if t = candidates.find { |c| c.name == "#{process.name}_Logger" } return t.name end elsif candidates.size == 1 return candidates.first end end |
#each_task ⇒ Object
Enumerate the TaskContext instances of the tasks that are running in this process.
See also #task_names
214 215 216 217 218 219 |
# File 'lib/orocos/process.rb', line 214 def each_task return enum_for(:each_task) if !block_given? task_names.each do |name| yield(task(name)) end end |
#get_mapped_name(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
use a mapping if exists
193 194 195 |
# File 'lib/orocos/process.rb', line 193 def get_mapped_name(name) name_mappings[name] || name end |
#log_all_ports(options = Hash.new) ⇒ Object
Requires all known ports of self
to be logged by the default
logger
244 245 246 |
# File 'lib/orocos/process.rb', line 244 def log_all_ports( = Hash.new) @logged_ports |= Orocos.log_all_process_ports(self, ) end |
#map_name(old, new) ⇒ Object
Require that to rename the task called old
in this deployment
to new
during execution
186 187 188 |
# File 'lib/orocos/process.rb', line 186 def map_name(old, new) name_mappings[old] = new end |
#orogen ⇒ Object
For backward compatibility only
155 |
# File 'lib/orocos/process.rb', line 155 def orogen; model end |
#register_task(task) ⇒ Object
238 239 240 241 |
# File 'lib/orocos/process.rb', line 238 def register_task(task) @tasks.delete_if { |t| t.name == task.name } @tasks << task end |
#setup_default_logger(logger = self.default_logger, log_file_name: default_log_file_name(logger.basename), remote: false, log_dir: Orocos.default_working_directory) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets up the default logger of this process
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/orocos/process.rb', line 258 def setup_default_logger(logger = self.default_logger, log_file_name: default_log_file_name(logger.basename), remote: false, log_dir: Orocos.default_working_directory) if remote index = (@@logfile_indexes[log_file_name] ||= -1) + 1 @@logfile_indexes[log_file_name] = index log_file_path = "#{log_file_name}.#{index}.log" else index = 0 while File.file?(log_file_path = File.join(log_dir, "#{log_file_name}.#{index}.log")) index += 1 end end logger.property('file').write(log_file_path) logger end |
#task(task_name, name_service = Orocos.name_service) ⇒ Object
Returns the TaskContext instance for a task that runs in this process, or raises Orocos::NotFound.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/orocos/process.rb', line 223 def task(task_name, name_service = Orocos.name_service) full_name = "#{name}_#{task_name}" if result = tasks.find { |t| t.basename == task_name || t.basename == full_name } return result end if task_names.include?(task_name) name_service.get task_name, process: self elsif task_names.include?(full_name) name_service.get full_name, process: self else raise Orocos::NotFound, "no task #{task_name} defined on #{name}" end end |
#task_names ⇒ Object
Returns the name of the tasks that are running in this process
See also #each_task
200 201 202 203 204 205 206 207 208 |
# File 'lib/orocos/process.rb', line 200 def task_names if !model raise Orocos::NotOrogenComponent, "#{name} does not seem to have been generated by orogen" end model.task_activities.map do |deployed_task| name = deployed_task.name get_mapped_name(name) end end |