From 3f3ee40c23a980505b04bcfcb183043b7fe91771 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 3 Jul 2024 13:34:03 -0700 Subject: [PATCH] Move cancel_all() out of SwervePathBuilder FFI class (#225) --- include/trajopt/path/SwervePathBuilder.hpp | 5 ----- src/RustFFI.cpp | 9 +++++---- src/RustFFI.hpp | 4 ++-- src/lib.rs | 12 ++++++------ src/path/SwervePathBuilder.cpp | 4 ---- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/include/trajopt/path/SwervePathBuilder.hpp b/include/trajopt/path/SwervePathBuilder.hpp index abd6dd24..421c7019 100644 --- a/include/trajopt/path/SwervePathBuilder.hpp +++ b/include/trajopt/path/SwervePathBuilder.hpp @@ -181,11 +181,6 @@ class TRAJOPT_DLLEXPORT SwervePathBuilder { void AddIntermediateCallback( const std::function callback); - /** - * Cancel all currently generating SwervePathBuilders. - */ - void CancelAll(); - private: SwervePath path; diff --git a/src/RustFFI.cpp b/src/RustFFI.cpp index c6a41eaa..b8d3fcaf 100644 --- a/src/RustFFI.cpp +++ b/src/RustFFI.cpp @@ -17,6 +17,7 @@ #include "trajopt/drivetrain/SwerveModule.hpp" #include "trajopt/trajectory/HolonomicTrajectory.hpp" #include "trajopt/trajectory/HolonomicTrajectorySample.hpp" +#include "trajopt/util/Cancellation.hpp" #include "trajoptlib/src/lib.rs.h" namespace trajopt::rsffi { @@ -240,12 +241,12 @@ void SwervePathBuilder::add_progress_callback( }); } -void SwervePathBuilder::cancel_all() { - path_builder.CancelAll(); -} - std::unique_ptr swerve_path_builder_new() { return std::make_unique(); } +void cancel_all() { + trajopt::GetCancellationFlag() = 1; +} + } // namespace trajopt::rsffi diff --git a/src/RustFFI.hpp b/src/RustFFI.hpp index dd4915b1..723af323 100644 --- a/src/RustFFI.hpp +++ b/src/RustFFI.hpp @@ -65,12 +65,12 @@ class SwervePathBuilder { void add_progress_callback( rust::Fn callback); - void cancel_all(); - private: trajopt::SwervePathBuilder path_builder; }; std::unique_ptr swerve_path_builder_new(); +void cancel_all(); + } // namespace trajopt::rsffi diff --git a/src/lib.rs b/src/lib.rs index 719d7daf..7f3a9f9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,9 +162,9 @@ mod ffi { callback: fn(HolonomicTrajectory, i64), ); - fn cancel_all(self: Pin<&mut SwervePathBuilder>); - fn swerve_path_builder_new() -> UniquePtr; + + fn cancel_all(); } } @@ -424,10 +424,6 @@ impl SwervePathBuilder { pub fn add_progress_callback(&mut self, callback: fn(HolonomicTrajectory, i64)) { crate::ffi::SwervePathBuilder::add_progress_callback(self.path_builder.pin_mut(), callback); } - - pub fn cancel_all(&mut self) { - crate::ffi::SwervePathBuilder::cancel_all(self.path_builder.pin_mut()); - } } impl Default for SwervePathBuilder { @@ -436,6 +432,10 @@ impl Default for SwervePathBuilder { } } +pub fn cancel_all() { + crate::ffi::cancel_all(); +} + pub use ffi::HolonomicTrajectory; pub use ffi::HolonomicTrajectorySample; pub use ffi::Pose2d; diff --git a/src/path/SwervePathBuilder.cpp b/src/path/SwervePathBuilder.cpp index f9404981..73afbc4a 100644 --- a/src/path/SwervePathBuilder.cpp +++ b/src/path/SwervePathBuilder.cpp @@ -198,10 +198,6 @@ void SwervePathBuilder::AddIntermediateCallback( path.callbacks.push_back(callback); } -void SwervePathBuilder::CancelAll() { - trajopt::GetCancellationFlag() = 1; -} - void SwervePathBuilder::NewWpts(size_t finalIndex) { int64_t targetIndex = finalIndex; int64_t greatestIndex = path.waypoints.size() - 1;