Skip to content

Commit

Permalink
Merge branch 'rolling' into yadu/tmp_jazzy
Browse files Browse the repository at this point in the history
  • Loading branch information
Yadunund committed May 24, 2024
2 parents e163f48 + 93ba28e commit 24ada2f
Show file tree
Hide file tree
Showing 46 changed files with 562 additions and 425 deletions.
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_
4 changes: 3 additions & 1 deletion 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 @@ -229,3 +230,4 @@ void EventsManager::notify_event(rmw_zenoh_event_type_t event_id)
event_conditions_[event_id]->notify_one();
}
}
} // namespace rmw_zenoh_cpp
11 changes: 4 additions & 7 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 @@ -157,18 +158,14 @@ class EventsManager
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_
13 changes: 8 additions & 5 deletions rmw_zenoh_cpp/src/detail/guard_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@

#include "guard_condition.hpp"

///==============================================================================
namespace rmw_zenoh_cpp
{
///=============================================================================
GuardCondition::GuardCondition()
: has_triggered_(false),
condition_variable_(nullptr)
{
}

///==============================================================================
///=============================================================================
void GuardCondition::trigger()
{
std::lock_guard<std::mutex> lock(internal_mutex_);
Expand All @@ -37,21 +39,21 @@ void GuardCondition::trigger()
}
}

///==============================================================================
///=============================================================================
void GuardCondition::attach_condition(std::condition_variable * condition_variable)
{
std::lock_guard<std::mutex> lock(internal_mutex_);
condition_variable_ = condition_variable;
}

///==============================================================================
///=============================================================================
void GuardCondition::detach_condition()
{
std::lock_guard<std::mutex> lock(internal_mutex_);
condition_variable_ = nullptr;
}

///==============================================================================
///=============================================================================
bool GuardCondition::get_and_reset_trigger()
{
std::lock_guard<std::mutex> lock(internal_mutex_);
Expand All @@ -63,3 +65,4 @@ bool GuardCondition::get_and_reset_trigger()

return ret;
}
} // namespace rmw_zenoh_cpp
5 changes: 4 additions & 1 deletion rmw_zenoh_cpp/src/detail/guard_condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <condition_variable>
#include <mutex>

///==============================================================================
namespace rmw_zenoh_cpp
{
///=============================================================================
class GuardCondition final
{
public:
Expand All @@ -40,5 +42,6 @@ class GuardCondition final
std::atomic_bool has_triggered_;
std::condition_variable * condition_variable_;
};
} // namespace rmw_zenoh_cpp

#endif // DETAIL__GUARD_CONDITION_HPP_
3 changes: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@

#include "identifier.hpp"

namespace rmw_zenoh_cpp
{
const char * const rmw_zenoh_identifier = "rmw_zenoh_cpp";
} // namespace rmw_zenoh_cpp
3 changes: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/identifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#ifndef DETAIL__IDENTIFIER_HPP_
#define DETAIL__IDENTIFIER_HPP_

namespace rmw_zenoh_cpp
{
extern const char * const rmw_zenoh_identifier;
} // namespace rmw_zenoh_cpp

#endif // DETAIL__IDENTIFIER_HPP_
33 changes: 16 additions & 17 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

#include "rmw/error_handling.h"


namespace rmw_zenoh_cpp
{
namespace liveliness
{

///=============================================================================
NodeInfo::NodeInfo(
std::size_t domain_id,
Expand Down Expand Up @@ -88,7 +88,6 @@ static const char PUB_STR[] = "MP";
static const char SUB_STR[] = "MS";
static const char SRV_STR[] = "SS";
static const char CLI_STR[] = "SC";
static const char EMPTY_NAMESPACE_REPLACEMENT = '_';
static const char KEYEXPR_DELIMITER = '/';
static const char SLASH_REPLACEMENT = '%';
static const char QOS_DELIMITER = ':';
Expand Down Expand Up @@ -261,7 +260,7 @@ Entity::Entity(
keyexpr_parts[KeyexprIndex::Id] = id_;
keyexpr_parts[KeyexprIndex::EntityStr] = entity_to_str.at(type_);
// An empty namespace from rcl will contain "/" but zenoh does not allow keys with "//".
// Hence we add an "_" to denote an empty namespace such that splitting the key
// Hence we mangle the empty namespace such that splitting the key
// will always result in 5 parts.
keyexpr_parts[KeyexprIndex::Namespace] = mangle_name(node_info_.ns_);
keyexpr_parts[KeyexprIndex::NodeName] = mangle_name(node_info_.name_);
Expand Down Expand Up @@ -318,12 +317,12 @@ std::shared_ptr<Entity> Entity::make(

return std::make_shared<Entity>(
Entity{
zid_to_str(zid),
nid,
id,
std::move(type),
std::move(node_info),
std::move(topic_info)});
zid_to_str(zid),
nid,
id,
std::move(type),
std::move(node_info),
std::move(topic_info)});
}

///=============================================================================
Expand Down Expand Up @@ -399,12 +398,12 @@ std::shared_ptr<Entity> Entity::make(const std::string & keyexpr)

return std::make_shared<Entity>(
Entity{
std::move(zid),
std::move(nid),
std::move(id),
std::move(entity_type),
NodeInfo{std::move(domain_id), std::move(ns), std::move(node_name), ""},
std::move(topic_info)});
std::move(zid),
std::move(nid),
std::move(id),
std::move(entity_type),
NodeInfo{std::move(domain_id), std::move(ns), std::move(node_name), ""},
std::move(topic_info)});
}

///=============================================================================
Expand Down Expand Up @@ -499,5 +498,5 @@ std::string demangle_name(const std::string & input)
}
return output;
}

} // namespace liveliness
} // namespace rmw_zenoh_cpp
Loading

0 comments on commit 24ada2f

Please sign in to comment.