Skip to content

Commit 11128b9

Browse files
Add Publisher::get_subscription_count
1 parent 83ab23a commit 11128b9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rclrs/src/publisher.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)