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"
31#include "rclcpp/detail/driven_future.hpp"
51 const char* service_name,
const char* type_name,
54 void* context, uint8_t sched_context,
55 size_t* out_handle_id);
154#if defined(NROS_CPP_HAS_STD_PROMISE)
159 using SharedRequest = ::std::shared_ptr<RequestType>;
160 using SharedResponse = ::std::shared_ptr<ResponseType>;
161 using SharedFuture = ::rclcpp::detail::DrivenSharedFuture<SharedResponse>;
189 uint8_t req_buf[::rclcpp::detail::buffer_bounds<RequestType>::tx];
191 if (RequestType::ffi_serialize(&req, req_buf,
sizeof(req_buf), &req_len) != 0) {
195 nros_cpp_service_client_send_on_handle(executor_, handle_id_, req_buf, req_len));
290 nros_cpp_service_client_server_available(
nullptr, executor_, handle_id_, &out);
293 if (ret != 0) return ::rclcpp::ResultOf<bool>::error(
static_cast<::
rclcpp::ErrorCode>(ret));
295 return ::rclcpp::ResultOf<bool>::ok(out != 0);
320 nros_cpp_service_client_wait_for_service(
nullptr, executor_, handle_id_, timeout_ms));
328 static_assert(::rclcpp::detail::refuse<T>::value, NROS_RCLCPP_REFUSE_UNBOUNDED_WAIT);
332#ifdef NROS_CPP_HAS_STD_CHRONO
338 template <typename Rep, typename Period>
339 Result wait_for_service(::std::chrono::duration<Rep, Period> timeout) {
340 const int64_t ms = ::rclcpp::detail::chrono_wait_budget_ms(timeout);
342 NROS_RCLCPP_SAY_REFUSED(NROS_RCLCPP_REFUSE_UNBOUNDED_WAIT_RUNTIME);
345 return wait_for_service(
static_cast<uint32_t
>(ms));
374 : executor_(other.executor_), initialized_(other.initialized_),
375 handle_id_(other.handle_id_), service_name_{} {
376 ::rclcpp::detail::assign_entity_name(service_name_, other.service_name_);
377 other.initialized_ =
false;
381 if (
this != &other) {
382 executor_ = other.executor_;
383 initialized_ = other.initialized_;
384 handle_id_ = other.handle_id_;
385 ::rclcpp::detail::assign_entity_name(service_name_, other.service_name_);
386 other.initialized_ =
false;
393 Client() : executor_(nullptr), initialized_(false), service_name_{} {}
399 friend class ::rclcpp::Node;
407 static void response_trampoline(
const uint8_t* data,
size_t len,
void* ctx) {
408 const TypedResponseFn user_fn = ::rclcpp::detail::fn_from_context<TypedResponseFn>(ctx);
409 if (user_fn ==
nullptr)
return;
411 if (ResponseType::ffi_deserialize(data, len, &response) != 0)
return;
425 nros_cpp_qos_t resp{};
426 if (!initialized_) return ::rclcpp::detail::qos_all_unknown();
427 if (nros_cpp_service_client_get_actual_qos(
nullptr, executor_, handle_id_, &req, &resp) !=
429 return ::rclcpp::detail::qos_all_unknown();
431 return ::rclcpp::detail::qos_from_ffi(request ? req : resp);
442 size_t handle_id_ =
static_cast<size_t>(-1);
446 char service_name_[::rclcpp::SERVICE_NAME_MAX];
463template <
typename S,
typename F,
typename>
465 const ::rclcpp::QoS& qos, const ::rclcpp::ClientOptions& options) {
474 uint8_t sched = (options.sched_context == ::rclcpp::SCHED_CONTEXT_UNSET)
476 :
static_cast<uint8_t
>(options.sched_context);
477 size_t handle =
static_cast<size_t>(-1);
479 &handle_, service_name, S::TYPE_NAME, S::Request::TYPE_HASH, ffi_qos,
481 ::rclcpp::detail::fn_to_context(user_fn), sched, &
handle);
483 out.executor_ = executor_handle_;
486 ::rclcpp::detail::assign_entity_name(out.service_name_, service_name);
487 out.initialized_ =
true;
Definition client.hpp:130
void(*)(const ResponseType &response) TypedResponseFn
Definition client.hpp:173
typename S::Request RequestType
Definition client.hpp:151
::rclcpp::ClientHandle< S > UniquePtr
rclcpp::Client<S>::UniquePtr — see SharedPtr.
Definition client.hpp:149
Client(Client &&other)
Definition client.hpp:373
::rclcpp::ClientHandle< S > SharedPtr
Definition client.hpp:142
~Client()
Definition client.hpp:361
Result async_send_request(const RequestType &req)
Definition client.hpp:187
::rclcpp::QoS get_request_publisher_actual_qos() const
Definition client.hpp:253
::rclcpp::ResultOf< bool > service_is_ready() const
Definition client.hpp:285
typename S::Response ResponseType
Definition client.hpp:152
Client()
Definition client.hpp:393
const char * get_service_name() const
Definition client.hpp:225
Result wait_for_service()
Definition client.hpp:327
Client & operator=(Client &&other)
Definition client.hpp:380
::rclcpp::ClientHandle< S > ConstSharedPtr
Definition client.hpp:147
::rclcpp::QoS get_response_subscription_actual_qos() const
Definition client.hpp:258
Result wait_for_service(uint32_t timeout_ms)
Definition client.hpp:317
bool is_valid() const
Check if the client was registered.
Definition client.hpp:199
size_t handle_id() const
Executor arena slot for the registration; SIZE_MAX until registered.
Definition client.hpp:350
::rclcpp::Owned<::rclcpp::PollClient< S > > create_client(const char *name, const ::rclcpp::QoS &qos=::rclcpp::QoS::services())
Definition result.hpp:332
Inline storage-size macros for opaque entity buffers.
int nros_cpp_ret_t
Definition future.hpp:25
constexpr nros_cpp_qos_t qos_to_ffi(const QoS &qos)
Definition qos.hpp:719
ErrorCode
Definition result.hpp:114
@ Error
Generic failure not covered by a more specific code.
Definition result.hpp:118
@ NotInitialized
Definition result.hpp:131
@ Unsupported
Operation not implemented by the active backend.
Definition result.hpp:152
ResultOf< void > Result
Definition result.hpp:247
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)
**auto handle
Definition client.hpp:127
void(* nros_cpp_service_response_callback_t)(const uint8_t *data, size_t len, void *ctx)
Definition client.hpp:48
rclcpp::Result, rclcpp::ErrorCode, and the RCLCPP_TRY macro.