class Orocos::ROS::ProcessManager

This class corresponds to the ProcessClient and is a drop-in replacement for ProcessClient. It allows to start ROS launch files using the process server

In this context launch files correspond to oroGen deployments The naming 'deployments' is kept when required by the top level interface otherwise 'launcher' is being used to clarify that this should be a ROS Launcher object

Attributes

dying_launcher_processes[R]

@return [Set<LauncherProcess>] the set of launcher processes for which

{#kill} has been called but the exit status has not yet been read by
{#wait_termination}
launcher_processes[R]

Mapping from a launcher name to the corresponding Launcher instance, for launcher processes that have been started by this client.

loader[R]

The loader object that should be used to get ROS models

@return [OroGen::ROS::Loader]

name_service[W]
processes[R]

Mapping from a launcher name to the corresponding Launcher instance, for launcher processes that have been started by this client.

Public Class Methods

new(loader = Orocos::ROS.default_loader) click to toggle source

Initialize process server

# File lib/orocos/ros/process_manager.rb, line 37
def initialize(loader = Orocos::ROS.default_loader)
    @launcher_processes = Hash.new
    @dying_launcher_processes = Array.new
    @loader = loader
end

Public Instance Methods

create_log_dir(log_dir, time_tag, metadata = Hash.new) click to toggle source

Creates a new log dir, and save the given time tag in it (used later on by #save_log_dir)

# File lib/orocos/ros/process_manager.rb, line 74
def create_log_dir(log_dir, time_tag, metadata = Hash.new)
end
disconnect() click to toggle source
# File lib/orocos/ros/process_manager.rb, line 43
def disconnect
end
kill(launcher_process) click to toggle source

Kills the given launcher process and registers it in {#dying_launcher_processes} for later reporting by {#wait_termination}

@param [LauncherProcess] launcher the launcher process to be killed @return [void]

# File lib/orocos/ros/process_manager.rb, line 109
def kill(launcher_process)
    ROS.info "ProcessManager is killing launcher process #{launcher_process.name} with pid '#{launcher_process.pid}'"
    ::Process.kill('SIGTERM', launcher_process.pid)
    dying_launcher_processes << launcher_process
    nil
end
name_service() click to toggle source

@return [Orocos::ROS::NameService] the ROS nameservice used by this process manager

# File lib/orocos/ros/process_manager.rb, line 30
def name_service
    @name_service ||= Orocos::ROS.name_service
end
save_log_dir(log_dir, results_dir) click to toggle source

Requests that the process server moves the log directory at log_dir to results_dir

# File lib/orocos/ros/process_manager.rb, line 69
def save_log_dir(log_dir, results_dir)
end
start(process_name, launcher, name_mappings = Hash.new, options = Hash.new) click to toggle source

Start a launcher process under the given process_name @return [Orocos::ROS::LauncherProcess] The launcher process which started by the process manager

# File lib/orocos/ros/process_manager.rb, line 48
def start(process_name, launcher, name_mappings = Hash.new, options = Hash.new)
    launcher_model = if launcher.respond_to?(:to_str)
                         loader.deployment_model_from_name(launcher)
                     else launcher
                     end

    ProcessManager.debug "launcher: '#{launcher_model.name}' with processname '#{process_name}'"
    launcher_processes.each do |process_name, l| 
        if l.name == launcher_model.name
            raise ArgumentError, "launcher #{launcher_model.name} is already started with processname #{process_name} in #{self}"
        end
    end

    ros_launcher = LauncherProcess.new(self, process_name, launcher_model)
    ros_launcher.spawn
    launcher_processes[process_name] = ros_launcher
    ros_launcher
end
wait_termination(timeout = nil) click to toggle source

Waits for processes to terminate. timeout is the number of milliseconds we should wait. If set to nil, the call will block until a process terminates

Returns a hash that maps launcher names to the Status object that represents their exit status.

# File lib/orocos/ros/process_manager.rb, line 83
def wait_termination(timeout = nil)
    if timeout != 0
        raise ArgumentError, "#{self.class} does not support non-zero timeouts in #wait_termination"
    end

    terminated_launchers = Hash.new
    dying_launcher_processes.delete_if do |launcher_process|
        _, status = ::Process.waitpid2(launcher_process.pid, ::Process::WUNTRACED | ::Process::WNOHANG)
        if status
            ROS.info "announing dead launcher_process: #{launcher_process}"
            terminated_launchers[launcher_process] = status
            launcher_processes.delete(launcher_process.name)
            launcher_process.dead!(status)
            true
        else
            false
        end
    end
    terminated_launchers
end