File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,20 @@ where
146146 }
147147 }
148148
149+ /// Returns the number of subscriptions of the publisher.
150+ pub fn get_subscription_count ( & self ) -> Result < usize , RclrsError > {
151+ let mut subscription_count = 0 ;
152+ // SAFETY: No preconditions for the function called.
153+ unsafe {
154+ rcl_publisher_get_subscription_count (
155+ & * self . handle . rcl_publisher . lock ( ) . unwrap ( ) ,
156+ & mut subscription_count,
157+ )
158+ . ok ( ) ?
159+ } ;
160+ Ok ( subscription_count)
161+ }
162+
149163 /// Publishes a message.
150164 ///
151165 /// The [`MessageCow`] trait is implemented by any
@@ -327,6 +341,10 @@ mod tests {
327341 expected_publishers_info
328342 ) ;
329343
344+ // Test get_subscription_count()
345+ assert_eq ! ( node_1_empty_publisher. get_subscription_count( ) , Ok ( 0 ) ) ;
346+ assert_eq ! ( node_2_default_publisher. get_subscription_count( ) , Ok ( 0 ) ) ;
347+
330348 Ok ( ( ) )
331349 }
332350}
You can’t perform that action at this time.
0 commit comments