SMACC2
Loading...
Searching...
No Matches
smacc_ros_launch_client_2.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#pragma once
22
25
26#include <rclcpp_action/client.hpp>
27#include <thread>
28
29namespace smacc2
30{
31namespace client_bases
32{
34{
35 pid_t pid; // PID del proceso hijo
36 FILE * pipe; // Pipe para la salida del proceso hijo
37};
38
39ProcessInfo runProcess(const char * command);
41void killProcessesRecursive(pid_t pid);
42
44{
45public:
47
48 ClRosLaunch2(std::string packageName, std::string launchFilename);
49
50 virtual ~ClRosLaunch2();
51
52 void launch();
53
54 void stop();
55
56 static std::future<std::string> executeRosLaunch(
57 std::string packageName, std::string launchFilename, std::function<bool()> cancelCondition,
58 ClRosLaunch2 * client = nullptr);
59
60 // static std::string executeRosLaunch(
61 // std::string packageName, std::string launchFilename, std::function<bool()> cancelCondition);
62
63 std::string packageName_;
64
65 std::string launchFileName_;
66
68
69protected:
70 // std::future<std::string> result_;
71 std::future<std::string> result_;
72
73 typedef std::function<void> cancelCallback;
74
75 static std::map<std::future<void>, cancelCallback> detached_futures_;
76
77 std::atomic<bool> cancellationToken_ = ATOMIC_VAR_INIT(false);
78};
79} // namespace client_bases
80} // namespace smacc2
static std::map< std::future< void >, cancelCallback > detached_futures_
static std::future< std::string > executeRosLaunch(std::string packageName, std::string launchFilename, std::function< bool()> cancelCondition, ClRosLaunch2 *client=nullptr)
void killGrandchildren(pid_t originalPid)
ProcessInfo runProcess(const char *command)