I’m writing a class for use during the autonomous
task which manages a few tasks as members. Ideally, the class’s destructor would be called when autonomous
ends and I could manage the tasks using RAII. However, I do not think they’re called by pros when autonomous
ends.
So, I was planning to call pros::c::task_notify_when_deleting
in the class constructor in a way that the member tasks would be notified to exit themselves. The problem is that I cannot find a way to get the member pros::Task
's internal, private pros::task_t
to pass to pros::c::task_notify_when_deleting
.
Example Code
class myClass {
public:
myClass()
: internalTask([]() {
while (pros::Task::notify_take(true, 10)) {
// Do task stuff
}
}) {
pros::c::task_notify_when_deleting(
pros::c::task_get_current(), // Notify when the current (auton) task ends
internalTask, 1, // Cant get the proper task type to pass in
pros::E_NOTIFY_ACTION_OWRITE);
}
~myClass() { // Ideally the destructor would be called as auton ends
internalTask.notify();
internalTask.join();
}
protected:
pros::Task internalTask;
};
The issue is with the type of internalTask
on the line
internalTask, 1, // Cant get the proper task type to pass in
Is there a better way to clean up tasks (and other resources) when autonoumous exits? Is there any way to get pros to call the class’s destructor?