service_server_test.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
3 
5 
6 #include <std_srvs/Empty.h>
7 
8 namespace du = diagnostic_updater;
9 
10 // Alias type for easier access to DiagnosticStatus enumerations.
11 typedef diagnostic_msgs::DiagnosticStatus DS;
12 
14 {
18 
20 
24 
26 
27  public:
29  :
30  test1_result_(true)
31  {
32  // Setup a one-shot timer to initialize the node after a brief
33  // delay so that /rosout is always fully initialized.
34  ROS_INFO("Starting initialization timer...");
37  this,
38  true);
39  }
40 
41  void initialize(const ros::WallTimerEvent &ignored)
42  {
44  test1_srv_ = swri::ServiceServer(nh_, "test_service1",
46  this);
47 
49  test2_srv_ = swri::ServiceServer(nh_, "test_service2",
51  this);
52 
53  test3_srv_.setLogCalls(true);
55  test3_srv_ = swri::ServiceServer(nh_, "test_service3",
57  this);
58 
59 
62  "swri::ServiceServer test service 1", this,
64 
66  "swri::ServiceServer test service 2", this,
68 
70  "swri::ServiceServer test service 3", this,
72 
75  this);
76  }
77 
78  bool handleService1(std_srvs::Empty::Request &req,
79  std_srvs::Empty::Response &res)
80  {
81  ROS_INFO("test service 1 called. returning %s",
82  test1_result_ ? "true" : "false");
83  return test1_result_;
84  }
85 
86  bool handleService2(ros::ServiceEvent<std_srvs::Empty::Request,
87  std_srvs::Empty::Response> &event)
88  {
89  ROS_INFO("test service 2 called");
91  return true;
92  }
93 
94  bool handleService3(const std::string &name,
95  const std_srvs::Empty::Request &request,
96  std_srvs::Empty::Response &response)
97  {
98  ROS_INFO("test service 3 called by %s", name.c_str());
99  return true;
100  }
101 
103  {
105  }
106 
108  {
109  status.summary(DS::OK, "No errors reported.");
110  test1_srv_.appendDiagnostics(status, "Test Service 1",
112  }
113 
115  {
116  status.summary(DS::OK, "No errors reported.");
117  test2_srv_.appendDiagnostics(status, "Test Service 2",
119  }
120 
122  {
123  status.summary(DS::OK, "No errors reported.");
124  test3_srv_.appendDiagnostics(status, "Test Service 3",
126  }
127 }; // class ServiceServerTest
128 
129 int main(int argc, char **argv)
130 {
131  ros::init(argc, argv, "service_server_test");
132 
133  ServiceServerTest node;
134  ros::spin();
135 
136  return 0;
137 }
ServiceServerTest::nh_
ros::NodeHandle nh_
Definition: service_server_test.cpp:15
service_server.h
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
swri::ServiceServer::DIAG_ALL
@ DIAG_ALL
Definition: service_server.h:101
ros::WallTimer
diagnostic_updater::Updater
ServiceServerTest::test1_srv_
swri::ServiceServer test1_srv_
Definition: service_server_test.cpp:21
ServiceServerTest::service3Diagnostics
void service3Diagnostics(du::DiagnosticStatusWrapper &status)
Definition: service_server_test.cpp:121
diagnostic_updater.h
swri::ServiceServer::appendDiagnostics
void appendDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &status, const std::string &name, const int flags)
Definition: service_server.h:238
swri::ServiceServer
Definition: service_server.h:39
diagnostic_updater::DiagnosticStatusWrapper::summary
void summary(const diagnostic_msgs::DiagnosticStatus &src)
ServiceServerTest::ServiceServerTest
ServiceServerTest()
Definition: service_server_test.cpp:28
diagnostic_updater
ServiceServerTest::test3_srv_
swri::ServiceServer test3_srv_
Definition: service_server_test.cpp:23
ServiceServerTest::service2Diagnostics
void service2Diagnostics(du::DiagnosticStatusWrapper &status)
Definition: service_server_test.cpp:114
ServiceServerTest::diag_timer_
ros::Timer diag_timer_
Definition: service_server_test.cpp:17
ros::TimerEvent
ServiceServerTest::handleService3
bool handleService3(const std::string &name, const std_srvs::Empty::Request &request, std_srvs::Empty::Response &response)
Definition: service_server_test.cpp:94
ServiceServerTest::init_timer_
ros::WallTimer init_timer_
Definition: service_server_test.cpp:16
diagnostic_updater::Updater::setHardwareID
void setHardwareID(const std::string &hwid)
ServiceServerTest::test2_srv_
swri::ServiceServer test2_srv_
Definition: service_server_test.cpp:22
ServiceServerTest
Definition: service_server_test.cpp:13
swri::ServiceServer::setInstrumentPerClient
void setInstrumentPerClient(bool enable)
Definition: service_server.h:201
ServiceServerTest::service1Diagnostics
void service1Diagnostics(du::DiagnosticStatusWrapper &status)
Definition: service_server_test.cpp:107
ServiceServerTest::test1_result_
bool test1_result_
Definition: service_server_test.cpp:25
diagnostic_updater::Updater::update
void update()
ros::WallTimerEvent
ServiceServerTest::handleDiagnosticsTimer
void handleDiagnosticsTimer(const ros::TimerEvent &ignored)
Definition: service_server_test.cpp:102
ServiceServerTest::diagnostic_updater_
du::Updater diagnostic_updater_
Definition: service_server_test.cpp:19
ServiceServerTest::initialize
void initialize(const ros::WallTimerEvent &ignored)
Definition: service_server_test.cpp:41
diagnostic_updater::DiagnosticStatusWrapper
DS
diagnostic_msgs::DiagnosticStatus DS
Definition: service_server_test.cpp:11
ros::spin
ROSCPP_DECL void spin()
ServiceServerTest::handleService1
bool handleService1(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
Definition: service_server_test.cpp:78
ros::WallDuration
ROS_INFO
#define ROS_INFO(...)
diagnostic_updater::DiagnosticTaskVector::add
void add(const std::string &name, TaskFunction f)
main
int main(int argc, char **argv)
Definition: service_server_test.cpp:129
ros::NodeHandle::createTimer
Timer createTimer(Duration period, const TimerCallback &callback, bool oneshot=false, bool autostart=true) const
swri::ServiceServer::setLogCalls
void setLogCalls(bool enable)
Definition: service_server.h:226
ros::Duration
ros::NodeHandle::createWallTimer
WallTimer createWallTimer(WallDuration period, const WallTimerCallback &callback, bool oneshot=false, bool autostart=true) const
ros::Timer
service_splitter.name
string name
Definition: service_splitter.py:68
ServiceServerTest::handleService2
bool handleService2(ros::ServiceEvent< std_srvs::Empty::Request, std_srvs::Empty::Response > &event)
Definition: service_server_test.cpp:86
ros::NodeHandle
ros::ServiceEvent


swri_roscpp
Author(s): P. J. Reed
autogenerated on Fri Aug 2 2024 08:39:15