Class: Orocos::ROS::ProcessManager
- Inherits:
-
Object
- Object
- Orocos::ROS::ProcessManager
- 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
-
#dying_launcher_processes ⇒ Set<LauncherProcess>
readonly
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 ⇒ Object
(also: #processes)
readonly
Mapping from a launcher name to the corresponding Launcher instance, for launcher processes that have been started by this client.
-
#loader ⇒ OroGen::ROS::Loader
readonly
The loader object that should be used to get ROS models.
-
#name_service ⇒ Orocos::ROS::NameService
The ROS nameservice used by this process manager.
Instance Method Summary collapse
-
#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).
- #disconnect ⇒ Object
-
#initialize(loader = Orocos::ROS.default_loader) ⇒ ProcessManager
constructor
Initialize process server.
-
#kill(launcher_process) ⇒ void
Kills the given launcher process and registers it in #dying_launcher_processes for later reporting by #wait_termination.
-
#save_log_dir(log_dir, results_dir) ⇒ Object
Requests that the process server moves the log directory at
log_dir
toresults_dir
. -
#start(process_name, launcher, name_mappings = Hash.new, options = Hash.new) ⇒ Orocos::ROS::LauncherProcess
Start a launcher process under the given process_name.
-
#wait_termination(timeout = nil) ⇒ Object
Waits for processes to terminate.
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_processes ⇒ Set<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
27 28 29 |
# File 'lib/orocos/ros/process_manager.rb', line 27 def @dying_launcher_processes end |
#launcher_processes ⇒ Object (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 |
#loader ⇒ OroGen::ROS::Loader (readonly)
The loader object that should be used to get ROS models
17 18 19 |
# File 'lib/orocos/ros/process_manager.rb', line 17 def loader @loader end |
#name_service ⇒ Orocos::ROS::NameService
Returns the ROS nameservice used by this process manager
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 |
#disconnect ⇒ Object
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
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) << 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
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, = 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 .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 |