Compare commits
2 Commits
2236b2ac12
...
e6f805b3d3
| Author | SHA1 | Date |
|---|---|---|
|
|
e6f805b3d3 | |
|
|
1f8e739803 |
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue