Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update listener logic for accurate counting #262

Merged
merged 1 commit into from Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,8 +47,8 @@ typedef struct CustomClientInfo
eprosima::fastrtps::Participant * participant_;
const char * typesupport_identifier_;
ClientPubListener * pub_listener_;
uint32_t response_subscriber_matched_count_;
uint32_t request_publisher_matched_count_;
std::atomic_uint32_t response_subscriber_matched_count_;
std::atomic_uint32_t request_publisher_matched_count_;
} CustomClientInfo;

typedef struct CustomClientResponse
Expand Down Expand Up @@ -152,15 +152,18 @@ class ClientListener : public eprosima::fastrtps::SubscriberListener
eprosima::fastrtps::Subscriber * sub,
eprosima::fastrtps::rtps::MatchingInfo & matchingInfo)
{
if (info_ == nullptr || sub == nullptr) {
(void)sub;
if (info_ == nullptr) {
return;
}

if (matchingInfo.status == eprosima::fastrtps::rtps::MATCHED_MATCHING) {
info_->response_subscriber_matched_count_++;
if (eprosima::fastrtps::rtps::MATCHED_MATCHING == matchingInfo.status) {
publishers_.insert(matchingInfo.remoteEndpointGuid);
} else if (eprosima::fastrtps::rtps::REMOVED_MATCHING == matchingInfo.status) {
publishers_.erase(matchingInfo.remoteEndpointGuid);
} else {
info_->response_subscriber_matched_count_--;
return;
}
info_->response_subscriber_matched_count_.store(publishers_.size());
}

private:
Expand All @@ -170,6 +173,7 @@ class ClientListener : public eprosima::fastrtps::SubscriberListener
std::atomic_bool list_has_data_;
std::mutex * conditionMutex_;
std::condition_variable * conditionVariable_;
std::set<eprosima::fastrtps::rtps::GUID_t> publishers_;
};

class ClientPubListener : public eprosima::fastrtps::PublisherListener
Expand All @@ -184,19 +188,23 @@ class ClientPubListener : public eprosima::fastrtps::PublisherListener
eprosima::fastrtps::Publisher * pub,
eprosima::fastrtps::rtps::MatchingInfo & matchingInfo)
{
if (info_ == nullptr || pub == nullptr) {
(void) pub;
if (info_ == nullptr) {
return;
}

if (matchingInfo.status == eprosima::fastrtps::rtps::MATCHED_MATCHING) {
info_->request_publisher_matched_count_++;
if (eprosima::fastrtps::rtps::MATCHED_MATCHING == matchingInfo.status) {
subscriptions_.insert(matchingInfo.remoteEndpointGuid);
} else if (eprosima::fastrtps::rtps::REMOVED_MATCHING == matchingInfo.status) {
subscriptions_.erase(matchingInfo.remoteEndpointGuid);
} else {
info_->request_publisher_matched_count_--;
return;
}
info_->request_publisher_matched_count_.store(subscriptions_.size());
}

private:
CustomClientInfo * info_;
std::set<eprosima::fastrtps::rtps::GUID_t> subscriptions_;
};

#endif // RMW_FASTRTPS_SHARED_CPP__CUSTOM_CLIENT_INFO_HPP_
Expand Up @@ -104,11 +104,11 @@ __rmw_service_server_is_available(
return RMW_RET_OK;
}

if (0 == client_info->request_publisher_matched_count_) {
if (0 == client_info->request_publisher_matched_count_.load()) {
// not ready
return RMW_RET_OK;
}
if (0 == client_info->response_subscriber_matched_count_) {
if (0 == client_info->response_subscriber_matched_count_.load()) {
// not ready
return RMW_RET_OK;
}
Expand Down