include
remote_rosbag_record
call.hpp
Go to the documentation of this file.
1
#ifndef REMOTE_ROSBAG_RECORD_CALL
2
#define REMOTE_ROSBAG_RECORD_CALL
3
4
#include <string>
5
6
#include <
ros/console.h
>
7
#include <
ros/master.h
>
8
#include <
ros/service.h
>
9
#include <
ros/this_node.h
>
10
#include <std_srvs/Empty.h>
11
#include <
xmlrpcpp/XmlRpcException.h
>
12
#include <
xmlrpcpp/XmlRpcValue.h
>
13
14
#include <boost/regex.hpp>
15
16
namespace
remote_rosbag_record
{
17
18
// try calling services matching the given expression
19
// and return number of successfull calls
20
inline
static
std::size_t
call
(
const
boost::regex &expression,
const
bool
verbose
=
true
) {
21
std::size_t n_match(0), n_success(0);
22
try
{
23
// call ros master api to get services info
24
XmlRpc::XmlRpcValue
args
, result, payload;
25
args
[0] =
ros::this_node::getName
();
26
if
(!
ros::master::execute
(
"getSystemState"
,
args
, result, payload,
27
/* wait_for_master = */
false
)) {
28
throw
XmlRpc::XmlRpcException
(
"getSystemState"
);
29
}
30
31
// call services which match the given expression
32
XmlRpc::XmlRpcValue
services(payload[2]);
33
for
(
int
i = 0; i < services.
size
(); ++i) {
34
const
std::string name(services[i][0]);
35
if
(!boost::regex_match(name, expression)) {
36
continue
;
37
}
38
++n_match;
39
40
std_srvs::Empty srv;
41
if
(!
ros::service::call
(name, srv)) {
42
ROS_ERROR_STREAM
(
"Failed to call '"
<< name <<
"'"
);
43
continue
;
44
}
45
++n_success;
46
47
if
(
verbose
) {
48
ROS_INFO_STREAM
(
"Called '"
<< name <<
"'"
);
49
}
50
}
51
52
if
(
verbose
&& n_match == 0) {
53
ROS_WARN_STREAM
(
"No service matched '"
<< expression <<
"'"
);
54
}
55
}
catch
(
const
XmlRpc::XmlRpcException
&error) {
56
ROS_ERROR_STREAM
(
"Error caught on calling services: "
<< error.
getMessage
());
57
}
58
return
n_success;
59
}
60
61
}
// namespace remote_rosbag_record
62
63
#endif
XmlRpc::XmlRpcValue::size
int size() const
ros::service::call
bool call(const std::string &service_name, MReq &req, MRes &res)
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
XmlRpc::XmlRpcException::getMessage
const std::string & getMessage() const
service.h
console.h
ROS_WARN_STREAM
#define ROS_WARN_STREAM(args)
verbose
bool verbose
Definition:
joy_listener.cpp:15
remote_rosbag_record::call
static std::size_t call(const boost::regex &expression, const bool verbose=true)
Definition:
call.hpp:20
XmlRpcValue.h
ROS_INFO_STREAM
#define ROS_INFO_STREAM(args)
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)
XmlRpc::XmlRpcException
ros::this_node::getName
const ROSCPP_DECL std::string & getName()
this_node.h
XmlRpcException.h
args
master.h
XmlRpc::XmlRpcValue
remote_rosbag_record
Definition:
call.hpp:16
remote_rosbag_record
Author(s):
autogenerated on Wed Mar 2 2022 00:49:24