From 866bc299f5278c91c107353a907d5e971d2e8e24 Mon Sep 17 00:00:00 2001 From: Barry Xu Date: Wed, 22 Mar 2023 21:31:01 +0800 Subject: [PATCH] Add matched event support (#331) RMW can notify the event that any subscriptions connect / disconnect on the topic to each publisher. Based on this capability, in rclcpp and rclpy, user application can register user callback that will be called when subscription connects or disconnects on the topic for publisher. Signed-off-by: Barry Xu --- rmw/include/rmw/event.h | 2 + .../rmw/events_statuses/events_statuses.h | 1 + rmw/include/rmw/events_statuses/matched.h | 59 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 rmw/include/rmw/events_statuses/matched.h diff --git a/rmw/include/rmw/event.h b/rmw/include/rmw/event.h index 861415ff..707ccca9 100644 --- a/rmw/include/rmw/event.h +++ b/rmw/include/rmw/event.h @@ -38,12 +38,14 @@ typedef enum rmw_event_type_e RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE, RMW_EVENT_MESSAGE_LOST, RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE, + RMW_EVENT_SUBSCRIPTION_MATCHED, // publisher events RMW_EVENT_LIVELINESS_LOST, RMW_EVENT_OFFERED_DEADLINE_MISSED, RMW_EVENT_OFFERED_QOS_INCOMPATIBLE, RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE, + RMW_EVENT_PUBLICATION_MATCHED, // sentinel value RMW_EVENT_INVALID diff --git a/rmw/include/rmw/events_statuses/events_statuses.h b/rmw/include/rmw/events_statuses/events_statuses.h index 4bd01a15..7c0ab929 100644 --- a/rmw/include/rmw/events_statuses/events_statuses.h +++ b/rmw/include/rmw/events_statuses/events_statuses.h @@ -19,6 +19,7 @@ #include "rmw/events_statuses/incompatible_type.h" #include "rmw/events_statuses/liveliness_changed.h" #include "rmw/events_statuses/liveliness_lost.h" +#include "rmw/events_statuses/matched.h" #include "rmw/events_statuses/message_lost.h" #include "rmw/events_statuses/offered_deadline_missed.h" #include "rmw/events_statuses/requested_deadline_missed.h" diff --git a/rmw/include/rmw/events_statuses/matched.h b/rmw/include/rmw/events_statuses/matched.h new file mode 100644 index 00000000..b798b9ca --- /dev/null +++ b/rmw/include/rmw/events_statuses/matched.h @@ -0,0 +1,59 @@ +// Copyright 2023 Sony Group Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef RMW__EVENTS_STATUSES__MATCHED_H_ +#define RMW__EVENTS_STATUSES__MATCHED_H_ + +#include +#include + +#include "rmw/visibility_control.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct RMW_PUBLIC_TYPE rmw_matched_status_s +{ + /** + * For publisher, the total cumulative count of subscribers matched to the concerned publisher. + * + * For subscriber, the total cumulative count of publishers matched to the concerned subscriber. + */ + size_t total_count; + + /** + * total_count change since last time the status was read. + */ + size_t total_count_change; + + /** + * For publisher, the number of subscribers currently matched to the concerned publisher. + * + * For subscriber, the number of publishers currently matched to the concerned subscriber. + */ + size_t current_count; + + /** + * The current_count change since last time the status was read. + */ + int32_t current_count_change; +} rmw_matched_status_t; + +#ifdef __cplusplus +} +#endif + +#endif // RMW__EVENTS_STATUSES__MATCHED_H_