[hal] Refactor C++ handle closing; check for invalid handle before closing (#7016)

Adds a close function pointer template parameter to hal::Handle.  This allows default destructors in many places.
The status parameter has been removed from close functions; in most places it was not used. Where it was, an error is printed instead.
This commit is contained in:
Ryan Blue
2024-09-07 13:58:15 -04:00
committed by GitHub
parent 80f3813908
commit 496e7c1bba
94 changed files with 247 additions and 425 deletions

View File

@@ -93,8 +93,7 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTriggerDutyCycle(
return HAL_kInvalidHandle;
}
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle,
int32_t* status) {
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analogTriggerHandle) {
auto trigger = analogTriggerHandles->Get(analogTriggerHandle);
analogTriggerHandles->Free(analogTriggerHandle);
if (trigger == nullptr) {

View File

@@ -31,7 +31,7 @@ HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
hal::init::CheckInit();
return 0;
}
void HAL_FreeCounter(HAL_CounterHandle counterHandle, int32_t* status) {}
void HAL_FreeCounter(HAL_CounterHandle counterHandle) {}
void HAL_SetCounterAverageSize(HAL_CounterHandle counterHandle, int32_t size,
int32_t* status) {}
void HAL_SetCounterUpSource(HAL_CounterHandle counterHandle,

View File

@@ -113,7 +113,7 @@ HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
return handle;
}
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator) {
auto port = digitalPWMHandles->Get(pwmGenerator);
digitalPWMHandles->Free(pwmGenerator);
if (port == nullptr) {

View File

@@ -113,7 +113,7 @@ HAL_EncoderHandle HAL_InitializeEncoder(
return handle;
}
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle, int32_t* status) {
void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle) {
auto encoder = encoderHandles->Get(encoderHandle);
encoderHandles->Free(encoderHandle);
if (encoder == nullptr) {

View File

@@ -204,7 +204,7 @@ void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
notifier->cond.notify_all();
}
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle) {
auto notifier = notifierHandles->Free(notifierHandle);
if (!notifier) {
return;

View File

@@ -111,10 +111,9 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle portHandle,
return handle;
}
void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle, int32_t* status) {
void HAL_FreePWMPort(HAL_DigitalHandle pwmPortHandle) {
auto port = digitalChannelHandles->Get(pwmPortHandle, HAL_HandleEnum::PWM);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}

View File

@@ -80,5 +80,5 @@ void HAL_FlushSerial(HAL_SerialPortHandle handle, int32_t* status) {}
void HAL_ClearSerial(HAL_SerialPortHandle handle, int32_t* status) {}
void HAL_CloseSerial(HAL_SerialPortHandle handle, int32_t* status) {}
void HAL_CloseSerial(HAL_SerialPortHandle handle) {}
} // extern "C"