Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Dahl e6f805b3d3 Update readme 2024-11-02 10:02:01 +01:00
Martin Dahl 1f8e739803 add destroy publisher functions 2024-10-30 20:52:59 +01:00
4 changed files with 30 additions and 2 deletions

View File

@ -46,6 +46,7 @@ What works?
Changelog
--------------------
#### [Unreleased]
- Add functions to destroy a publisher <https://github.com/sequenceplanner/r2r/pull/110>
#### [0.9.2] - 2024-10-13
- Fix cfg warnings <https://github.com/sequenceplanner/r2r/commit/4cb5bd362e81154924cc7dc21f8edbf470c4604a>

View File

@ -31,6 +31,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
count += 1;
}
// destroy publisher before the node
node.destroy_publisher(publisher);
println!("All done!");
Ok(())

View File

@ -905,6 +905,30 @@ impl Node {
Ok(p)
}
/// Destroy a ROS publisher.
pub fn destroy_publisher<T: WrappedTypesupport>(&mut self, p: Publisher<T>) {
if let Some(handle) = p.handle.upgrade() {
// Remove handle from list of publishers.
self.pubs.iter().position(|p| Arc::ptr_eq(p, &handle))
.map(|i| self.pubs.swap_remove(i));
let handle = wait_until_unwrapped(handle);
handle.destroy(self.node_handle.as_mut());
}
}
/// Destroy a ROS publisher.
pub fn destroy_publisher_untyped(&mut self, p: PublisherUntyped) {
if let Some(handle) = p.handle.upgrade() {
// Remove handle from list of publishers.
self.pubs.iter().position(|p| Arc::ptr_eq(p, &handle))
.map(|i| self.pubs.swap_remove(i));
let handle = wait_until_unwrapped(handle);
handle.destroy(self.node_handle.as_mut());
}
}
/// Spin the ROS node.
///
/// This handles wakeups of all subscribes, services, etc on the

View File

@ -104,7 +104,7 @@ pub struct Publisher<T>
where
T: WrappedTypesupport,
{
handle: Weak<Publisher_>,
pub(crate) handle: Weak<Publisher_>,
type_: PhantomData<T>,
}
@ -116,7 +116,7 @@ unsafe impl Send for PublisherUntyped {}
/// move between threads.
#[derive(Debug, Clone)]
pub struct PublisherUntyped {
handle: Weak<Publisher_>,
pub(crate) handle: Weak<Publisher_>,
type_: String,
}