Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Move cancel_all() out of SwervePathBuilder FFI class (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Jul 3, 2024
1 parent 380206d commit 3f3ee40
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
5 changes: 0 additions & 5 deletions include/trajopt/path/SwervePathBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ class TRAJOPT_DLLEXPORT SwervePathBuilder {
void AddIntermediateCallback(
const std::function<void(SwerveSolution&, int64_t)> callback);

/**
* Cancel all currently generating SwervePathBuilders.
*/
void CancelAll();

private:
SwervePath path;

Expand Down
9 changes: 5 additions & 4 deletions src/RustFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -240,12 +241,12 @@ void SwervePathBuilder::add_progress_callback(
});
}

void SwervePathBuilder::cancel_all() {
path_builder.CancelAll();
}

std::unique_ptr<SwervePathBuilder> swerve_path_builder_new() {
return std::make_unique<SwervePathBuilder>();
}

void cancel_all() {
trajopt::GetCancellationFlag() = 1;
}

} // namespace trajopt::rsffi
4 changes: 2 additions & 2 deletions src/RustFFI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ class SwervePathBuilder {
void add_progress_callback(
rust::Fn<void(HolonomicTrajectory, int64_t)> callback);

void cancel_all();

private:
trajopt::SwervePathBuilder path_builder;
};

std::unique_ptr<SwervePathBuilder> swerve_path_builder_new();

void cancel_all();

} // namespace trajopt::rsffi
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ mod ffi {
callback: fn(HolonomicTrajectory, i64),
);

fn cancel_all(self: Pin<&mut SwervePathBuilder>);

fn swerve_path_builder_new() -> UniquePtr<SwervePathBuilder>;

fn cancel_all();
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/path/SwervePathBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3f3ee40

Please sign in to comment.