Skip to content

Commit

Permalink
Some small updates.
Browse files Browse the repository at this point in the history
Just so we don't have to use as many workarounds.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Dec 11, 2024
1 parent fdc091a commit 6ae4444
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
38 changes: 23 additions & 15 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <algorithm>
#include <array>
#include <functional>
#include <limits>
#include <memory>
#include <mutex>
#include <optional>
Expand Down Expand Up @@ -210,48 +211,55 @@ void GraphCache::handle_matched_events_for_put(
EntityEventMap local_entities_with_events = {};
// The entity added may be local with callbacks registered but there
// may be other local entities in the graph that are matched.
std::size_t match_count_for_entity = 0;
int32_t match_count_for_entity = 0;
for (const auto & [_, topic_data_ptr] : topic_qos_map) {
if (is_pub) {
// Count the number of matching subs for each set of qos settings.
match_count_for_entity += topic_data_ptr->subs_.size();
std::size_t sub_size = topic_data_ptr->subs_.size();
if (sub_size > std::numeric_limits<int32_t>::max()) {
RMW_ZENOH_LOG_ERROR_NAMED(
"rmw_zenoh_cpp",
"Too many subscriptions on publisher; assuming 0. Report this bug.");
sub_size = 0;
}
match_count_for_entity += static_cast<int32_t>(sub_size);
// Also iterate through the subs to check if any are local and if update event counters.
for (liveliness::ConstEntityPtr sub_entity : topic_data_ptr->subs_) {
// Update counters only if key expressions match.
if (entity->topic_info()->topic_keyexpr_ ==
sub_entity->topic_info().value().topic_keyexpr_)
{
update_event_counters(
topic_info.name_,
ZENOH_EVENT_SUBSCRIPTION_MATCHED,
static_cast<int32_t>(1));
update_event_counters(topic_info.name_, ZENOH_EVENT_SUBSCRIPTION_MATCHED, 1);
if (is_entity_local(*sub_entity)) {
local_entities_with_events[sub_entity].insert(ZENOH_EVENT_SUBSCRIPTION_MATCHED);
}
}
}
// Update event counters for the new entity->
update_event_counters(
topic_info.name_,
update_event_counters(topic_info.name_,
ZENOH_EVENT_PUBLICATION_MATCHED,
static_cast<int32_t>(match_count_for_entity));
match_count_for_entity);
if (is_entity_local(*entity) && match_count_for_entity > 0) {
local_entities_with_events[entity].insert(ZENOH_EVENT_PUBLICATION_MATCHED);
}
} else {
// Entity is a sub.
// Count the number of matching pubs for each set of qos settings.
match_count_for_entity += topic_data_ptr->pubs_.size();
std::size_t pub_size = topic_data_ptr->pubs_.size();
if (pub_size > std::numeric_limits<int32_t>::max()) {
RMW_ZENOH_LOG_ERROR_NAMED(
"rmw_zenoh_cpp",
"Too many publishers on subscription; assuming 0. Report this bug.");
pub_size = 0;
}
match_count_for_entity += static_cast<int32_t>(pub_size);
// Also iterate through the pubs to check if any are local and if update event counters.
for (liveliness::ConstEntityPtr pub_entity : topic_data_ptr->pubs_) {
// Update counters only if key expressions match.
if (entity->topic_info()->topic_keyexpr_ ==
pub_entity->topic_info().value().topic_keyexpr_)
{
update_event_counters(
topic_info.name_,
ZENOH_EVENT_PUBLICATION_MATCHED,
static_cast<int32_t>(1));
update_event_counters(topic_info.name_, ZENOH_EVENT_PUBLICATION_MATCHED, 1);
if (is_entity_local(*pub_entity)) {
local_entities_with_events[pub_entity].insert(ZENOH_EVENT_PUBLICATION_MATCHED);
}
Expand All @@ -261,7 +269,7 @@ void GraphCache::handle_matched_events_for_put(
update_event_counters(
topic_info.name_,
ZENOH_EVENT_SUBSCRIPTION_MATCHED,
static_cast<int32_t>(match_count_for_entity));
match_count_for_entity);
if (is_entity_local(*entity) && match_count_for_entity > 0) {
local_entities_with_events[entity].insert(ZENOH_EVENT_SUBSCRIPTION_MATCHED);
}
Expand Down
9 changes: 1 addition & 8 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@
#include "rmw/ret_types.h"
#include "rmw/types.h"

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4099)
#endif
///=============================================================================
class rmw_context_impl_s final
struct rmw_context_impl_s final
{
public:
// Constructor that internally initializes the Zenoh session and other artifacts.
Expand Down Expand Up @@ -99,8 +95,5 @@ class rmw_context_impl_s final
private:
std::shared_ptr<Data> data_{nullptr};
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif // DETAIL__RMW_CONTEXT_IMPL_S_HPP_
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/zenoh_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ std::optional<uint64_t> zenoh_router_check_attempts()
}
// If the environment variable contains a value, handle it accordingly.
if (envar_value[0] != '\0') {
const auto read_value = std::strtoll(envar_value, nullptr, 10);
const int64_t read_value = std::strtoll(envar_value, nullptr, 10);
if (read_value > 0) {
return read_value;
} else if (read_value < 0) {
Expand Down

0 comments on commit 6ae4444

Please sign in to comment.