Skip to content

Commit

Permalink
Merge branch 'rolling' into yadu/test_rclcpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Yadunund committed May 24, 2024
2 parents f23b7a9 + 1ac6bd2 commit 5d8d6c0
Show file tree
Hide file tree
Showing 51 changed files with 619 additions and 586 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ jobs:
strategy:
fail-fast: false
matrix:
docker_image: ['ros:iron-ros-base', 'ros:rolling-ros-base']
distro: ['iron', 'jazzy', 'rolling']
container:
image: ${{ matrix.docker_image }}
image: ros:${{ matrix.distro }}-ros-base
timeout-minutes: 30
steps:
- name: Deps
run: |
apt update && apt install -y curl
- name: Setup Rust
uses: dtolnay/[email protected]
- uses: actions/checkout@v2
- name: Clone system_tests
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
strategy:
fail-fast: false
matrix:
docker_image: ['ros:iron-ros-base', 'ros:rolling-ros-base']
distro: ['iron', 'jazzy', 'rolling']
container:
image: ${{ matrix.docker_image }}
image: ros:${{ matrix.distro }}-ros-base
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
Expand Down
36 changes: 0 additions & 36 deletions .github/workflows/tmp_build_noble.yaml

This file was deleted.

14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ A ROS 2 RMW implementation based on Zenoh that is written using the zenoh-c bind
For information about the Design please visit [design](docs/design.md) page.

## Requirements
- [ROS 2](https://docs.ros.org): Rolling/Iron
- [ROS 2](https://docs.ros.org): Rolling/Jazzy/Iron


## Setup

Install latest rustc via `rustup` if building on Ubuntu Jammy.
Skip this step if building on Ubuntu Noble as `cargo` and `rustc` will be
installed via `rosdep`.
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install 1.75.0
```

Build `rmw_zenoh_cpp`

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

```bash
mkdir ~/ws_rmw_zenoh/src -p && cd ~/ws_rmw_zenoh/src
git clone https://github.com/ros2/rmw_zenoh.git
Expand Down
5 changes: 4 additions & 1 deletion rmw_zenoh_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)
find_package(rmw REQUIRED)
find_package(rmw_dds_common REQUIRED)
find_package(zenoh_c_vendor REQUIRED)
find_package(zenohc REQUIRED)
find_package(zenohc_debug QUIET)
if(NOT zenohc_debug_FOUND)
find_package(zenohc REQUIRED)
endif()

add_library(rmw_zenoh_cpp SHARED
src/detail/attachment_helpers.cpp
Expand Down
9 changes: 1 addition & 8 deletions rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_ROUTER_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,7 @@
},
// Number of threads dedicated to transmission
// By default, the number of threads is calculated as follows: 1 + ((#cores - 1) / 4)
// We limit the number of threads that the zenoh session can spin to 1.
// Without this limit, applications with multiple zenoh sessions can
// encounter system resource errors when trying to create new threads.
// Once zenoh migrates to relying on tokio for its async runtime,
// see https://github.com/eclipse-zenoh/zenoh/pull/566, we can consider
// removing these flags since with tokio, zenoh can better manage the threads it spins
// with the help of thread pools.
threads: 1,
// threads: 1,
},
/// Configure the zenoh RX parameters of a link
rx: {
Expand Down
9 changes: 1 addition & 8 deletions rmw_zenoh_cpp/config/DEFAULT_RMW_ZENOH_SESSION_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,7 @@
},
// Number of threads dedicated to transmission
// By default, the number of threads is calculated as follows: 1 + ((#cores - 1) / 4)
// We limit the number of threads that the zenoh session can spin to 1.
// Without this limit, applications with multiple zenoh sessions can
// encounter system resource errors when trying to create new threads.
// Once zenoh migrates to relying on tokio for its async runtime,
// see https://github.com/eclipse-zenoh/zenoh/pull/566, we can consider
// removing these flags since with tokio, zenoh can better manage the threads it spins
// with the help of thread pools.
threads: 1,
// threads: 1,
},
/// Configure the zenoh RX parameters of a link
rx: {
Expand Down
3 changes: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "attachment_helpers.hpp"

namespace rmw_zenoh_cpp
{
bool get_gid_from_attachment(
const z_attachment_t * const attachment, uint8_t gid[RMW_GID_STORAGE_SIZE])
{
Expand Down Expand Up @@ -91,3 +93,4 @@ int64_t get_int64_from_attachment(

return num;
}
} // namespace rmw_zenoh_cpp
3 changes: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

#include "rmw/types.h"

namespace rmw_zenoh_cpp
{
bool get_gid_from_attachment(
const z_attachment_t * const attachment, uint8_t gid[RMW_GID_STORAGE_SIZE]);

int64_t get_int64_from_attachment(
const z_attachment_t * const attachment, const std::string & name);
} // namespace rmw_zenoh_cpp

#endif // DETAIL__ATTACHMENT_HELPERS_HPP_
9 changes: 6 additions & 3 deletions rmw_zenoh_cpp/src/detail/cdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

#include "cdr.hpp"

rmw_zenoh_cpp::Cdr::Cdr(eprosima::fastcdr::FastBuffer & fastbuffer)
namespace rmw_zenoh_cpp
{
Cdr::Cdr(eprosima::fastcdr::FastBuffer & fastbuffer)
#if FASTCDR_VERSION_MAJOR == 1
: cdr_(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR)
#else
Expand All @@ -27,7 +29,7 @@ rmw_zenoh_cpp::Cdr::Cdr(eprosima::fastcdr::FastBuffer & fastbuffer)
{
}

size_t rmw_zenoh_cpp::Cdr::get_serialized_data_length() const
size_t Cdr::get_serialized_data_length() const
{
#if FASTCDR_VERSION_MAJOR == 1
return cdr_.getSerializedDataLength();
Expand All @@ -36,7 +38,8 @@ size_t rmw_zenoh_cpp::Cdr::get_serialized_data_length() const
#endif
}

eprosima::fastcdr::Cdr & rmw_zenoh_cpp::Cdr::get_cdr()
eprosima::fastcdr::Cdr & Cdr::get_cdr()
{
return cdr_;
}
} // namespace rmw_zenoh_cpp
1 change: 0 additions & 1 deletion rmw_zenoh_cpp/src/detail/cdr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Cdr final
private:
eprosima::fastcdr::Cdr cdr_;
};

} // namespace rmw_zenoh_cpp

