From a579a496a901659a11d8424113678d27929e8226 Mon Sep 17 00:00:00 2001
From: ChenYing Kuo <evshary@gmail.com>
Date: Fri, 11 Oct 2024 11:51:12 +0800
Subject: [PATCH 1/2] Bump zenoh-c version.

Signed-off-by: ChenYing Kuo <evshary@gmail.com>
---
 rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp    | 4 ++--
 rmw_zenoh_cpp/src/detail/rmw_node_data.cpp         | 2 +-
 rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp    | 6 +++---
 rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp | 6 +++---
 rmw_zenoh_cpp/src/rmw_zenoh.cpp                    | 6 +++---
 zenoh_c_vendor/CMakeLists.txt                      | 2 +-
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
index d4f7c372..b5905dcb 100644
--- a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
+++ b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
@@ -132,8 +132,8 @@ rmw_ret_t rmw_context_impl_s::Data::subscribe_to_ros_graph()
       z_undeclare_subscriber(z_move(this->graph_subscriber_));
     });
   if (zc_liveliness_declare_subscriber(
-      &graph_subscriber_,
-      z_loan(session_), z_loan(keyexpr),
+      z_loan(session_), 
+      &graph_subscriber_, z_loan(keyexpr),
       z_move(callback), &sub_options) != Z_OK)
   {
     RMW_SET_ERROR_MSG("unable to create zenoh subscription");
diff --git a/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp
index ba57b23d..ea79154a 100644
--- a/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp
+++ b/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp
@@ -65,7 +65,7 @@ std::shared_ptr<NodeData> NodeData::make(
     [&token]() {
       z_drop(z_move(token));
     });
-  if (zc_liveliness_declare_token(&token, session, z_loan(liveliness_ke), NULL) != Z_OK) {
+  if (zc_liveliness_declare_token(session, &token, z_loan(liveliness_ke), NULL) != Z_OK) {
     RMW_ZENOH_LOG_ERROR_NAMED(
       "rmw_zenoh_cpp",
       "Unable to create liveliness token for the node.");
diff --git a/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp
index f04680aa..0eba9c38 100644
--- a/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp
+++ b/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp
@@ -132,7 +132,7 @@ std::shared_ptr<PublisherData> PublisherData::make(
 
     ze_owned_publication_cache_t pub_cache_;
     if (ze_declare_publication_cache(
-        &pub_cache_, session, z_loan(pub_ke), &pub_cache_opts))
+        session, &pub_cache_, z_loan(pub_ke), &pub_cache_opts))
     {
       RMW_SET_ERROR_MSG("unable to create zenoh publisher cache");
       return nullptr;
@@ -159,7 +159,7 @@ std::shared_ptr<PublisherData> PublisherData::make(
       z_undeclare_publisher(z_move(pub));
     });
   if (z_declare_publisher(
-      &pub, session, z_loan(pub_ke), &opts) != Z_OK)
+      session, &pub, z_loan(pub_ke), &opts) != Z_OK)
   {
     RMW_SET_ERROR_MSG("Unable to create Zenoh publisher.");
     return nullptr;
@@ -174,7 +174,7 @@ std::shared_ptr<PublisherData> PublisherData::make(
       z_drop(z_move(token));
     });
   if (zc_liveliness_declare_token(
-      &token, session, z_loan(liveliness_ke),
+      session, &token, z_loan(liveliness_ke),
       NULL) != Z_OK)
   {
     RMW_ZENOH_LOG_ERROR_NAMED(
diff --git a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
index f0d60b40..ac266849 100644
--- a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
+++ b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
@@ -220,7 +220,7 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
     sub_options.query_consolidation = z_query_consolidation_none();
     ze_owned_querying_subscriber_t sub;
     if (ze_declare_querying_subscriber(
-        &sub, session, z_loan(sub_ke), z_move(callback), &sub_options))
+        session, &sub, z_loan(sub_ke), z_move(callback), &sub_options))
     {
       RMW_SET_ERROR_MSG("unable to create zenoh subscription");
       return nullptr;
@@ -274,7 +274,7 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
 
     z_owned_subscriber_t sub;
     if (z_declare_subscriber(
-        &sub, session, z_loan(sub_ke), z_move(callback),
+        session, &sub, z_loan(sub_ke), z_move(callback),
         &sub_options) != Z_OK)
     {
       RMW_SET_ERROR_MSG("unable to create zenoh subscription");
@@ -295,7 +295,7 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
       }
     });
   if (zc_liveliness_declare_token(
-      &sub_data->token_, session, z_loan(liveliness_ke), NULL) != Z_OK)
+      session, &sub_data->token_, z_loan(liveliness_ke), NULL) != Z_OK)
   {
     RMW_ZENOH_LOG_ERROR_NAMED(
       "rmw_zenoh_cpp",
diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp
index b39b5b90..f588b071 100644
--- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp
+++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp
@@ -1609,7 +1609,7 @@ rmw_create_client(
       }
     });
   if (zc_liveliness_declare_token(
-      &client_data->token, session, z_loan(liveliness_ke),
+      session, &client_data->token, z_loan(liveliness_ke),
       NULL) != Z_OK)
   {
     RMW_ZENOH_LOG_ERROR_NAMED(
@@ -2170,7 +2170,7 @@ rmw_create_service(
   z_queryable_options_default(&qable_options);
   qable_options.complete = true;
   if (z_declare_queryable(
-      &service_data->qable, session, z_loan(service_data->keyexpr),
+      session, &service_data->qable, z_loan(service_data->keyexpr),
       z_move(callback), &qable_options) != Z_OK)
   {
     RMW_SET_ERROR_MSG("unable to create zenoh queryable");
@@ -2191,7 +2191,7 @@ rmw_create_service(
       }
     });
   if (zc_liveliness_declare_token(
-      &service_data->token, session, z_loan(liveliness_ke),
+      session, &service_data->token, z_loan(liveliness_ke),
       NULL) != Z_OK)
   {
     RMW_ZENOH_LOG_ERROR_NAMED(
diff --git a/zenoh_c_vendor/CMakeLists.txt b/zenoh_c_vendor/CMakeLists.txt
index b1dd363c..fe5467d4 100644
--- a/zenoh_c_vendor/CMakeLists.txt
+++ b/zenoh_c_vendor/CMakeLists.txt
@@ -26,7 +26,7 @@ set(ZENOHC_CARGO_FLAGS "--no-default-features$<SEMICOLON>--features=shared-memor
 # - https://github.com/eclipse-zenoh/zenoh-c/pull/620 (fix ze_querying_subscriber_get API to query newly discovered publishers)
 ament_vendor(zenoh_c_vendor
   VCS_URL https://github.com/eclipse-zenoh/zenoh-c.git
-  VCS_VERSION e270137cbe109032feecf06389b0560e75fc8c84
+  VCS_VERSION a5232cfa1ccc760b2e89fde3efd522795d0e1dc9
   CMAKE_ARGS
     "-DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS}"
     "-DZENOHC_BUILD_WITH_UNSTABLE_API=TRUE"

From 90827c77bf8f6a96d658ee57206a7a75a36f32bf Mon Sep 17 00:00:00 2001
From: ChenYing Kuo <evshary@gmail.com>
Date: Fri, 11 Oct 2024 13:39:53 +0800
Subject: [PATCH 2/2] Fix uncrustify.

Signed-off-by: ChenYing Kuo <evshary@gmail.com>
---
 rmw_zenoh_cpp/src/detail/attachment_helpers.cpp    |  6 ++++--
 rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp    |  5 +++--
 rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp    | 12 +++++++-----
 rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp |  8 +++++---
 rmw_zenoh_cpp/src/rmw_zenoh.cpp                    | 10 ++++++----
 5 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/rmw_zenoh_cpp/src/detail/attachment_helpers.cpp b/rmw_zenoh_cpp/src/detail/attachment_helpers.cpp
index 54ea7dae..cbdcfa1b 100644
--- a/rmw_zenoh_cpp/src/detail/attachment_helpers.cpp
+++ b/rmw_zenoh_cpp/src/detail/attachment_helpers.cpp
@@ -65,7 +65,8 @@ attachement_data_t::attachement_data_t(const z_loaned_bytes_t * attachment)
   ze_deserializer_deserialize_string(&deserializer, &key);
 
   // Deserialize the sequence_number
-  if (std::string_view(z_string_data(z_loan(key)),
+  if (std::string_view(
+      z_string_data(z_loan(key)),
       z_string_len(z_loan(key))) != "sequence_number")
   {
     throw std::runtime_error("sequence_number is not found in the attachment.");
@@ -77,7 +78,8 @@ attachement_data_t::attachement_data_t(const z_loaned_bytes_t * attachment)
 
   // Deserialize the source_timestamp
   ze_deserializer_deserialize_string(&deserializer, &key);
-  if (std::string_view(z_string_data(z_loan(key)),
+  if (std::string_view(
+      z_string_data(z_loan(key)),
       z_string_len(z_loan(key))) != "source_timestamp")
   {
     throw std::runtime_error("source_timestamp is not found in the attachment");
diff --git a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
index b5905dcb..959f846a 100644
--- a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
+++ b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
@@ -132,7 +132,7 @@ rmw_ret_t rmw_context_impl_s::Data::subscribe_to_ros_graph()
       z_undeclare_subscriber(z_move(this->graph_subscriber_));
     });
   if (zc_liveliness_declare_subscriber(
-      z_loan(session_), 
+      z_loan(session_),
       &graph_subscriber_, z_loan(keyexpr),
       z_move(callback), &sub_options) != Z_OK)
   {
@@ -333,7 +333,8 @@ rmw_context_impl_s::rmw_context_impl_s(
 }
 
 ///=============================================================================
-rmw_context_impl_s::~rmw_context_impl_s() {
+rmw_context_impl_s::~rmw_context_impl_s()
+{
   // std::lock_guard<std::recursive_mutex> lock(data_->mutex_);
   // z_drop(z_move(data_->session_));
 }
diff --git a/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp
index 0eba9c38..2de77b33 100644
--- a/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp
+++ b/rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp
@@ -253,7 +253,7 @@ rmw_ret_t PublisherData::publish(
       if (shmbuf.has_value()) {
         z_drop(z_move(shmbuf.value()));
       }
-  });
+    });
 
   rcutils_allocator_t * allocator = &rmw_node_->context->options.allocator;
 
@@ -324,8 +324,9 @@ rmw_ret_t PublisherData::publish(
   z_result_t res = z_publisher_put(z_loan(pub_), z_move(payload), &options);
   if (res != Z_OK) {
     if (res == Z_ESESSION_CLOSED) {
-      RMW_ZENOH_LOG_WARN_NAMED("rmw_zenoh_cpp",
-          "unable to publish message since the zenoh session is closed");
+      RMW_ZENOH_LOG_WARN_NAMED(
+        "rmw_zenoh_cpp",
+        "unable to publish message since the zenoh session is closed");
     } else {
       RMW_SET_ERROR_MSG("unable to publish message");
       return RMW_RET_ERROR;
@@ -368,8 +369,9 @@ rmw_ret_t PublisherData::publish_serialized_message(
   z_result_t res = z_publisher_put(z_loan(pub_), z_move(payload), &options);
   if (res != Z_OK) {
     if (res == Z_ESESSION_CLOSED) {
-      RMW_ZENOH_LOG_WARN_NAMED("rmw_zenoh_cpp",
-          "unable to publish message since the zenoh session is closed");
+      RMW_ZENOH_LOG_WARN_NAMED(
+        "rmw_zenoh_cpp",
+        "unable to publish message since the zenoh session is closed");
     } else {
       RMW_SET_ERROR_MSG("unable to publish message");
       return RMW_RET_ERROR;
diff --git a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
index ac266849..6709083c 100644
--- a/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
+++ b/rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
@@ -203,7 +203,7 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
     // Make the initial query to hit all the PublicationCaches, using a query_selector with
     // '*' in place of the queryable_prefix of each PublicationCache
     const std::string selector = "*/" +
-    sub_data->entity_->topic_info()->topic_keyexpr_;
+      sub_data->entity_->topic_info()->topic_keyexpr_;
     z_view_keyexpr_t selector_ke;
     z_view_keyexpr_from_str(&selector_ke, selector.c_str());
     sub_options.query_selector = z_loan(selector_ke);
@@ -291,7 +291,7 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
   auto free_token = rcpputils::make_scope_exit(
     [sub_data]() {
       if (sub_data != nullptr) {
-        z_drop(z_move(sub_data->token_ ));
+        z_drop(z_move(sub_data->token_));
       }
     });
   if (zc_liveliness_declare_token(
@@ -556,7 +556,9 @@ void SubscriptionData::add_new_message(
   const size_t gid_hash = hash_gid(msg->attachment.source_gid);
   auto last_known_pub_it = last_known_published_msg_.find(gid_hash);
   if (last_known_pub_it != last_known_published_msg_.end()) {
-    const int64_t seq_increment = std::abs(msg->attachment.sequence_number - last_known_pub_it->second);
+    const int64_t seq_increment = std::abs(
+      msg->attachment.sequence_number -
+      last_known_pub_it->second);
     if (seq_increment > 1) {
       const size_t num_msg_lost = seq_increment - 1;
       total_messages_lost_ += num_msg_lost;
diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp
index f588b071..cc8b8d5c 100644
--- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp
+++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp
@@ -1764,8 +1764,9 @@ rmw_send_request(
   z_get_options_default(&opts);
 
   z_owned_bytes_t attachment;
-  rmw_zenoh_cpp::create_map_and_set_sequence_num(&attachment, *sequence_id,
-      client_data->client_gid);
+  rmw_zenoh_cpp::create_map_and_set_sequence_num(
+    &attachment, *sequence_id,
+    client_data->client_gid);
   auto free_attachment = rcpputils::make_scope_exit(
     [&attachment]() {
       z_drop(z_move(attachment));
@@ -2433,8 +2434,9 @@ rmw_send_response(
   z_query_reply_options_default(&options);
 
   z_owned_bytes_t attachment;
-  rmw_zenoh_cpp::create_map_and_set_sequence_num(&attachment, request_header->sequence_number,
-      request_header->writer_guid);
+  rmw_zenoh_cpp::create_map_and_set_sequence_num(
+    &attachment, request_header->sequence_number,
+    request_header->writer_guid);
   options.attachment = z_move(attachment);
 
   z_owned_bytes_t payload;