10#ifndef NROS_CPP_CLIENT_HPP
11#define NROS_CPP_CLIENT_HPP
20#include "nros_cpp_ffi.h"
31 const char* service_name,
const char* type_name,
34 void* context, uint8_t sched_context,
35 size_t* out_handle_id);
123 if (!initialized_)
return -1;
127 if (
ret != 0)
return -1;
156 if (initialized_ && !callback_mode_) {
159 initialized_ =
false;
167 : executor_(
other.executor_), initialized_(
other.initialized_), user_fn_(
other.user_fn_),
168 user_fn_ctx_(
other.user_fn_ctx_), user_ctx_(
other.user_ctx_),
169 handle_id_(
other.handle_id_), callback_mode_(
other.callback_mode_) {
170 if (
other.initialized_ && !
other.callback_mode_) {
173 other.initialized_ =
false;
177 if (
this != &
other) {
178 if (initialized_ && !callback_mode_) {
181 executor_ =
other.executor_;
182 initialized_ =
other.initialized_;
183 user_fn_ =
other.user_fn_;
184 user_fn_ctx_ =
other.user_fn_ctx_;
185 user_ctx_ =
other.user_ctx_;
186 handle_id_ =
other.handle_id_;
187 callback_mode_ =
other.callback_mode_;
188 if (
other.initialized_ && !
other.callback_mode_) {
191 other.initialized_ =
false;
209 static void response_trampoline(
const uint8_t* data,
size_t len,
void*
ctx) {
211 if (
self ==
nullptr)
return;
213 if (ResponseType::ffi_deserialize(data, len, &
response) != 0)
return;
214 if (
self->user_fn_ !=
nullptr) {
216 }
else if (
self->user_fn_ctx_ !=
nullptr) {
221 alignas(8) uint8_t storage_[NROS_SERVICE_CLIENT_SIZE];
227 void* user_ctx_ =
nullptr;
228 size_t handle_id_ =
static_cast<size_t>(-1);
229 bool callback_mode_ =
false;
250 ffi_qos.liveliness_lease_ms =
qos.liveliness_lease_ms();
251 ffi_qos.avoid_ros_namespace_conventions =
qos.avoid_ros_namespace_conventions() ? 1 : 0;
255 out.executor_ = executor_handle_;
256 out.initialized_ =
true;
264template <
typename S,
typename F,
typename>
276 ffi_qos.liveliness_lease_ms =
qos.liveliness_lease_ms();
277 ffi_qos.avoid_ros_namespace_conventions =
qos.avoid_ros_namespace_conventions() ? 1 : 0;
280 out.user_fn_ctx_ =
nullptr;
281 out.user_ctx_ =
nullptr;
286 size_t handle =
static_cast<size_t>(-1);
290 &
out, sched, &handle);
292 out.executor_ = executor_handle_;
293 out.handle_id_ = handle;
294 out.callback_mode_ =
true;
295 out.initialized_ =
true;
typename S::Response ResponseType
Definition client.hpp:57
Result async_send_request(const RequestType &req)
Definition client.hpp:135
Client()
Definition client.hpp:198
void(*)(const ResponseType &response, void *ctx) TypedResponseFnWithCtx
Definition client.hpp:64
Client & operator=(Client &&other)
Definition client.hpp:176
int server_available() const
Definition client.hpp:122
size_t handle_id() const
Definition client.hpp:148
typename S::Request RequestType
Definition client.hpp:56
~Client()
Definition client.hpp:155
Client(Client &&other)
Definition client.hpp:166
bool is_valid() const
Check if the client is initialized and valid.
Definition client.hpp:107
void(*)(const ResponseType &response) TypedResponseFn
Definition client.hpp:63
Future< ResponseType > send_request(const RequestType &req)
Definition client.hpp:74
Result call(const RequestType &req, ResponseType &resp, uint32_t timeout_ms=5000)
Definition client.hpp:100
Result wait(void *executor_handle, uint32_t timeout_ms, T &out, uint32_t poll_ms=10)
Definition future.hpp:84
Result create_client(Client< S > &out, const char *service_name, const QoS &qos=QoS::services())
Definition client.hpp:240
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:28
Inline storage-size macros for opaque entity buffers.
nros::Future<T> — single-shot deferred result.
int nros_cpp_ret_t
Definition future.hpp:20
@ Error
Generic failure not covered by a more specific code.
nros::Node and global session helpers.
nros_cpp_qos_history_t
Definition qos.hpp:31
nros_cpp_qos_liveliness_t
Definition qos.hpp:35
nros_cpp_qos_durability_t
Definition qos.hpp:27
nros_cpp_qos_reliability_t
Definition qos.hpp:23
nros::Result, nros::ErrorCode, and the NROS_TRY macro.