#endif // DETAIL__CDR_HPP_
14 changes: 6 additions & 8 deletions rmw_zenoh_cpp/src/detail/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

#include "rmw/error_handling.h"


namespace rmw_zenoh_cpp
{
///=============================================================================
void DataCallbackManager::set_callback(
const void * user_data, rmw_event_callback_t callback)
Expand Down Expand Up @@ -184,7 +185,6 @@ void EventsManager::add_new_event(
///=============================================================================
void EventsManager::attach_event_condition(
rmw_zenoh_event_type_t event_id,
std::mutex * condition_mutex,
std::condition_variable * condition_variable)
{
if (event_id > ZENOH_EVENT_ID_MAX) {
Expand All @@ -195,8 +195,7 @@ void EventsManager::attach_event_condition(
return;
}

std::lock_guard<std::mutex> lock(update_event_condition_mutex_);
event_condition_mutexes_[event_id] = condition_mutex;
std::lock_guard<std::mutex> lock(event_condition_mutex_);
event_conditions_[event_id] = condition_variable;
}

Expand All @@ -211,8 +210,7 @@ void EventsManager::detach_event_condition(rmw_zenoh_event_type_t event_id)
return;
}

std::lock_guard<std::mutex> lock(update_event_condition_mutex_);
event_condition_mutexes_[event_id] = nullptr;
std::lock_guard<std::mutex> lock(event_condition_mutex_);
event_conditions_[event_id] = nullptr;
}

Expand All @@ -227,9 +225,9 @@ void EventsManager::notify_event(rmw_zenoh_event_type_t event_id)
return;
}

std::lock_guard<std::mutex> lock(update_event_condition_mutex_);
std::lock_guard<std::mutex> lock(event_condition_mutex_);
if (event_conditions_[event_id] != nullptr) {
std::lock_guard<std::mutex> cvlk(*event_condition_mutexes_[event_id]);
event_conditions_[event_id]->notify_one();
}
}
} // namespace rmw_zenoh_cpp
15 changes: 5 additions & 10 deletions rmw_zenoh_cpp/src/detail/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include "rmw/event.h"
#include "rmw/event_callback_type.h"


