mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Cleaned up robot startup and cleanup/shutdown code (#77)
Cleaned up RobotBase, removed singleton list from SensorBase, and removed unused typedefs and NULL_TASK macro from HAL's Task.hpp. Making the robot class instance static fixed non-POD statics used by the instance during destruction from being destroyed first.
This commit is contained in:
committed by
Peter Johnson
parent
ecc210f99a
commit
d66c61a36e
@@ -51,8 +51,6 @@ DriverStation::DriverStation() {
|
||||
joysticks[5] = msgs::FRCJoystickPtr(new msgs::FRCJoystick());
|
||||
joysticksSub[5] = MainNode::Subscribe(
|
||||
"~/ds/joysticks/5", &DriverStation::joystickCallback5, this);
|
||||
|
||||
AddToSingletonList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,15 +11,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
RobotBase* RobotBase::m_instance = nullptr;
|
||||
|
||||
void RobotBase::setInstance(RobotBase* robot) {
|
||||
wpi_assert(m_instance == nullptr);
|
||||
m_instance = robot;
|
||||
}
|
||||
|
||||
RobotBase& RobotBase::getInstance() { return *m_instance; }
|
||||
|
||||
/**
|
||||
* Constructor for a generic robot program.
|
||||
*
|
||||
@@ -73,17 +64,3 @@ bool RobotBase::IsOperatorControl() const { return m_ds.IsOperatorControl(); }
|
||||
* field controls.
|
||||
*/
|
||||
bool RobotBase::IsTest() const { return m_ds.IsTest(); }
|
||||
|
||||
/**
|
||||
* This class exists for the sole purpose of getting its destructor called when
|
||||
* the module unloads.
|
||||
*
|
||||
* Before the module is done unloading, we need to delete the RobotBase derived
|
||||
* singleton. This should delete the other remaining singletons that were
|
||||
* registered. This should also stop all tasks that are using the Task class.
|
||||
*/
|
||||
class RobotDeleter {
|
||||
public:
|
||||
~RobotDeleter() { delete &RobotBase::getInstance(); }
|
||||
};
|
||||
static RobotDeleter g_robotDeleter;
|
||||
|
||||
@@ -17,44 +17,12 @@ const uint32_t SensorBase::kPwmChannels;
|
||||
const uint32_t SensorBase::kRelayChannels;
|
||||
const uint32_t SensorBase::kPDPChannels;
|
||||
const uint32_t SensorBase::kChassisSlots;
|
||||
SensorBase* SensorBase::m_singletonList = nullptr;
|
||||
|
||||
/**
|
||||
* Creates an instance of the sensor base and gets an FPGA handle
|
||||
*/
|
||||
SensorBase::SensorBase() {}
|
||||
|
||||
/**
|
||||
* Add sensor to the singleton list.
|
||||
*
|
||||
* Add this sensor to the list of singletons that need to be deleted when
|
||||
* the robot program exits. Each of the sensors on this list are singletons,
|
||||
* that is they aren't allocated directly with new, but instead are allocated
|
||||
* by the static GetInstance method. As a result, they are never deleted when
|
||||
* the program exits. Consequently these sensors may still be holding onto
|
||||
* resources and need to have their destructors called at the end of the
|
||||
* program.
|
||||
*/
|
||||
void SensorBase::AddToSingletonList() {
|
||||
m_nextSingleton = m_singletonList;
|
||||
m_singletonList = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the singleton classes on the list.
|
||||
*
|
||||
* All the classes that were allocated as singletons need to be deleted so
|
||||
* their resources can be freed.
|
||||
*/
|
||||
void SensorBase::DeleteSingletons() {
|
||||
for (SensorBase* next = m_singletonList; next != nullptr;) {
|
||||
SensorBase* tmp = next;
|
||||
next = next->m_nextSingleton;
|
||||
delete tmp;
|
||||
}
|
||||
m_singletonList = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the solenoid module number is valid.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user