Skip to content

Commit

Permalink
Update codes since matched/unmatched event interface changed
Browse files Browse the repository at this point in the history
Signed-off-by: Barry Xu <barry.xu@sony.com>
  • Loading branch information
Barry-Xu-2018 committed Feb 11, 2023
1 parent c3632ef commit fc7f082
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 64 deletions.
53 changes: 21 additions & 32 deletions rmw_fastrtps_shared_cpp/src/custom_publisher_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,20 @@ bool PubListener::take_event(
{
auto rmw_data = static_cast<rmw_matched_status_t *>(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;
}
break;
case RMW_EVENT_PUBLICATION_UNMATCHED:
{
auto rmw_data = static_cast<rmw_matched_status_t *>(event_info);
auto rmw_data = static_cast<rmw_unmatched_status_t *>(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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -228,15 +215,17 @@ PubListener::on_publication_matched(
}

if (event_type != RMW_EVENT_INVALID) {
std::unique_lock<std::mutex> lock_mutex(on_new_event_m_);
{
std::lock_guard<std::mutex> 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);
}
Expand Down
53 changes: 21 additions & 32 deletions rmw_fastrtps_shared_cpp/src/custom_subscriber_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,20 @@ bool SubListener::take_event(
{
auto rmw_data = static_cast<rmw_matched_status_t *>(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;
}
break;
case RMW_EVENT_SUBSCRIPTION_UNMATCHED:
{
auto rmw_data = static_cast<rmw_matched_status_t *>(event_info);
auto rmw_data = static_cast<rmw_unmatched_status_t *>(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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -380,15 +367,17 @@ void SubListener::on_subscription_matched(
}

if (event_type != RMW_EVENT_INVALID) {
std::unique_lock<std::mutex> lock_mutex(on_new_event_m_);
{
std::lock_guard<std::mutex> 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);
}
Expand Down

0 comments on commit fc7f082

Please sign in to comment.