SMACC2
Loading...
Searching...
No Matches
smacc_service_server_client.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
21#pragma once
22
23#include <optional>
26
27namespace smacc2
28{
29namespace client_bases
30{
31template <typename TService>
33{
34 using TServiceRequest = typename TService::Request;
35 using TServiceResponse = typename TService::Response;
36
37public:
38 std::optional<std::string> serviceName_;
45
47
49 const std::shared_ptr<typename TService::Request>,
50 std::shared_ptr<typename TService::Response>)>
52
53 template <typename T>
54 boost::signals2::connection onServiceRequestReceived(
55 void (T::*callback)(
58 T * object)
59 {
62 }
63
64 void onInitialize() override
65 {
66 if (!initialized_)
67 {
68 if (!serviceName_)
69 {
71 getLogger(),
72 "[" << this->getName() << "] service server with no service name set. Skipping.");
73 }
74 else
75 {
77 getLogger(), "[" << this->getName() << "] Client Service: " << *serviceName_);
78
79 server_ = getNode()->create_service<TService>(
80 *serviceName_, std::bind(
82 std::placeholders::_1, std::placeholders::_2));
83
84 this->initialized_ = true;
85 }
86 }
87 }
88
89private:
91 const std::shared_ptr<typename TService::Request> req,
92 std::shared_ptr<typename TService::Response> res)
93 {
95 }
96 typename rclcpp::Service<TService>::SharedPtr server_;
98};
99} // namespace client_bases
100} // namespace smacc2
rclcpp::Node::SharedPtr getNode()
Definition client.cpp:60
ISmaccStateMachine * getStateMachine()
virtual std::string getName() const
Definition client.cpp:42
rclcpp::Logger getLogger()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
void serviceCallback(const std::shared_ptr< typename TService::Request > req, std::shared_ptr< typename TService::Response > res)
boost::signals2::connection onServiceRequestReceived(void(T::*callback)(const std::shared_ptr< typename TService::Request >, std::shared_ptr< typename TService::Response >), T *object)
smacc2::SmaccSignal< void(const std::shared_ptr< typename TService::Request >, std::shared_ptr< typename TService::Response >)> onServiceRequestReceived_