Skip to content

Commit 8cd19bf

Browse files
committed
Added feedback
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
1 parent d4b9613 commit 8cd19bf

16 files changed

+136
-150
lines changed

rmw_zenoh_cpp/src/detail/attachment_helpers.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ namespace rmw_zenoh_cpp
3131
{
3232

3333
AttachmentData::AttachmentData(
34-
const int64_t _sequence_number,
35-
const int64_t _source_timestamp,
36-
const std::vector<uint8_t> _source_gid)
34+
const int64_t sequence_number,
35+
const int64_t source_timestamp,
36+
const std::vector<uint8_t> source_gid)
37+
: sequence_number_(sequence_number),
38+
source_timestamp_(source_timestamp),
39+
source_gid_(source_gid),
40+
gid_hash_(hash_gid(source_gid))
3741
{
38-
sequence_number_ = _sequence_number;
39-
source_timestamp_ = _source_timestamp;
40-
source_gid_ = _source_gid;
41-
gid_hash_ = hash_gid(source_gid_);
4242
}
4343

4444
AttachmentData::AttachmentData(AttachmentData && data)
@@ -85,9 +85,9 @@ zenoh::Bytes AttachmentData::serialize_to_zbytes()
8585
return std::move(serializer).finish();
8686
}
8787

88-
AttachmentData::AttachmentData(const zenoh::Bytes & attachment)
88+
AttachmentData::AttachmentData(const zenoh::Bytes & bytes)
8989
{
90-
zenoh::ext::Deserializer deserializer(std::move(attachment));
90+
zenoh::ext::Deserializer deserializer(std::move(bytes));
9191
const auto sequence_number_str = deserializer.deserialize<std::string>();
9292
if (sequence_number_str != "sequence_number") {
9393
throw std::runtime_error("sequence_number is not found in the attachment.");

rmw_zenoh_cpp/src/detail/attachment_helpers.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424

2525
namespace rmw_zenoh_cpp
2626
{
27+
///=============================================================================
2728
class AttachmentData final
2829
{
2930
public:
30-
explicit AttachmentData(
31-
const int64_t _sequence_number,
32-
const int64_t _source_timestamp,
33-
const std::vector<uint8_t> _source_gid);
31+
AttachmentData(
32+
const int64_t sequence_number,
33+
const int64_t source_timestamp,
34+
const std::vector<uint8_t> source_gid);
3435

3536
explicit AttachmentData(const zenoh::Bytes & bytes);
3637
explicit AttachmentData(AttachmentData && data);

rmw_zenoh_cpp/src/detail/graph_cache.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ TopicData::TopicData(ConstEntityPtr entity)
6969
}
7070

7171
///=============================================================================
72-
GraphCache::GraphCache(const std::string & zid)
73-
: zid_str_(zid)
72+
GraphCache::GraphCache(const zenoh::Id & zid)
73+
: zid_str_(zid.to_string())
7474
{
7575
// Do nothing.
7676
}

rmw_zenoh_cpp/src/detail/graph_cache.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "rmw/get_topic_endpoint_info.h"
3737
#include "rmw/names_and_types.h"
3838

39+
#include <zenoh/api/id.hxx>
3940

4041
namespace rmw_zenoh_cpp
4142
{
@@ -110,7 +111,7 @@ class GraphCache final
110111
/// @param id The id of the zenoh session that is building the graph cache.
111112
/// This is used to infer which entities originated from the current session
112113
/// so that appropriate event callbacks may be triggered.
113-
explicit GraphCache(const std::string & zid);
114+
explicit GraphCache(const zenoh::Id & zid);
114115

115116
// Parse a PUT message over a token's key-expression and update the graph.
116117
void parse_put(const std::string & keyexpr, bool ignore_from_current_session = false);

rmw_zenoh_cpp/src/detail/rmw_client_data.cpp

+18-16
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ bool ClientData::init(const std::shared_ptr<zenoh::Session> session)
182182
keyexpr_ = zenoh::KeyExpr(topic_keyexpr);
183183
// TODO(ahcorde) check KeyExpr
184184
std::string liveliness_keyexpr = this->entity_->liveliness_keyexpr();
185-
zenoh::ZResult err;
185+
zenoh::ZResult result;
186186
this->token_ = session->liveliness_declare_token(
187187
zenoh::KeyExpr(liveliness_keyexpr),
188188
zenoh::Session::LivelinessDeclarationOptions::create_default(),
189-
&err);
190-
if (err != Z_OK) {
189+
&result);
190+
if (result != Z_OK) {
191191
RMW_ZENOH_LOG_ERROR_NAMED(
192192
"rmw_zenoh_cpp",
193193
"Unable to create liveliness token for the client.");
@@ -280,14 +280,10 @@ rmw_ret_t ClientData::take_response(
280280
const zenoh::Sample & sample = reply.get_ok();
281281

282282
// Object that manages the raw buffer
283-
auto & payload = sample.get_payload();
284-
auto slice = payload.slice_iter().next();
285-
if (slice.has_value()) {
286-
const uint8_t * payload = slice.value().data;
287-
const size_t payload_len = slice.value().len;
288-
283+
auto payload = sample.get_payload().as_vector();
284+
if (payload.size() > 0) {
289285
eprosima::fastcdr::FastBuffer fastbuffer(
290-
reinterpret_cast<char *>(const_cast<uint8_t *>(payload)), payload_len);
286+
reinterpret_cast<char *>(const_cast<uint8_t *>(payload.data())), payload.size());
291287

292288
// Object that serializes the data
293289
rmw_zenoh_cpp::Cdr deser(fastbuffer);
@@ -401,10 +397,10 @@ rmw_ret_t ClientData::send_request(
401397
std::vector<uint8_t> raw_bytes(
402398
reinterpret_cast<const uint8_t *>(request_bytes),
403399
reinterpret_cast<const uint8_t *>(request_bytes) + data_length);
404-
opts.payload = zenoh::Bytes(raw_bytes);
400+
opts.payload = zenoh::Bytes(std::move(raw_bytes));
405401

406402
std::weak_ptr<rmw_zenoh_cpp::ClientData> client_data = shared_from_this();
407-
zenoh::ZResult err;
403+
zenoh::ZResult result;
408404
std::string parameters;
409405
context_impl->session()->get(
410406
keyexpr_.value(),
@@ -448,7 +444,13 @@ rmw_ret_t ClientData::send_request(
448444
}
449445
},
450446
std::move(opts),
451-
&err);
447+
&result);
448+
if (result != Z_OK) {
449+
RMW_ZENOH_LOG_DEBUG_NAMED(
450+
"rmw_zenoh_cpp",
451+
"ClientData unable to call get");
452+
return RMW_RET_ERROR;
453+
}
452454
return RMW_RET_OK;
453455
}
454456

@@ -506,9 +508,9 @@ rmw_ret_t ClientData::shutdown()
506508

507509
// Unregister this node from the ROS graph.
508510
if (initialized_) {
509-
zenoh::ZResult err;
510-
std::move(token_).value().undeclare(&err);
511-
if (err != Z_OK) {
511+
zenoh::ZResult result;
512+
std::move(token_).value().undeclare(&result);
513+
if (result != Z_OK) {
512514
RMW_ZENOH_LOG_ERROR_NAMED(
513515
"rmw_zenoh_cpp",
514516
"Unable to undeclare liveliness token");

rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp

+11-25
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ class rmw_context_impl_s::Data final
111111
"Unable to connect to a Zenoh router. "
112112
"Have you started a router with `ros2 run rmw_zenoh_cpp rmw_zenohd`?");
113113
}
114-
zenoh::ZResult err;
115-
this->session_->get_routers_z_id(&err);
116-
if (err != Z_OK) {
114+
zenoh::ZResult result;
115+
this->session_->get_routers_z_id(&result);
116+
if (result != Z_OK) {
117117
++connection_attempts;
118118
} else {
119119
ret = RMW_RET_OK;
@@ -127,7 +127,7 @@ class rmw_context_impl_s::Data final
127127

128128
// Initialize the graph cache.
129129
graph_cache_ =
130-
std::make_shared<rmw_zenoh_cpp::GraphCache>(this->session_->get_zid().to_string());
130+
std::make_shared<rmw_zenoh_cpp::GraphCache>(this->session_->get_zid());
131131
// Setup liveliness subscriptions for discovery.
132132
std::string liveliness_str = rmw_zenoh_cpp::liveliness::subscription_token(domain_id);
133133

@@ -155,14 +155,13 @@ class rmw_context_impl_s::Data final
155155
options.target = zenoh::QueryTarget::Z_QUERY_TARGET_ALL;
156156
options.payload = "";
157157

158-
zenoh::ZResult err;
159158
auto replies = session_->liveliness_get(
160159
keyexpr,
161160
zenoh::channels::FifoChannel(SIZE_MAX - 1),
162161
zenoh::Session::LivelinessGetOptions::create_default(),
163-
&err);
162+
&result);
164163

165-
if (err != Z_OK) {
164+
if (result != Z_OK) {
166165
throw std::runtime_error("Error getting liveliness. ");
167166
}
168167

@@ -223,9 +222,9 @@ class rmw_context_impl_s::Data final
223222
},
224223
zenoh::closures::none,
225224
std::move(sub_options),
226-
&err);
225+
&result);
227226

228-
if (err != Z_OK) {
227+
if (result != Z_OK) {
229228
RMW_SET_ERROR_MSG("unable to create zenoh subscription");
230229
throw std::runtime_error("Unable to subscribe to ROS graph updates.");
231230
}
@@ -241,22 +240,9 @@ class rmw_context_impl_s::Data final
241240
return ret;
242241
}
243242

244-
// TODO(ahcorde): review this
245-
// // Shutdown all the nodes in this context.
246-
// for (auto node_it = nodes_.begin(); node_it != nodes_.end(); ++node_it) {
247-
// ret = node_it->second->shutdown();
248-
// if (ret != RMW_RET_OK) {
249-
// RMW_ZENOH_LOG_ERROR_NAMED(
250-
// "rmw_zenoh_cpp",
251-
// "Unable to shutdown node with id %zu. rmw_ret_t code: %zu.",
252-
// node_it->second->id(),
253-
// ret
254-
// );
255-
// }
256-
257-
zenoh::ZResult err;
258-
std::move(graph_subscriber_cpp_).value().undeclare(&err);
259-
if (err != Z_OK) {
243+
zenoh::ZResult result;
244+
std::move(graph_subscriber_cpp_).value().undeclare(&result);
245+
if (result != Z_OK) {
260246
RMW_ZENOH_LOG_ERROR_NAMED(
261247
"rmw_zenoh_cpp",
262248
"Unable to undeclare liveliness token");

rmw_zenoh_cpp/src/detail/rmw_node_data.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ std::shared_ptr<NodeData> NodeData::make(
5858

5959
// Create the liveliness token.
6060
std::string liveliness_keyexpr = entity->liveliness_keyexpr();
61-
zenoh::ZResult err;
61+
zenoh::ZResult result;
6262
auto token = session->liveliness_declare_token(
6363
zenoh::KeyExpr(liveliness_keyexpr),
6464
zenoh::Session::LivelinessDeclarationOptions::create_default(),
65-
&err);
66-
if (err != Z_OK) {
65+
&result);
66+
if (result != Z_OK) {
6767
RMW_ZENOH_LOG_ERROR_NAMED(
6868
"rmw_zenoh_cpp",
6969
"Unable to create liveliness token for the node.");
@@ -393,9 +393,9 @@ rmw_ret_t NodeData::shutdown()
393393
}
394394

395395
// Unregister this node from the ROS graph.
396-
zenoh::ZResult err;
397-
std::move(token_).value().undeclare(&err);
398-
if (err != Z_OK) {
396+
zenoh::ZResult result;
397+
std::move(token_).value().undeclare(&result);
398+
if (result != Z_OK) {
399399
RMW_ZENOH_LOG_ERROR_NAMED(
400400
"rmw_zenoh_cpp",
401401
"Unable to undeclare liveliness token");

rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ std::shared_ptr<PublisherData> PublisherData::make(
103103
return nullptr;
104104
}
105105

106-
zenoh::ZResult err;
106+
zenoh::ZResult result;
107107
std::optional<zenoh::ext::PublicationCache> pub_cache;
108108
zenoh::KeyExpr pub_ke(entity->topic_info()->topic_keyexpr_);
109109
// Create a Publication Cache if durability is transient_local.
@@ -117,9 +117,9 @@ std::shared_ptr<PublisherData> PublisherData::make(
117117
std::string queryable_prefix = entity->zid();
118118
pub_cache_opts.queryable_prefix = zenoh::KeyExpr(queryable_prefix);
119119

120-
pub_cache = session->declare_publication_cache(pub_ke, std::move(pub_cache_opts), &err);
120+
pub_cache = session->declare_publication_cache(pub_ke, std::move(pub_cache_opts), &result);
121121

122-
if (err != Z_OK) {
122+
if (result != Z_OK) {
123123
RMW_SET_ERROR_MSG("unable to create zenoh publisher cache");
124124
return nullptr;
125125
}
@@ -135,9 +135,9 @@ std::shared_ptr<PublisherData> PublisherData::make(
135135
opts.congestion_control = Z_CONGESTION_CONTROL_BLOCK;
136136
}
137137
}
138-
auto pub = session->declare_publisher(pub_ke, std::move(opts), &err);
138+
auto pub = session->declare_publisher(pub_ke, std::move(opts), &result);
139139

140-
if (err != Z_OK) {
140+
if (result != Z_OK) {
141141
RMW_SET_ERROR_MSG("Unable to create Zenoh publisher.");
142142
return nullptr;
143143
}
@@ -146,8 +146,8 @@ std::shared_ptr<PublisherData> PublisherData::make(
146146
auto token = session->liveliness_declare_token(
147147
zenoh::KeyExpr(liveliness_keyexpr),
148148
zenoh::Session::LivelinessDeclarationOptions::create_default(),
149-
&err);
150-
if (err != Z_OK) {
149+
&result);
150+
if (result != Z_OK) {
151151
RMW_ZENOH_LOG_ERROR_NAMED(
152152
"rmw_zenoh_cpp",
153153
"Unable to create liveliness token for the publisher.");
@@ -273,7 +273,7 @@ rmw_ret_t PublisherData::publish(
273273
// The encoding is simply forwarded and is useful when key expressions in the
274274
// session use different encoding formats. In our case, all key expressions
275275
// will be encoded with CDR so it does not really matter.
276-
zenoh::ZResult err;
276+
zenoh::ZResult result;
277277
auto options = zenoh::Publisher::PutOptions::create_default();
278278
options.attachment = create_map_and_set_sequence_num(
279279
sequence_number_++,
@@ -285,9 +285,9 @@ rmw_ret_t PublisherData::publish(
285285
reinterpret_cast<const uint8_t *>(msg_bytes) + data_length);
286286
zenoh::Bytes payload(raw_image);
287287

288-
pub_.put(std::move(payload), std::move(options), &err);
289-
if (err != Z_OK) {
290-
if (err == Z_ESESSION_CLOSED) {
288+
pub_.put(std::move(payload), std::move(options), &result);
289+
if (result != Z_OK) {
290+
if (result == Z_ESESSION_CLOSED) {
291291
RMW_ZENOH_LOG_WARN_NAMED(
292292
"rmw_zenoh_cpp",
293293
"unable to publish message since the zenoh session is closed");
@@ -319,7 +319,7 @@ rmw_ret_t PublisherData::publish_serialized_message(
319319
// The encoding is simply forwarded and is useful when key expressions in the
320320
// session use different encoding formats. In our case, all key expressions
321321
// will be encoded with CDR so it does not really matter.
322-
zenoh::ZResult err;
322+
zenoh::ZResult result;
323323
auto options = zenoh::Publisher::PutOptions::create_default();
324324
options.attachment = create_map_and_set_sequence_num(sequence_number_++, entity_->copy_gid());
325325

@@ -328,9 +328,9 @@ rmw_ret_t PublisherData::publish_serialized_message(
328328
serialized_message->buffer + data_length);
329329
zenoh::Bytes payload(raw_image);
330330

331-
pub_.put(std::move(payload), std::move(options), &err);
332-
if (err != Z_OK) {
333-
if (err == Z_ESESSION_CLOSED) {
331+
pub_.put(std::move(payload), std::move(options), &result);
332+
if (result != Z_OK) {
333+
if (result == Z_ESESSION_CLOSED) {
334334
RMW_ZENOH_LOG_WARN_NAMED(
335335
"rmw_zenoh_cpp",
336336
"unable to publish message since the zenoh session is closed");
@@ -408,16 +408,16 @@ rmw_ret_t PublisherData::shutdown()
408408
}
409409

410410
// Unregister this publisher from the ROS graph.
411-
zenoh::ZResult err;
412-
std::move(token_).value().undeclare(&err);
413-
if (err != Z_OK) {
411+
zenoh::ZResult result;
412+
std::move(token_).value().undeclare(&result);
413+
if (result != Z_OK) {
414414
RMW_ZENOH_LOG_ERROR_NAMED(
415415
"rmw_zenoh_cpp",
416416
"Unable to undeclare liveliness token");
417417
return RMW_RET_ERROR;
418418
}
419-
std::move(pub_).undeclare(&err);
420-
if (err != Z_OK) {
419+
std::move(pub_).undeclare(&result);
420+
if (result != Z_OK) {
421421
RMW_ZENOH_LOG_ERROR_NAMED(
422422
"rmw_zenoh_cpp",
423423
"Unable to undeclare publisher");

rmw_zenoh_cpp/src/detail/rmw_publisher_data.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class PublisherData final
7171

7272
// Copy the GID of this PublisherData into an rmw_gid_t.
7373
void copy_gid(uint8_t out_gid[RMW_GID_STORAGE_SIZE]) const;
74+
75+
// Return a copy of the GID of this publisher.
7476
std::vector<uint8_t> copy_gid() const;
7577

7678
// Returns true if liveliness token is still valid.

0 commit comments

Comments
 (0)