43 std::string packageName, std::string launchFileName, std::function<
bool()> cancelCondition)
50 rclcpp::get_logger(
"smacc2"),
"[ClRosLaunch static] starting ros launch thread ");
52 std::stringstream cmd;
53 cmd <<
"ros2 launch " << packageName <<
" " << launchFileName;
55 std::array<char, 128> buffer;
57 auto pipe_deleter = [](FILE * fp)
61 std::unique_ptr<FILE,
decltype(pipe_deleter)> pipe(
62 popen(cmd.str().c_str(),
"r"), pipe_deleter);
65 throw std::runtime_error(
"popen() failed!");
69 bool cancelled =
false;
72 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr &&
73 !(cancelled = cancelCondition()))
79 rclcpp::get_logger(
"smacc2"),
"[ClRosLaunch static] cancelling ros launch thread ");
82 pclose(pipe.release());
88 catch (
const std::exception & e)
90 std::cerr << e.what() <<
'\n';
95 rclcpp::get_logger(
"smacc2"),
"[ClRosLaunch static]] RESULT = \n " << ss.str());