SMACC2
cb_call_service.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI 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#pragma once
23
24namespace smacc2
25{
26namespace client_behaviors
27{
28template <typename ServiceType>
30{
31public:
32 CbServiceCall(const char * serviceName) : serviceName_(serviceName) {}
33
34 CbServiceCall(const char * serviceName, std::shared_ptr<typename ServiceType::Request>)
35 : serviceName_(serviceName)
36 {
37 }
38
39 void onEntry() override
40 {
41 RCLCPP_INFO_STREAM(
42 getLogger(), "[" << this->getName() << "] creating service client: " << serviceName_);
43
44 client_ = getNode()->create_client<ServiceType>(serviceName_);
45
46 result_ = client_->async_send_request(request_).get();
47
48 //, std::bind(&CbServiceCall<ServiceType>::onServiceResponse, this, std::placeholders::_1));
49 }
50
51 typename std::shared_ptr<typename ServiceType::Response> result_;
52
53protected:
54 //rclcpp::NodeHandle nh_;
55 std::shared_ptr<rclcpp::Client<ServiceType>> client_;
56 std::string serviceName_;
57 std::shared_ptr<typename ServiceType::Request> request_;
58
59 void onServiceResponse(typename rclcpp::Client<ServiceType>::SharedFuture result)
60 {
61 result_ = result;
62 }
63};
64
65} // namespace client_behaviors
66} // namespace smacc2
virtual rclcpp::Node::SharedPtr getNode()
std::shared_ptr< typename ServiceType::Response > result_
std::shared_ptr< typename ServiceType::Request > request_
std::shared_ptr< rclcpp::Client< ServiceType > > client_
CbServiceCall(const char *serviceName, std::shared_ptr< typename ServiceType::Request >)
void onServiceResponse(typename rclcpp::Client< ServiceType >::SharedFuture result)