Class: Orocos::ROS::ProcessManager

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/ros/process_manager.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loader = Orocos::ROS.default_loader) ⇒ ProcessManager

Initialize process server



37
38
39
40
41
# 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

Instance Attribute Details

#dying_launcher_processesSet<LauncherProcess> (readonly)

Returns the set of launcher processes for which #kill has been called but the exit status has not yet been read by #wait_termination

Returns:



27
28
29
# File 'lib/orocos/ros/process_manager.rb', line 27

def dying_launcher_processes
  @dying_launcher_processes
end

#launcher_processesObject (readonly) Also known as: processes

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



21
22
23
# File 'lib/orocos/ros/process_manager.rb', line 21

def launcher_processes
  @launcher_processes
end

#loaderOroGen::ROS::Loader (readonly)

The loader object that should be used to get ROS models

Returns:

  • (OroGen::ROS::Loader)


17
18
19
# File 'lib/orocos/ros/process_manager.rb', line 17

def loader
  @loader
end

#name_serviceOrocos::ROS::NameService

Returns the ROS nameservice used by this process manager

Returns:



30
31
32
# File 'lib/orocos/ros/process_manager.rb', line 30

def name_service
    @name_service ||= Orocos::ROS.name_service
end

Instance Method Details

#create_log_dir(log_dir, time_tag, metadata = Hash.new) ⇒ Object

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



74
75
# File 'lib/orocos/ros/process_manager.rb', line 74

def create_log_dir(log_dir, time_tag,  = Hash.new)
end

#disconnectObject



43
44
# File 'lib/orocos/ros/process_manager.rb', line 43

def disconnect
end

#kill(launcher_process) ⇒ void

This method returns an undefined value.

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

Parameters:



109
110
111
112
113
114
# 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

#save_log_dir(log_dir, results_dir) ⇒ Object

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



69
70
# 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) ⇒ Orocos::ROS::LauncherProcess

Start a launcher process under the given process_name

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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) ⇒ Object

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.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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