16#ifndef NROS_RCLCPP_CLIENT_HPP
17#define NROS_RCLCPP_CLIENT_HPP
22#include "rclcpp/detail/callback_context.hpp"
23#include "rclcpp/client_handle.hpp"
25#include "rclcpp/detail/entity_name.hpp"
26#include "rclcpp/logging.hpp"
28#include "rclcpp/size_bound.hpp"
30#include "rclcpp/detail/nros_cpp_ffi.h"
50 const char* service_name,
const char* type_name,
53 void* context, uint8_t sched_context,
54 size_t* out_handle_id);
178 uint8_t req_buf[::rclcpp::detail::buffer_bounds<RequestType>::tx];
180 if (RequestType::ffi_serialize(&req, req_buf,
sizeof(req_buf), &req_len) != 0) {
184 nros_cpp_service_client_send_on_handle(executor_, handle_id_, req_buf, req_len));
279 nros_cpp_service_client_server_available(
nullptr, executor_, handle_id_, &out);
282 if (ret != 0) return ::rclcpp::ResultOf<bool>::error(
static_cast<::
rclcpp::ErrorCode>(ret));
284 return ::rclcpp::ResultOf<bool>::ok(out != 0);
309 nros_cpp_service_client_wait_for_service(
nullptr, executor_, handle_id_, timeout_ms));
317 static_assert(::rclcpp::detail::refuse<T>::value, NROS_RCLCPP_REFUSE_UNBOUNDED_WAIT);
346 : executor_(other.executor_), initialized_(other.initialized_),
347 handle_id_(other.handle_id_), service_name_{} {
348 ::rclcpp::detail::assign_entity_name(service_name_, other.service_name_);
349 other.initialized_ =
false;
353 if (
this != &other) {
354 executor_ = other.executor_;
355 initialized_ = other.initialized_;
356 handle_id_ = other.handle_id_;
357 ::rclcpp::detail::assign_entity_name(service_name_, other.service_name_);
358 other.initialized_ =
false;
365 Client() : executor_(nullptr), initialized_(false), service_name_{} {}
371 friend class ::rclcpp::Node;
379 static void response_trampoline(
const uint8_t* data,
size_t len,
void* ctx) {
380 const TypedResponseFn user_fn = ::rclcpp::detail::fn_from_context<TypedResponseFn>(ctx);
381 if (user_fn ==
nullptr)
return;
383 if (ResponseType::ffi_deserialize(data, len, &response) != 0)
return;
398 if (!initialized_) return ::rclcpp::detail::qos_all_unknown();
399 if (nros_cpp_service_client_get_actual_qos(
nullptr, executor_, handle_id_, &req, &resp) !=
401 return ::rclcpp::detail::qos_all_unknown();
403 return ::rclcpp::detail::qos_from_ffi(request ? req : resp);
414 size_t handle_id_ =
static_cast<size_t>(-1);
418 char service_name_[::rclcpp::SERVICE_NAME_MAX];
435template <
typename S,
typename F,
typename>
437 const ::rclcpp::QoS& qos, const ::rclcpp::ClientOptions& options) {
448 : static_cast<uint8_t>(options.sched_context);
449 size_t handle =
static_cast<size_t>(-1);
451 &handle_, service_name, S::TYPE_NAME, S::Request::TYPE_HASH, ffi_qos,
453 ::rclcpp::detail::fn_to_context(user_fn), sched, &handle);
455 out.executor_ = executor_handle_;
456 out.handle_id_ = handle;
458 ::rclcpp::detail::assign_entity_name(out.service_name_, service_name);
459 out.initialized_ =
true;
Definition client.hpp:129
::rclcpp::QoS get_request_publisher_actual_qos() const
Definition client.hpp:242
void(*)(const ResponseType &response) TypedResponseFn
Definition client.hpp:162
Result wait_for_service(uint32_t timeout_ms)
Definition client.hpp:306
::rclcpp::ResultOf< bool > service_is_ready() const
Definition client.hpp:274
Result async_send_request(const RequestType &req)
Definition client.hpp:176
typename S::Request RequestType
Definition client.hpp:150
bool is_valid() const
Check if the client was registered.
Definition client.hpp:188
const char * get_service_name() const
Definition client.hpp:214
::rclcpp::QoS get_response_subscription_actual_qos() const
Definition client.hpp:247
~Client()
Definition client.hpp:333
Client()
Definition client.hpp:365
Result wait_for_service()
Definition client.hpp:316
Client(Client &&other)
Definition client.hpp:345
Client & operator=(Client &&other)
Definition client.hpp:352
size_t handle_id() const
Executor arena slot for the registration; SIZE_MAX until registered.
Definition client.hpp:322
typename S::Response ResponseType
Definition client.hpp:151
::rclcpp::Owned<::rclcpp::PollClient< S > > create_client(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Definition result.hpp:216
Definition result.hpp:331
Inline storage-size macros for opaque entity buffers.
int nros_cpp_ret_t
Definition future.hpp:21
ResultOf< void > Result
Definition result.hpp:246
ErrorCode
Definition result.hpp:113
@ Error
Generic failure not covered by a more specific code.
@ Unsupported
Operation not implemented by the active backend.
rclcpp::Node and global session helpers.
rclcpp::QoS — full DDS-shaped QoS settings (Phase 108.B.7).
nros_cpp_ret_t nros_cpp_service_client_register(const nros_cpp_node_t *node, const char *service_name, const char *type_name, const char *type_hash, nros_cpp_qos_t qos, nros_cpp_service_response_callback_t callback, void *context, uint8_t sched_context, size_t *out_handle_id)
void(* nros_cpp_service_response_callback_t)(const uint8_t *data, size_t len, void *ctx)
Definition client.hpp:47
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.