Package roslaunch :: Module child
[frames] | no frames]

Source Code for Module roslaunch.child

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2008, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id$ 
 34   
 35  """ 
 36  ROSLaunch child server. 
 37   
 38  ROSLaunch has a client/server architecture for running remote 
 39  processes. When a user runs roslaunch, this creates a "parent" 
 40  roslaunch process. This parent process will then start "child" 
 41  processes on remote machines. The parent can then invoke methods on 
 42  this child process to launch remote processes, and the child can 
 43  invoke methods on the parent to provide feedback. 
 44  """ 
 45   
 46  import logging 
 47  import traceback 
 48   
 49  import roslaunch.core 
 50  import roslaunch.pmon 
 51  import roslaunch.server 
 52   
53 -class ROSLaunchChild(object):
54 """ 55 ROSLaunchChild infrastructure. 56 57 This must be called from the Python Main thread due to signal registration. 58 """ 59
60 - def __init__(self, run_id, name, server_uri):
61 """ 62 Startup roslaunch remote client XML-RPC services. Blocks until shutdown 63 @param run_id: UUID of roslaunch session 64 @type run_id: str 65 @param name: name of remote client 66 @type name: str 67 @param server_uri: XML-RPC URI of roslaunch server 68 @type server_uri: str 69 @return: XML-RPC URI 70 @rtype: str 71 """ 72 roslaunch.core.set_child_mode(True) 73 74 self.logger = logging.getLogger("roslaunch.child") 75 self.run_id = run_id 76 self.name = name 77 self.server_uri = server_uri 78 self.child_server = None 79 self.pm = None 80 81 roslaunch.pmon._init_signal_handlers()
82
83 - def _start_pm(self):
84 """ 85 Start process monitor for child roslaunch 86 """ 87 # start process monitor 88 # - this test is mainly here so that testing logic can 89 # override process monitor with a mock 90 if self.pm is None: 91 self.pm = roslaunch.pmon.start_process_monitor() 92 if self.pm is None: 93 # this should only happen if a shutdown signal is received during startup 94 raise roslaunch.core.RLException("cannot startup remote child: unable to start process monitor.") 95 self.logger.debug("started process monitor")
96
97 - def run(self):
98 """ 99 Runs child. Blocks until child processes exit. 100 """ 101 try: 102 try: 103 self.logger.info("starting roslaunch child process [%s], server URI is [%s]", self.name, self.server_uri) 104 self._start_pm() 105 self.child_server = roslaunch.server.ROSLaunchChildNode(self.run_id, self.name, self.server_uri, self.pm) 106 self.logger.info("... creating XMLRPC server for child") 107 self.child_server.start() 108 self.logger.info("... started XMLRPC server for child") 109 # block until process monitor is shutdown 110 self.pm.mainthread_spin() 111 self.logger.info("... process monitor is done spinning") 112 except: 113 self.logger.error(traceback.format_exc()) 114 raise 115 finally: 116 if self.pm: 117 self.pm.shutdown() 118 self.pm.join() 119 if self.child_server: 120 self.child_server.shutdown('roslaunch child complete')
121
122 - def shutdown(self):
123 if self.pm: 124 self.pm.shutdown() 125 self.pm.join()
126