namespace rmw_zenoh_cpp
{
///=============================================================================
// A struct that represents an event status in rmw_zenoh.
enum rmw_zenoh_event_type_t
Expand Down Expand Up @@ -138,7 +139,6 @@ class EventsManager
/// @param condition_variable to attach.
void attach_event_condition(
rmw_zenoh_event_type_t event_id,
std::mutex * condition_mutex,
std::condition_variable * condition_variable);

/// @brief Detach the condition variable provided by rmw_wait.
Expand All @@ -155,22 +155,17 @@ class EventsManager
/// Mutex to lock when read/writing members.
mutable std::mutex event_mutex_;
/// Mutex to lock for event_condition.
mutable std::mutex update_event_condition_mutex_;
std::mutex * event_condition_mutexes_[ZENOH_EVENT_ID_MAX + 1]{nullptr};
mutable std::mutex event_condition_mutex_;
/// Condition variable to attach for event notifications.
std::condition_variable * event_conditions_[ZENOH_EVENT_ID_MAX + 1]{nullptr};
/// User callback that can be set via data_callback_mgr.set_callback().
rmw_event_callback_t callback_ {nullptr};
/// User data that should be passed to the user callback.
const void * user_data_ {nullptr};
/// Count for
size_t unread_count_ {0};

rmw_event_callback_t event_callback_[ZENOH_EVENT_ID_MAX + 1] {nullptr};
const void * event_data_[ZENOH_EVENT_ID_MAX + 1] {nullptr};
size_t event_unread_count_[ZENOH_EVENT_ID_MAX + 1] {0};
// A dequeue of events for each type of event this RMW supports.
std::deque<std::unique_ptr<rmw_zenoh_event_status_t>> event_queues_[ZENOH_EVENT_ID_MAX + 1] {};
const std::size_t event_queue_depth_ = 10;
};
} // namespace rmw_zenoh_cpp

#endif // DETAIL__EVENT_HPP_
9 changes: 7 additions & 2 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "graph_cache.hpp"
#include "rmw_data_types.hpp"

namespace rmw_zenoh_cpp
{
///=============================================================================
using Entity = liveliness::Entity;
using ConstEntityPtr = liveliness::ConstEntityPtr;
Expand Down Expand Up @@ -836,7 +838,8 @@ rmw_ret_t GraphCache::publisher_count_matched_subscriptions(
*subscription_count = 0;
GraphNode::TopicMap::const_iterator topic_it = graph_topics_.find(publisher->topic_name);
if (topic_it != graph_topics_.end()) {
rmw_publisher_data_t * pub_data = static_cast<rmw_publisher_data_t *>(publisher->data);
rmw_publisher_data_t * pub_data =
static_cast<rmw_publisher_data_t *>(publisher->data);
GraphNode::TopicTypeMap::const_iterator topic_data_it = topic_it->second.find(
pub_data->type_support->get_name());
if (topic_data_it != topic_it->second.end()) {
Expand Down Expand Up @@ -871,7 +874,8 @@ rmw_ret_t GraphCache::subscription_count_matched_publishers(
*publisher_count = 0;
GraphNode::TopicMap::const_iterator topic_it = graph_topics_.find(subscription->topic_name);
if (topic_it != graph_topics_.end()) {
rmw_subscription_data_t * sub_data = static_cast<rmw_subscription_data_t *>(subscription->data);
rmw_subscription_data_t * sub_data =
static_cast<rmw_subscription_data_t *>(subscription->data);
GraphNode::TopicTypeMap::const_iterator topic_data_it = topic_it->second.find(
sub_data->type_support->get_name());
if (topic_data_it != topic_it->second.end()) {
Expand Down Expand Up @@ -1297,3 +1301,4 @@ std::unique_ptr<rmw_zenoh_event_status_t> GraphCache::take_event_status(
status_to_take.current_count_change = 0;
return result;
}
} // namespace rmw_zenoh_cpp
3 changes: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/graph_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "rmw/names_and_types.h"


namespace rmw_zenoh_cpp
{
///=============================================================================
// TODO(Yadunund): Consider changing this to an array of unordered_set where the index of the
// array corresponds to the EntityType enum. This way we don't need to mix
Expand Down Expand Up @@ -284,5 +286,6 @@ class GraphCache final
// Mutex to lock before modifying the members above.
mutable std::mutex graph_mutex_;
};
} // namespace rmw_zenoh_cpp

#endif // DETAIL__GRAPH_CACHE_HPP_
Loading

0 comments on commit 5d8d6c0

Please sign in to comment.