From fc7f0822e98c521af0c0f4d43ea2646ba4aead2c Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Sat, 11 Feb 2023 17:39:16 +0800 Subject: [PATCH] Update codes since matched/unmatched event interface changed Signed-off-by: Barry Xu --- .../src/custom_publisher_info.cpp | 53 ++++++++----------- .../src/custom_subscriber_info.cpp | 53 ++++++++----------- 2 files changed, 42 insertions(+), 64 deletions(-) diff --git a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp index df60b6df7..1cb60f752 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp @@ -100,9 +100,8 @@ bool PubListener::take_event( { auto rmw_data = static_cast(event_info); - rmw_data->total_count_change = matched_status_.total_count_change; - rmw_data->current_count = matched_status_.current_count; - rmw_data->current_count_change = matched_status_.current_count_change; + rmw_data->current_matched_count = matched_status_.current_count; + rmw_data->current_count_change = matched_status_.total_count_change; matched_status_.current_count_change = 0; matched_status_.total_count_change = 0; @@ -110,11 +109,11 @@ bool PubListener::take_event( break; case RMW_EVENT_PUBLICATION_UNMATCHED: { - auto rmw_data = static_cast(event_info); + auto rmw_data = static_cast(event_info); - rmw_data->total_count_change = unmatched_status_.total_count_change; - rmw_data->current_count = unmatched_status_.current_count; - rmw_data->current_count_change = unmatched_status_.current_count_change; + rmw_data->current_matched_count = unmatched_status_.current_count; + rmw_data->current_count_change = unmatched_status_.total_count_change - + unmatched_status_.current_count_change; unmatched_status_.current_count_change = 0; unmatched_status_.total_count_change = 0; @@ -164,28 +163,16 @@ void PubListener::set_on_new_event_callback( break; case RMW_EVENT_PUBLICATION_MATCHED: { - publisher_info_->data_writer_->get_publication_matched_status( - matched_status_); - if (matched_status_.total_count_change > 0) { - callback( - user_data, - matched_status_.total_count_change); - matched_status_.total_count_change = 0; - matched_status_.current_count_change = 0; - } + // Not call callback since recorded matched event happened before + matched_status_.total_count_change = 0; + matched_status_.current_count_change = 0; } break; case RMW_EVENT_PUBLICATION_UNMATCHED: { - publisher_info_->data_writer_->get_publication_matched_status( - unmatched_status_); - if ((unmatched_status_.total_count_change - unmatched_status_.current_count_change) > 0) { - callback( - user_data, - unmatched_status_.total_count_change - unmatched_status_.current_count_change); - unmatched_status_.total_count_change = 0; - unmatched_status_.current_count_change = 0; - } + // Not call callback since recorded unmatched event happened before + unmatched_status_.total_count_change = 0; + unmatched_status_.current_count_change = 0; } break; default: @@ -228,15 +215,17 @@ PubListener::on_publication_matched( } if (event_type != RMW_EVENT_INVALID) { - std::unique_lock lock_mutex(on_new_event_m_); + { + std::lock_guard lock_mutex(on_new_event_m_); - matched_status_.total_count_change += info.total_count_change; - matched_status_.current_count = info.current_count; - matched_status_.current_count_change += info.current_count_change; + matched_status_.total_count_change += info.total_count_change; + matched_status_.current_count = info.current_count; + matched_status_.current_count_change += info.current_count_change; - unmatched_status_.total_count_change += info.total_count_change; - unmatched_status_.current_count = info.current_count; - unmatched_status_.current_count_change += info.current_count_change; + unmatched_status_.total_count_change += info.total_count_change; + unmatched_status_.current_count = info.current_count; + unmatched_status_.current_count_change += info.current_count_change; + } trigger_event(event_type); } diff --git a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp index dbf84ed15..50381dd51 100644 --- a/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp +++ b/rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp @@ -122,9 +122,8 @@ bool SubListener::take_event( { auto rmw_data = static_cast(event_info); - rmw_data->total_count_change = matched_status_.total_count_change; - rmw_data->current_count = matched_status_.current_count; - rmw_data->current_count_change = matched_status_.current_count_change; + rmw_data->current_matched_count = matched_status_.current_count; + rmw_data->current_count_change = matched_status_.total_count_change; matched_status_.current_count_change = 0; matched_status_.total_count_change = 0; @@ -132,11 +131,11 @@ bool SubListener::take_event( break; case RMW_EVENT_SUBSCRIPTION_UNMATCHED: { - auto rmw_data = static_cast(event_info); + auto rmw_data = static_cast(event_info); - rmw_data->total_count_change = unmatched_status_.total_count_change; - rmw_data->current_count = unmatched_status_.current_count; - rmw_data->current_count_change = unmatched_status_.current_count_change; + rmw_data->current_matched_count = unmatched_status_.current_count; + rmw_data->current_count_change = unmatched_status_.total_count_change - + unmatched_status_.current_count_change; unmatched_status_.current_count_change = 0; unmatched_status_.total_count_change = 0; @@ -209,28 +208,16 @@ void SubListener::set_on_new_event_callback( break; case RMW_EVENT_SUBSCRIPTION_MATCHED: { - subscriber_info_->data_reader_->get_subscription_matched_status( - matched_status_); - if (matched_status_.total_count_change > 0) { - callback( - user_data, - matched_status_.total_count_change); - matched_status_.total_count_change = 0; - matched_status_.current_count_change = 0; - } + // Not call callback since recorded matched event happened before + matched_status_.total_count_change = 0; + matched_status_.current_count_change = 0; } break; case RMW_EVENT_SUBSCRIPTION_UNMATCHED: { - subscriber_info_->data_reader_->get_subscription_matched_status( - unmatched_status_); - if ((unmatched_status_.total_count_change - unmatched_status_.current_count_change) > 0) { - callback( - user_data, - unmatched_status_.total_count_change - unmatched_status_.current_count_change); - unmatched_status_.total_count_change = 0; - unmatched_status_.current_count_change = 0; - } + // Not call callback since recorded unmatched event happened before + unmatched_status_.total_count_change = 0; + unmatched_status_.current_count_change = 0; } default: break; @@ -380,15 +367,17 @@ void SubListener::on_subscription_matched( } if (event_type != RMW_EVENT_INVALID) { - std::unique_lock lock_mutex(on_new_event_m_); + { + std::lock_guard lock_mutex(on_new_event_m_); - matched_status_.total_count_change += info.total_count_change; - matched_status_.current_count = info.current_count; - matched_status_.current_count_change += info.current_count_change; + matched_status_.total_count_change += info.total_count_change; + matched_status_.current_count = info.current_count; + matched_status_.current_count_change += info.current_count_change; - unmatched_status_.total_count_change += info.total_count_change; - unmatched_status_.current_count = info.current_count; - unmatched_status_.current_count_change += info.current_count_change; + unmatched_status_.total_count_change += info.total_count_change; + unmatched_status_.current_count = info.current_count; + unmatched_status_.current_count_change += info.current_count_change; + } trigger_event(event_type); }