mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[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:
@@ -41,7 +41,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AddressableLEDJNI_free
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
HAL_FreeAddressableLED(static_cast<HAL_AddressableLEDHandle>(handle));
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_FreeAddressableLED(static_cast<HAL_AddressableLEDHandle>(handle));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -57,7 +57,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogGyroJNI_freeAnalogGyro
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
HAL_FreeAnalogGyro((HAL_GyroHandle)id);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeAnalogGyro((HAL_GyroHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -47,7 +47,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_freeAnalogInputPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
HAL_FreeAnalogInputPort((HAL_AnalogInputHandle)id);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeAnalogInputPort((HAL_AnalogInputHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -76,7 +78,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_freeAnalogOutputPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
HAL_FreeAnalogOutputPort((HAL_AnalogOutputHandle)id);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeAnalogOutputPort((HAL_AnalogOutputHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -540,9 +544,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_AnalogJNI_cleanAnalogTrigger
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_CleanAnalogTrigger((HAL_AnalogTriggerHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_CleanAnalogTrigger((HAL_AnalogTriggerHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -58,7 +58,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_CANAPIJNI_cleanCAN
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
HAL_CleanCAN(static_cast<HAL_CANHandle>(handle));
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_CleanCAN(static_cast<HAL_CANHandle>(handle));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -41,7 +41,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_CTREPCMJNI_free
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
HAL_FreeCTREPCM(handle);
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_FreeCTREPCM(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -53,9 +53,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_CounterJNI_freeCounter
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_FreeCounter((HAL_CounterHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeCounter((HAL_CounterHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -57,7 +57,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_DIOJNI_freeDIOPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
HAL_FreeDIOPort((HAL_DigitalHandle)id);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeDIOPort((HAL_DigitalHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -227,9 +229,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_DIOJNI_freeDigitalPWM
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_FreeDigitalPWM((HAL_DigitalPWMHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeDigitalPWM((HAL_DigitalPWMHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -46,7 +46,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_DMAJNI_free
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
HAL_FreeDMA(handle);
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_FreeDMA(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -37,7 +37,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_DutyCycleJNI_free
|
||||
(JNIEnv*, jclass, jint handle)
|
||||
{
|
||||
HAL_FreeDutyCycle(static_cast<HAL_DutyCycleHandle>(handle));
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_FreeDutyCycle(static_cast<HAL_DutyCycleHandle>(handle));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -46,9 +46,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_EncoderJNI_freeEncoder
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_FreeEncoder((HAL_EncoderHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeEncoder((HAL_EncoderHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -44,7 +44,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_InterruptJNI_cleanInterrupts
|
||||
(JNIEnv* env, jclass, jint interruptHandle)
|
||||
{
|
||||
HAL_CleanInterrupts((HAL_InterruptHandle)interruptHandle);
|
||||
if (interruptHandle != HAL_kInvalidHandle) {
|
||||
HAL_CleanInterrupts((HAL_InterruptHandle)interruptHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -87,9 +87,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_NotifierJNI_cleanNotifier
|
||||
(JNIEnv* env, jclass, jint notifierHandle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_CleanNotifier((HAL_NotifierHandle)notifierHandle, &status);
|
||||
CheckStatus(env, status);
|
||||
if (notifierHandle != HAL_kInvalidHandle) {
|
||||
HAL_CleanNotifier((HAL_NotifierHandle)notifierHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -56,9 +56,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_PWMJNI_freePWMPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_FreePWMPort((HAL_DigitalHandle)id, &status);
|
||||
CheckStatus(env, status);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreePWMPort((HAL_DigitalHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -51,7 +51,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_PowerDistributionJNI_free
|
||||
(JNIEnv*, jclass, jint handle)
|
||||
{
|
||||
HAL_CleanPowerDistribution(handle);
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_CleanPowerDistribution(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -44,7 +44,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_RelayJNI_freeRelayPort
|
||||
(JNIEnv* env, jclass, jint id)
|
||||
{
|
||||
HAL_FreeRelayPort((HAL_RelayHandle)id);
|
||||
if (id != HAL_kInvalidHandle) {
|
||||
HAL_FreeRelayPort((HAL_RelayHandle)id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -298,7 +298,9 @@ Java_edu_wpi_first_hal_SPIJNI_spiFreeAuto
|
||||
(JNIEnv* env, jclass, jint port)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_FreeSPIAuto(static_cast<HAL_SPIPort>(port), &status);
|
||||
if (port != HAL_kInvalidHandle) {
|
||||
HAL_FreeSPIAuto(static_cast<HAL_SPIPort>(port), &status);
|
||||
}
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
|
||||
@@ -306,9 +306,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SerialPortJNI_serialClose
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_CloseSerial(static_cast<HAL_SerialPortHandle>(handle), &status);
|
||||
CheckStatus(env, status);
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_CloseSerial(static_cast<HAL_SerialPortHandle>(handle));
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -60,7 +60,9 @@ JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_SimDeviceJNI_freeSimDevice
|
||||
(JNIEnv*, jclass, jint handle)
|
||||
{
|
||||
HAL_FreeSimDevice(handle);
|
||||
if (handle != HAL_kInvalidHandle) {
|
||||
HAL_FreeSimDevice(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user