15 #ifndef CONCEALER__SERVICE_HPP_
16 #define CONCEALER__SERVICE_HPP_
18 #include <autoware_adapi_v1_msgs/msg/response_status.hpp>
21 #include <rclcpp/rclcpp.hpp>
24 #include <tier4_external_api_msgs/msg/response_status.hpp>
25 #include <tier4_rtc_msgs/msg/cooperate_response.hpp>
26 #include <tier4_rtc_msgs/srv/auto_mode_with_module.hpp>
27 #include <type_traits>
36 typename rclcpp::Client<T>::SharedPtr client;
38 rclcpp::WallRate interval;
41 template <
typename Node>
44 const std::chrono::nanoseconds & interval = std::chrono::seconds(3))
46 client(node.template create_client<T>(name, rmw_qos_profile_services_default)),
52 const typename T::Request::SharedPtr & request, std::size_t attempts_count,
53 std::chrono::seconds availability_timeout = std::chrono::seconds(180))
55 const auto availability_deadline = std::chrono::steady_clock::now() + availability_timeout;
57 while (rclcpp::ok() and not client->service_is_ready()) {
58 if (std::chrono::steady_clock::now() > availability_deadline) {
60 "Service ", std::quoted(name),
" is not ready after ", availability_timeout.count(),
66 auto receive = [
this](
const auto & response) {
67 if constexpr (DetectMember_status<typename T::Response>::value) {
68 if constexpr (std::is_same_v<
69 tier4_external_api_msgs::msg::ResponseStatus,
70 decltype(T::Response::status)>) {
72 }
else if constexpr (std::is_same_v<
73 autoware_adapi_v1_msgs::msg::ResponseStatus,
74 decltype(T::Response::status)>) {
75 return response->status.success;
77 static_assert([]() {
return false; });
79 }
else if constexpr (DetectMember_success<typename T::Response>::value) {
80 if constexpr (std::is_same_v<
bool, decltype(T::Response::success)>) {
81 return response->success;
83 static_assert([]() {
return false; });
85 }
else if constexpr (DetectMember_responses<typename T::Response>::value) {
86 if constexpr (std::is_same_v<
87 std::vector<tier4_rtc_msgs::msg::CooperateResponse>,
88 decltype(T::Response::responses)>) {
90 response->responses.begin(), response->responses.end(),
91 [](
const auto & response) { return response.success; });
93 static_assert([]() {
return false; });
96 static_assert([]() {
return false; });
100 for (std::size_t attempt = 0; attempt < attempts_count; ++attempt, interval.sleep()) {
101 if (
auto future = client->async_send_request(request);
102 future.wait_for(interval.period()) == std::future_status::ready and
103 receive(future.get())) {
109 "Requested the service ", std::quoted(name),
" ", attempts_count,
110 " times, but was not successful.");
Definition: service.hpp:33
auto operator()(const typename T::Request::SharedPtr &request, std::size_t attempts_count, std::chrono::seconds availability_timeout=std::chrono::seconds(180))
Definition: service.hpp:51
Service(const std::string &name, Node &node, const std::chrono::nanoseconds &interval=std::chrono::seconds(3))
Definition: service.hpp:42
Definition: autoware_universe.hpp:40
constexpr int SUCCESS
Definition: constants.hpp:22
std::string string
Definition: junit5.hpp:26
Autoware encountered some problem that led to a simulation failure.
Definition: exception.hpp:41