40using namespace std::chrono_literals;
42: cancellationToken_(
false)
78 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"smacc2"),
"[ClRosLaunch2] Starting ros launch thread");
80 std::stringstream
cmd;
82 std::array<char, 128>
buffer;
89 throw std::runtime_error(
"popen() failed!");
91 if (client !=
nullptr)
116 std::this_thread::sleep_for(
117 std::chrono::milliseconds(100));
122 RCLCPP_ERROR(rclcpp::get_logger(
"smacc2"),
"Error de lectura en pipe");
127 rclcpp::sleep_for(2
s);
131 rclcpp::sleep_for(2
s);
142 rclcpp::get_logger(
"smacc2"),
"Child process exited with status: %d",
exit_status);
148 rclcpp::get_logger(
"smacc2"),
"Child process terminated by signal: %d",
term_signal);
153 RCLCPP_ERROR(rclcpp::get_logger(
"smacc2"),
"Error waiting for child process.");
159 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"smacc2"),
"[ClRosLaunch2] RESULT:\n" << result);
196 std::cerr <<
"Error al ejecutar el comando: " <<
command << std::endl;
208 std::cerr <<
"Error al crear el proceso hijo." << std::endl;
216 std::string
command =
"pgrep -P " + std::to_string(pid);
221 std::cerr <<
"Error executing pgrep command." << std::endl;
226 std::string result =
"";
235 std::istringstream
iss(result);
254 RCLCPP_FATAL(rclcpp::get_logger(
"smacc2"),
"Killed process %d", pid);
std::atomic< bool > cancellationToken_
std::string launchFileName_
std::future< std::string > result_
static std::future< std::string > executeRosLaunch(std::string packageName, std::string launchFilename, std::function< bool()> cancelCondition, ClRosLaunch2 *client=nullptr)
void killGrandchildren(pid_t originalPid)
void killProcessesRecursive(pid_t pid)
ProcessInfo runProcess(const char *command)