def StartNode(self, request_iterator, context): for request in request_iterator: rospy.logdebug('StartNode request:\n%s' % str(request)) try: result = lmsg.StartNodeReply(name=request.name) launch_configs = [] if request.opt_launch: cfgid = CfgId(request.opt_launch, request.masteruri) if cfgid in self._loaded_files: launch_configs.append(self._loaded_files[cfgid]) if not launch_configs: # get launch configurations with given node launch_configs = [] for cfgid, launchcfg in self._loaded_files.items(): if cfgid.equal_masteruri(request.masteruri): n = launchcfg.get_node(request.name) if n is not None: launch_configs.append(launchcfg) if not launch_configs: result.status.code = NODE_NOT_FOUND result.status.error_msg = "Node '%s' not found" % request.name yield result if len(launch_configs) > 1: result.status.code = MULTIPLE_LAUNCHES result.status.error_msg = "Node '%s' found in multiple launch files" % request.name result.launch.extend([lcfg.filename for lcfg in launch_configs]) yield result try: result.launch.append(launch_configs[0].filename) startcfg = launcher.create_start_config(request.name, launch_configs[0], request.opt_binary, masteruri=request.masteruri, loglevel=request.loglevel, logformat=request.logformat, reload_global_param=request.reload_global_param, cmd_prefix=request.cmd_prefix) launcher.run_node(startcfg) result.status.code = OK yield result except exceptions.BinarySelectionRequest as bsr: result.status.code = MULTIPLE_BINARIES result.status.error_msg = "multiple binaries found for node '%s': %s" % (request.name, bsr.choices) result.path.extend(bsr.choices) yield result except grpc.RpcError as conerr: result.status.code = CONNECTION_ERROR result.status.error_msg = utf8(conerr) yield result except exceptions.ResourceNotFound as err_nf: result = lmsg.StartNodeReply(name=request.name) result.status.code = ERROR result.status.error_msg = "Error while start node '%s': %s" % (request.name, utf8(err_nf)) yield result except Exception as _errr: result = lmsg.StartNodeReply(name=request.name) result.status.code = ERROR result.status.error_msg = "Error while start node '%s': %s" % (request.name, utf8(traceback.format_exc())) yield result
def StartStandaloneNode(self, request, context): result = lmsg.StartNodeReply(name=request.name) try: startcfg = StartConfig.from_msg(request) try: launcher.run_node(startcfg) result.status.code = OK except exceptions.BinarySelectionRequest as bsr: result.status.code = MULTIPLE_BINARIES result.status.error_msg = "multiple binaries found for node '%s': %s" % (request.name, bsr.choices) result.launch.extend(bsr.choices) except grpc.RpcError as conerr: result.status.code = CONNECTION_ERROR result.status.error_msg = utf8(conerr) except Exception: result = lmsg.StartNodeReply(name=request.name) result.status.code = ERROR result.status.error_msg = "Error while start node '%s': %s" % (request.name, utf8(traceback.format_exc())) return result