e2e_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2024 The urg_stamped Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef E2E_UTILS_H
18 #define E2E_UTILS_H
19 
20 #include <string>
21 
22 #include <boost/asio/ip/tcp.hpp>
23 
24 #include <ros/ros.h>
25 
26 #include <ros/network.h>
27 #include <ros/xmlrpc_manager.h>
28 #include <xmlrpcpp/XmlRpc.h>
29 
30 inline bool shutdownNode(const std::string& name)
31 {
32  XmlRpc::XmlRpcValue req, res, payload;
33  req[0] = ros::this_node::getName();
34  req[1] = name;
35  if (!ros::master::execute("lookupNode", req, res, payload, true))
36  {
37  return false;
38  }
39 
40  std::string host;
41  uint32_t port;
42  if (!ros::network::splitURI(static_cast<std::string>(res[2]), host, port))
43  {
44  return false;
45  }
46 
47  XmlRpc::XmlRpcClient cli(host.c_str(), port, "/");
48  XmlRpc::XmlRpcValue req2, res2;
49  return cli.execute("shutdown", req2, res2);
50 }
51 
52 #endif // E2E_UTILS_H
ros.h
XmlRpc::XmlRpcClient::execute
bool execute(const char *method, XmlRpcValue const &params, XmlRpcValue &result)
network.h
XmlRpc::XmlRpcClient
xmlrpc_manager.h
XmlRpc.h
ros::master::execute
ROSCPP_DECL bool execute(const std::string &method, const XmlRpc::XmlRpcValue &request, XmlRpc::XmlRpcValue &response, XmlRpc::XmlRpcValue &payload, bool wait_for_master)
ros::this_node::getName
const ROSCPP_DECL std::string & getName()
shutdownNode
bool shutdownNode(const std::string &name)
Definition: e2e_utils.h:30
ros::network::splitURI
ROSCPP_DECL bool splitURI(const std::string &uri, std::string &host, uint32_t &port)
XmlRpc::XmlRpcValue


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Wed Dec 18 2024 03:10:57