SMACC2
Loading...
Searching...
No Matches
smacc2
include
smacc2
client_bases
smacc_ros_launch_client_2.hpp
Go to the documentation of this file.
1
// Copyright 2025 Robosoft 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
23
#include <
smacc2/smacc_client.hpp
>
24
#include <
smacc2/smacc_state_machine.hpp
>
25
26
#include <cstdio>
27
#include <memory>
28
#include <rclcpp_action/client.hpp>
29
#include <thread>
30
31
namespace
smacc2
32
{
33
namespace
client_bases
34
{
35
struct
ProcessInfo
36
{
37
pid_t
pid
;
// PID of the child process
38
// Stream on the child process output; closed with fclose when this object goes.
39
std::unique_ptr<FILE, int (*)(FILE *)>
pipe
;
40
};
41
42
ProcessInfo
runProcess
(
const
char
* command);
43
void
killGrandchildren
(pid_t originalPid);
44
void
killProcessesRecursive
(pid_t pid);
45
46
class
ClRosLaunch2
:
public
ISmaccClient
47
{
48
public
:
49
ClRosLaunch2
();
50
51
ClRosLaunch2
(std::string packageName, std::string launchFilename);
52
53
~ClRosLaunch2
()
override
;
54
55
void
launch
();
56
57
void
stop
();
58
59
static
std::future<std::string>
executeRosLaunch
(
60
const
std::string & packageName,
const
std::string & launchFileName,
61
std::function<
bool
()> cancelCondition,
ClRosLaunch2
* client =
nullptr
);
62
63
// static std::string executeRosLaunch(
64
// std::string packageName, std::string launchFilename, std::function<bool()> cancelCondition);
65
66
std::string
packageName_
;
67
68
std::string
launchFileName_
;
69
70
// -1 until a launch runs. A pid of 0 or -1 must never reach kill(): process group or every process.
71
pid_t
launchPid_
= -1;
72
73
protected
:
74
std::future<std::string>
result_
;
75
76
typedef
std::function<void>
cancelCallback
;
77
78
static
std::map<std::future<void>,
cancelCallback
>
detached_futures_
;
79
80
std::atomic<bool>
cancellationToken_
= ATOMIC_VAR_INIT(
false
);
81
};
82
}
// namespace client_bases
83
}
// namespace smacc2
smacc2::ISmaccClient
Definition
smacc_client.hpp:46
smacc2::client_bases::ClRosLaunch2
Definition
smacc_ros_launch_client_2.hpp:47
smacc2::client_bases::ClRosLaunch2::cancellationToken_
std::atomic< bool > cancellationToken_
Definition
smacc_ros_launch_client_2.hpp:80
smacc2::client_bases::ClRosLaunch2::launch
void launch()
Definition
smacc_ros_launch_client_2.cpp:50
smacc2::client_bases::ClRosLaunch2::cancelCallback
std::function< void > cancelCallback
Definition
smacc_ros_launch_client_2.hpp:76
smacc2::client_bases::ClRosLaunch2::ClRosLaunch2
ClRosLaunch2()
Definition
smacc_ros_launch_client_2.cpp:41
smacc2::client_bases::ClRosLaunch2::launchPid_
pid_t launchPid_
Definition
smacc_ros_launch_client_2.hpp:71
smacc2::client_bases::ClRosLaunch2::stop
void stop()
Definition
smacc_ros_launch_client_2.cpp:58
smacc2::client_bases::ClRosLaunch2::detached_futures_
static std::map< std::future< void >, cancelCallback > detached_futures_
Definition
smacc_ros_launch_client_2.hpp:78
smacc2::client_bases::ClRosLaunch2::~ClRosLaunch2
~ClRosLaunch2() override
Definition
smacc_ros_launch_client_2.cpp:48
smacc2::client_bases::ClRosLaunch2::launchFileName_
std::string launchFileName_
Definition
smacc_ros_launch_client_2.hpp:68
smacc2::client_bases::ClRosLaunch2::executeRosLaunch
static std::future< std::string > executeRosLaunch(const std::string &packageName, const std::string &launchFileName, std::function< bool()> cancelCondition, ClRosLaunch2 *client=nullptr)
Definition
smacc_ros_launch_client_2.cpp:64
smacc2::client_bases::ClRosLaunch2::result_
std::future< std::string > result_
Definition
smacc_ros_launch_client_2.hpp:74
smacc2::client_bases::ClRosLaunch2::packageName_
std::string packageName_
Definition
smacc_ros_launch_client_2.hpp:66
smacc2::client_bases::killGrandchildren
void killGrandchildren(pid_t originalPid)
Definition
smacc_ros_launch_client_2.cpp:273
smacc2::client_bases::killProcessesRecursive
void killProcessesRecursive(pid_t pid)
Definition
smacc_ros_launch_client_2.cpp:229
smacc2::client_bases::runProcess
ProcessInfo runProcess(const char *command)
Definition
smacc_ros_launch_client_2.cpp:175
smacc2
Definition
callback_counter_semaphore.hpp:30
smacc_client.hpp
smacc_state_machine.hpp
smacc2::client_bases::ProcessInfo
Definition
smacc_ros_launch_client_2.hpp:36
smacc2::client_bases::ProcessInfo::pipe
std::unique_ptr< FILE, int(*)(FILE *)> pipe
Definition
smacc_ros_launch_client_2.hpp:39
smacc2::client_bases::ProcessInfo::pid
pid_t pid
Definition
smacc_ros_launch_client_2.hpp:37
Generated by
1.12.0