class Orocos::ProcessBase

Base class for process representation objects

Attributes

default_logger[W]

Overrides the default logger usually autodetected by default_logger

logged_ports[R]

The set of [task_name, port_name] that represent the ports being currently logged by this process' default logger

model[R]

The deployment oroGen model @return [OroGen::Spec::Deployment]

name[R]

The process name @return [String]

name_mappings[R]

A set of mappings from task names in the deployment model to the actual name in the running process

tasks[R]

The set of task contexts for this process. This is valid only after the process is actually started

Public Class Methods

new(name, model, name_mappings: Hash.new) click to toggle source
# 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
resolve_prefix(model, prefix) click to toggle source

@api private

Applies a prefix to this process' task names and returns the names

@param [OroGen::Spec::Deployment] model the deployment model @param [String,nil] prefix the prefix string, no prefix is going to be

applied if it is nil

@return [Hash<String,String>] the name mappings that should be applied

when spawning the process
# 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

Public Instance Methods

default_log_file_name(orocos_name) click to toggle source

Computes the default log file name for a given orocos name

# File lib/orocos/process.rb, line 251
def default_log_file_name(orocos_name)
    orocos_name[/.*(?=_[L|l]ogger)/] || orocos_name
end
default_logger() click to toggle source

@return [#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
# 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
default_logger_name() click to toggle source

@api private

@return [String] the name of the default logger for this process

# 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() { |task(name)| ... } click to toggle source

Enumerate the TaskContext instances of the tasks that are running in this process.

See also task_names

# 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) click to toggle source

@api private

use a mapping if exists

# File lib/orocos/process.rb, line 193
def get_mapped_name(name)
    name_mappings[name] || name
end
log_all_ports(options = Hash.new) click to toggle source

Requires all known ports of self to be logged by the default logger

# File lib/orocos/process.rb, line 244
def log_all_ports(options = Hash.new)
    @logged_ports |= Orocos.log_all_process_ports(self, options)
end
map_name(old, new) click to toggle source

Require that to rename the task called old in this deployment to new during execution

@see #name_mappings #name_mappings=

# File lib/orocos/process.rb, line 186
def map_name(old, new)
    name_mappings[old] = new
end
name_mappings=(mappings) click to toggle source

Sets a batch of name mappings @see #map_name

# File lib/orocos/process.rb, line 176
def name_mappings=(mappings)
    mappings.each do |old, new|
        map_name old, new
    end
end
orogen() click to toggle source

@deprecated For backward compatibility only

# File lib/orocos/process.rb, line 155
def orogen; model end
register_task(task) click to toggle source
# 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) click to toggle source

@api private

Sets up the default logger of this process

# 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) click to toggle source

Returns the TaskContext instance for a task that runs in this process, or raises Orocos::NotFound.

# 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() click to toggle source

Returns the name of the tasks that are running in this process

See also each_task

# 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