SMACC
Loading...
Searching...
No Matches
smacc_service_client.h
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6
7#pragma once
8
10#include <boost/optional/optional_io.hpp>
11
12namespace smacc
13{
14namespace client_bases
15{
16template <typename ServiceType>
18{
19public:
20 boost::optional<std::string> serviceName_;
21
23 {
24 initialized_ = false;
25 }
26 SmaccServiceClient(std::string service_name)
27 {
28 serviceName_ = service_name;
29 initialized_ = false;
30 }
31
32 virtual void initialize() override
33 {
34 if (!initialized_)
35 {
36 if (!serviceName_)
37 {
38 ROS_ERROR("service client with no service name set. Skipping.");
39 }
40 else
41 {
42 ROS_INFO_STREAM("[" << this->getName() << "] Client Service: " << *serviceName_);
43 this->initialized_ = true;
44
45 client_ = nh_.serviceClient<ServiceType>(*serviceName_);
46 }
47 }
48 }
49
50 bool call(ServiceType &srvreq)
51 {
52 return client_.call(srvreq);
53 }
54
55protected:
56 ros::NodeHandle nh_;
57 ros::ServiceClient client_;
59};
60} // namespace client_bases
61} // namespace smacc
virtual std::string getName() const
Definition: client.cpp:34
SmaccServiceClient(std::string service_name)
boost::optional< std::string > serviceName_