Skip to content

Commit 196f30d

Browse files
ahcordeYadunund
authored andcommitted
zenoh_c to zenoh_cpp
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Fixed CI Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> tokens Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> removed zenoh_router_check Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> removed rmw_init_options_impl.hpp Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Publisher Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Added subscribers Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Removed zid_to_str Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> use zenoh::KeyExpr Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> service data Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> client data Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Removed unused signature Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> cleanups and shm Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> more changes Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Fixed segfault Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> make linters happy Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> removed zenohc from CMakeLists.txt and warning Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Restored one method Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> wrap the zenoh session with a shared pointer Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Changes missed Signed-off-by: Yadunund <yadunund@gmail.com>
1 parent 7fcd074 commit 196f30d

37 files changed

+1042
-1148
lines changed

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ jobs:
4040
with:
4141
package-name: |
4242
rmw_zenoh_cpp
43-
zenoh_c_vendor
43+
zenoh_cpp_vendor
4444
target-ros2-distro: ${{ matrix.ROS_DISTRO }}
4545
vcs-repo-file-url: ${{ matrix.BUILD_TYPE == 'source' && env.ROS2_REPOS_FILE_URL || '' }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Build `rmw_zenoh_cpp`
1919

2020
>Note: By default, we vendor and compile `zenoh-c` with a subset of `zenoh` features.
2121
The `ZENOHC_CARGO_FLAGS` CMake argument may be overwritten with other features included if required.
22-
See [zenoh_c_vendor/CMakeLists.txt](./zenoh_c_vendor/CMakeLists.txt) for more details.
22+
See [zenoh_cpp_vendor/CMakeLists.txt](./zenoh_cpp_vendor/CMakeLists.txt) for more details.
2323

2424
```bash
2525
mkdir ~/ws_rmw_zenoh/src -p && cd ~/ws_rmw_zenoh/src

rmw_zenoh_cpp/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ find_package(rcutils REQUIRED)
2121
find_package(rosidl_typesupport_fastrtps_c REQUIRED)
2222
find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)
2323
find_package(rmw REQUIRED)
24-
find_package(zenoh_c_vendor REQUIRED)
24+
find_package(zenoh_cpp_vendor REQUIRED)
2525

2626
add_library(rmw_zenoh_cpp SHARED
2727
src/detail/attachment_helpers.cpp
@@ -45,7 +45,6 @@ add_library(rmw_zenoh_cpp SHARED
4545
src/detail/type_support.cpp
4646
src/detail/type_support_common.cpp
4747
src/detail/zenoh_config.cpp
48-
src/detail/zenoh_router_check.cpp
4948
src/detail/zenoh_utils.cpp
5049
src/rmw_event.cpp
5150
src/rmw_get_network_flow_endpoints.cpp
@@ -68,7 +67,7 @@ target_link_libraries(rmw_zenoh_cpp
6867
rosidl_typesupport_fastrtps_c::rosidl_typesupport_fastrtps_c
6968
rosidl_typesupport_fastrtps_cpp::rosidl_typesupport_fastrtps_cpp
7069
rmw::rmw
71-
zenohc::lib
70+
zenohcxx::zenohc
7271
)
7372

7473
configure_rmw_library(rmw_zenoh_cpp)
@@ -130,7 +129,7 @@ target_link_libraries(rmw_zenohd
130129
rcutils::rcutils
131130
rcpputils::rcpputils
132131
rmw::rmw
133-
zenohc::lib
132+
zenohcxx::zenohc
134133
)
135134

136135
install(

rmw_zenoh_cpp/package.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
<buildtool_depend>ament_cmake</buildtool_depend>
1717

18-
<build_depend>zenoh_c_vendor</build_depend>
19-
<build_export_depend>zenoh_c_vendor</build_export_depend>
18+
<build_depend>zenoh_cpp_vendor</build_depend>
19+
<build_export_depend>zenoh_cpp_vendor</build_export_depend>
2020

2121
<depend>ament_index_cpp</depend>
2222
<depend>fastcdr</depend>

rmw_zenoh_cpp/src/detail/attachment_helpers.cpp

+49-77
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <zenoh.h>
16-
1715
#include <cstdlib>
1816
#include <cstring>
1917
#include <stdexcept>
18+
#include <string>
2019
#include <string_view>
2120
#include <utility>
21+
#include <vector>
22+
23+
#include <zenoh.hxx>
2224

2325
#include "rmw/types.h"
2426

@@ -27,75 +29,24 @@
2729

2830
namespace rmw_zenoh_cpp
2931
{
30-
///=============================================================================
32+
3133
AttachmentData::AttachmentData(
32-
const int64_t sequence_number,
33-
const int64_t source_timestamp,
34-
const uint8_t source_gid[RMW_GID_STORAGE_SIZE])
35-
: sequence_number_(sequence_number),
36-
source_timestamp_(source_timestamp)
34+
const int64_t _sequence_number,
35+
const int64_t _source_timestamp,
36+
const std::vector<uint8_t> _source_gid)
3737
{
38-
memcpy(source_gid_, source_gid, RMW_GID_STORAGE_SIZE);
38+
sequence_number_ = _sequence_number;
39+
source_timestamp_ = _source_timestamp;
40+
source_gid_ = _source_gid;
3941
gid_hash_ = hash_gid(source_gid_);
4042
}
4143

42-
///=============================================================================
4344
AttachmentData::AttachmentData(AttachmentData && data)
44-
: sequence_number_(std::move(data.sequence_number_)),
45-
source_timestamp_(std::move(data.source_timestamp_)),
46-
gid_hash_(std::move(data.gid_hash_))
47-
{
48-
memcpy(source_gid_, data.source_gid_, RMW_GID_STORAGE_SIZE);
49-
}
50-
51-
///=============================================================================
52-
AttachmentData::AttachmentData(const z_loaned_bytes_t * attachment)
5345
{
54-
ze_deserializer_t deserializer = ze_deserializer_from_bytes(attachment);
55-
z_owned_string_t key;
56-
57-
// Deserialize the sequence_number
58-
ze_deserializer_deserialize_string(&deserializer, &key);
59-
if (std::string_view(
60-
z_string_data(z_loan(key)),
61-
z_string_len(z_loan(key))) != "sequence_number")
62-
{
63-
throw std::runtime_error("sequence_number is not found in the attachment.");
64-
}
65-
z_drop(z_move(key));
66-
if (ze_deserializer_deserialize_int64(&deserializer, &this->sequence_number_)) {
67-
throw std::runtime_error("Failed to deserialize the sequence_number.");
68-
}
69-
70-
// Deserialize the source_timestamp
71-
ze_deserializer_deserialize_string(&deserializer, &key);
72-
if (std::string_view(
73-
z_string_data(z_loan(key)),
74-
z_string_len(z_loan(key))) != "source_timestamp")
75-
{
76-
throw std::runtime_error("source_timestamp is not found in the attachment");
77-
}
78-
z_drop(z_move(key));
79-
if (ze_deserializer_deserialize_int64(&deserializer, &this->source_timestamp_)) {
80-
throw std::runtime_error("Failed to deserialize the source_timestamp.");
81-
}
82-
83-
// Deserialize the source_gid
84-
ze_deserializer_deserialize_string(&deserializer, &key);
85-
if (std::string_view(z_string_data(z_loan(key)), z_string_len(z_loan(key))) != "source_gid") {
86-
throw std::runtime_error("Invalid attachment: the key source_gid is not found");
87-
}
88-
z_drop(z_move(key));
89-
z_owned_slice_t slice;
90-
if (ze_deserializer_deserialize_slice(&deserializer, &slice)) {
91-
throw std::runtime_error("Failed to deserialize the source_gid.");
92-
}
93-
if (z_slice_len(z_loan(slice)) != RMW_GID_STORAGE_SIZE) {
94-
throw std::runtime_error("The length of source_gid mismatched.");
95-
}
96-
memcpy(this->source_gid_, z_slice_data(z_loan(slice)), z_slice_len(z_loan(slice)));
97-
z_drop(z_move(slice));
98-
gid_hash_ = hash_gid(this->source_gid_);
46+
gid_hash_ = std::move(data.gid_hash_);
47+
sequence_number_ = std::move(data.sequence_number_);
48+
source_timestamp_ = std::move(data.source_timestamp_);
49+
source_gid_ = data.source_gid_;
9950
}
10051

10152
///=============================================================================
@@ -111,9 +62,9 @@ int64_t AttachmentData::source_timestamp() const
11162
}
11263

11364
///=============================================================================
114-
void AttachmentData::copy_gid(uint8_t out_gid[RMW_GID_STORAGE_SIZE]) const
65+
std::vector<uint8_t> AttachmentData::copy_gid() const
11566
{
116-
memcpy(out_gid, source_gid_, RMW_GID_STORAGE_SIZE);
67+
return source_gid_;
11768
}
11869

11970
///=============================================================================
@@ -122,17 +73,38 @@ size_t AttachmentData::gid_hash() const
12273
return gid_hash_;
12374
}
12475

125-
///=============================================================================
126-
void AttachmentData::serialize_to_zbytes(z_owned_bytes_t * attachment)
76+
zenoh::Bytes AttachmentData::serialize_to_zbytes()
77+
{
78+
auto serializer = zenoh::ext::Serializer();
79+
serializer.serialize(std::string("sequence_number"));
80+
serializer.serialize(this->sequence_number_);
81+
serializer.serialize(std::string("source_timestamp"));
82+
serializer.serialize(this->source_timestamp_);
83+
serializer.serialize(std::string("source_gid"));
84+
serializer.serialize(this->source_gid_);
85+
return std::move(serializer).finish();
86+
}
87+
88+
AttachmentData::AttachmentData(const zenoh::Bytes & attachment)
12789
{
128-
ze_owned_serializer_t serializer;
129-
ze_serializer_empty(&serializer);
130-
ze_serializer_serialize_str(z_loan_mut(serializer), "sequence_number");
131-
ze_serializer_serialize_int64(z_loan_mut(serializer), this->sequence_number_);
132-
ze_serializer_serialize_str(z_loan_mut(serializer), "source_timestamp");
133-
ze_serializer_serialize_int64(z_loan_mut(serializer), this->source_timestamp_);
134-
ze_serializer_serialize_str(z_loan_mut(serializer), "source_gid");
135-
ze_serializer_serialize_buf(z_loan_mut(serializer), this->source_gid_, RMW_GID_STORAGE_SIZE);
136-
ze_serializer_finish(z_move(serializer), attachment);
90+
zenoh::ext::Deserializer deserializer(std::move(attachment));
91+
const auto sequence_number_str = deserializer.deserialize<std::string>();
92+
if (sequence_number_str != "sequence_number") {
93+
throw std::runtime_error("sequence_number is not found in the attachment.");
94+
}
95+
this->sequence_number_ = deserializer.deserialize<int64_t>();
96+
97+
const auto source_timestamp_str = deserializer.deserialize<std::string>();
98+
if (source_timestamp_str != "source_timestamp") {
99+
throw std::runtime_error("source_timestamp is not found in the attachment.");
100+
}
101+
this->source_timestamp_ = deserializer.deserialize<int64_t>();
102+
103+
const auto source_gid_str = deserializer.deserialize<std::string>();
104+
if (source_gid_str != "source_gid") {
105+
throw std::runtime_error("source_gid is not found in the attachment.");
106+
}
107+
this->source_gid_ = deserializer.deserialize<std::vector<uint8_t>>();
108+
gid_hash_ = hash_gid(this->source_gid_);
137109
}
138110
} // namespace rmw_zenoh_cpp

rmw_zenoh_cpp/src/detail/attachment_helpers.hpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,37 @@
1515
#ifndef DETAIL__ATTACHMENT_HELPERS_HPP_
1616
#define DETAIL__ATTACHMENT_HELPERS_HPP_
1717

18-
#include <zenoh.h>
18+
#include <cstdint>
19+
#include <vector>
20+
21+
#include <zenoh.hxx>
1922

2023
#include "rmw/types.h"
2124

2225
namespace rmw_zenoh_cpp
2326
{
24-
///=============================================================================
2527
class AttachmentData final
2628
{
2729
public:
28-
AttachmentData(
29-
const int64_t sequence_number,
30-
const int64_t source_timestamp,
31-
const uint8_t source_gid[RMW_GID_STORAGE_SIZE]);
32-
explicit AttachmentData(const z_loaned_bytes_t *);
30+
explicit AttachmentData(
31+
const int64_t _sequence_number,
32+
const int64_t _source_timestamp,
33+
const std::vector<uint8_t> _source_gid);
34+
35+
explicit AttachmentData(const zenoh::Bytes & bytes);
3336
explicit AttachmentData(AttachmentData && data);
3437

3538
int64_t sequence_number() const;
3639
int64_t source_timestamp() const;
37-
void copy_gid(uint8_t out_gid[RMW_GID_STORAGE_SIZE]) const;
40+
std::vector<uint8_t> copy_gid() const;
3841
size_t gid_hash() const;
3942

40-
void serialize_to_zbytes(z_owned_bytes_t *);
43+
zenoh::Bytes serialize_to_zbytes();
4144

4245
private:
4346
int64_t sequence_number_;
4447
int64_t source_timestamp_;
45-
uint8_t source_gid_[RMW_GID_STORAGE_SIZE];
48+
std::vector<uint8_t> source_gid_;
4649
size_t gid_hash_;
4750
};
4851
} // namespace rmw_zenoh_cpp

rmw_zenoh_cpp/src/detail/graph_cache.cpp

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

7171
///=============================================================================
72-
GraphCache::GraphCache(const z_id_t & zid)
73-
: zid_str_(liveliness::zid_to_str(zid))
72+
GraphCache::GraphCache(const std::string & zid)
73+
: zid_str_(zid)
7474
{
7575
// Do nothing.
7676
}
@@ -1160,7 +1160,7 @@ rmw_ret_t GraphCache::get_entities_info_by_topic(
11601160
}
11611161

11621162
memset(ep.endpoint_gid, 0, RMW_GID_STORAGE_SIZE);
1163-
entity->copy_gid(ep.endpoint_gid);
1163+
memcpy(ep.endpoint_gid, entity->copy_gid().data(), RMW_GID_STORAGE_SIZE);
11641164

11651165
endpoints.push_back(ep);
11661166
}

rmw_zenoh_cpp/src/detail/graph_cache.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class GraphCache final
110110
/// @param id The id of the zenoh session that is building the graph cache.
111111
/// This is used to infer which entities originated from the current session
112112
/// so that appropriate event callbacks may be triggered.
113-
explicit GraphCache(const z_id_t & zid);
113+
explicit GraphCache(const std::string & zid);
114114

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

0 commit comments

Comments
 (0)