add destroy publisher functions
This commit is contained in:
parent
2236b2ac12
commit
1f8e739803
|
|
@ -31,6 +31,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// destroy publisher before the node
|
||||||
|
node.destroy_publisher(publisher);
|
||||||
|
|
||||||
println!("All done!");
|
println!("All done!");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -905,6 +905,30 @@ impl Node {
|
||||||
Ok(p)
|
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.
|
/// Spin the ROS node.
|
||||||
///
|
///
|
||||||
/// This handles wakeups of all subscribes, services, etc on the
|
/// This handles wakeups of all subscribes, services, etc on the
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ pub struct Publisher<T>
|
||||||
where
|
where
|
||||||
T: WrappedTypesupport,
|
T: WrappedTypesupport,
|
||||||
{
|
{
|
||||||
handle: Weak<Publisher_>,
|
pub(crate) handle: Weak<Publisher_>,
|
||||||
type_: PhantomData<T>,
|
type_: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ unsafe impl Send for PublisherUntyped {}
|
||||||
/// move between threads.
|
/// move between threads.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PublisherUntyped {
|
pub struct PublisherUntyped {
|
||||||
handle: Weak<Publisher_>,
|
pub(crate) handle: Weak<Publisher_>,
|
||||||
type_: String,
|
type_: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue