diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java index 36d3388000..33c1bac477 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/SimDeviceDataJNI.java @@ -47,17 +47,11 @@ public class SimDeviceDataJNI extends JNIWrapper { public static native int registerSimValueCreatedCallback( int device, SimValueCallback callback, boolean initialNotify); - public static native int registerSimValueCreatedCallback2( - int device, SimValueCallback2 callback, boolean initialNotify); - public static native void cancelSimValueCreatedCallback(int uid); public static native int registerSimValueChangedCallback( int handle, SimValueCallback callback, boolean initialNotify); - public static native int registerSimValueChangedCallback2( - int handle, SimValueCallback2 callback, boolean initialNotify); - public static native void cancelSimValueChangedCallback(int uid); /** @@ -69,7 +63,7 @@ public class SimDeviceDataJNI extends JNIWrapper { * @param initialNotify ignored (present for consistency) */ public static native int registerSimValueResetCallback( - int handle, SimValueCallback2 callback, boolean initialNotify); + int handle, SimValueCallback callback, boolean initialNotify); public static native void cancelSimValueResetCallback(int uid); diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java index c586210459..4f9da942cc 100644 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java +++ b/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback.java @@ -8,10 +8,10 @@ import edu.wpi.first.hal.HALValue; @FunctionalInterface public interface SimValueCallback { - void callback(String name, int handle, boolean readonly, HALValue value); + void callback(String name, int handle, int direction, HALValue value); default void callbackNative( - String name, int handle, boolean readonly, int type, long value1, double value2) { - callback(name, handle, readonly, HALValue.fromNative(type, value1, value2)); + String name, int handle, int direction, int type, long value1, double value2) { + callback(name, handle, direction, HALValue.fromNative(type, value1, value2)); } } diff --git a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback2.java b/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback2.java deleted file mode 100644 index f575c7f42c..0000000000 --- a/hal/src/main/java/edu/wpi/first/hal/simulation/SimValueCallback2.java +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -package edu.wpi.first.hal.simulation; - -import edu.wpi.first.hal.HALValue; - -@FunctionalInterface -public interface SimValueCallback2 { - void callback(String name, int handle, int direction, HALValue value); - - default void callbackNative( - String name, int handle, int direction, int type, long value1, double value2) { - callback(name, handle, direction, HALValue.fromNative(type, value1, value2)); - } -} diff --git a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp index 5f02ebcbc1..a07e8af15c 100644 --- a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp @@ -109,8 +109,6 @@ class DeviceCallbackStore { class ValueCallbackStore { public: - explicit ValueCallbackStore(bool dirCallback) : m_dirCallback{dirCallback} {} - void create(JNIEnv* env, jobject obj) { m_call = JGlobal(env, obj); } void performCallback(const char* name, HAL_SimValueHandle handle, int32_t direction, const HAL_Value& value); @@ -121,7 +119,6 @@ class ValueCallbackStore { private: wpi::java::JGlobal m_call; int32_t m_callbackId; - bool m_dirCallback; }; } // namespace @@ -181,17 +178,9 @@ void ValueCallbackStore::performCallback(const char* name, } auto [value1, value2] = ToValue12(value); - if (m_dirCallback) { - env->CallVoidMethod(m_call, simValueCallbackCallback, - MakeJString(env, name), static_cast(handle), - static_cast(direction), - static_cast(value.type), value1, value2); - } else { - env->CallVoidMethod(m_call, simValueCallbackCallback, - MakeJString(env, name), static_cast(handle), - static_cast(direction == HAL_SimValueOutput), - static_cast(value.type), value1, value2); - } + env->CallVoidMethod(m_call, simValueCallbackCallback, MakeJString(env, name), + static_cast(handle), static_cast(direction), + static_cast(value.type), value1, value2); if (env->ExceptionCheck()) { env->ExceptionDescribe(); @@ -266,12 +255,11 @@ using FreeValueCallbackFunc = void (*)(int32_t uid); template static SIM_JniHandle AllocateValueCallback( - JNIEnv* env, THandle h, jobject callback, bool dirCallback, - jboolean initialNotify, + JNIEnv* env, THandle h, jobject callback, jboolean initialNotify, int32_t (*createCallback)(THandle handle, void* param, HALSIM_SimValueCallback callback, HAL_Bool initialNotify)) { - auto callbackStore = std::make_shared(dirCallback); + auto callbackStore = std::make_shared(); auto handle = valueCallbackHandles->Allocate(callbackStore); @@ -345,7 +333,7 @@ bool InitializeSimDeviceDataJNI(JNIEnv* env) { } simValueCallbackCallback = env->GetMethodID( - simValueCallbackCls, "callbackNative", "(Ljava/lang/String;IZIJD)V"); + simValueCallbackCls, "callbackNative", "(Ljava/lang/String;IIIJD)V"); if (!simValueCallbackCallback) { return false; } @@ -530,21 +518,7 @@ Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueCreatedCallba (JNIEnv* env, jclass, jint device, jobject callback, jboolean initialNotify) { return AllocateValueCallback(env, static_cast(device), - callback, false, initialNotify, - &HALSIM_RegisterSimValueCreatedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI - * Method: registerSimValueCreatedCallback2 - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueCreatedCallback2 - (JNIEnv* env, jclass, jint device, jobject callback, jboolean initialNotify) -{ - return AllocateValueCallback(env, static_cast(device), - callback, true, initialNotify, + callback, initialNotify, &HALSIM_RegisterSimValueCreatedCallback); } @@ -570,21 +544,7 @@ Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueChangedCallba (JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify) { return AllocateValueCallback(env, static_cast(handle), - callback, false, initialNotify, - &HALSIM_RegisterSimValueChangedCallback); -} - -/* - * Class: edu_wpi_first_hal_simulation_SimDeviceDataJNI - * Method: registerSimValueChangedCallback2 - * Signature: (ILjava/lang/Object;Z)I - */ -JNIEXPORT jint JNICALL -Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueChangedCallback2 - (JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify) -{ - return AllocateValueCallback(env, static_cast(handle), - callback, true, initialNotify, + callback, initialNotify, &HALSIM_RegisterSimValueChangedCallback); } @@ -610,7 +570,7 @@ Java_edu_wpi_first_hal_simulation_SimDeviceDataJNI_registerSimValueResetCallback (JNIEnv* env, jclass, jint handle, jobject callback, jboolean initialNotify) { return AllocateValueCallback(env, static_cast(handle), - callback, true, initialNotify, + callback, initialNotify, &HALSIM_RegisterSimValueResetCallback); } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java index 4aee29fe42..84b062cafe 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/SimDeviceSim.java @@ -13,7 +13,6 @@ import edu.wpi.first.hal.SimValue; import edu.wpi.first.hal.simulation.SimDeviceCallback; import edu.wpi.first.hal.simulation.SimDeviceDataJNI; import edu.wpi.first.hal.simulation.SimValueCallback; -import edu.wpi.first.hal.simulation.SimValueCallback2; /** Class to control the simulation side of a SimDevice. */ public class SimDeviceSim { @@ -191,22 +190,6 @@ public class SimDeviceSim { return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueChangedCallback); } - /** - * Register a callback to be run every time a value is changed on this device. - * - * @param callback the callback - * @param initialNotify should the callback be run with the initial state - * @return the {@link CallbackStore} object associated with this callback. Save a reference to - * this object so GC doesn't cancel the callback. - */ - public CallbackStore registerValueChangedCallback2( - SimValue value, SimValueCallback2 callback, boolean initialNotify) { - int uid = - SimDeviceDataJNI.registerSimValueChangedCallback2( - value.getNativeHandle(), callback, initialNotify); - return new CallbackStore(uid, SimDeviceDataJNI::cancelSimValueChangedCallback); - } - /** * Register a callback for SimDouble.reset() and similar functions. The callback is called with * the old value. @@ -216,7 +199,7 @@ public class SimDeviceSim { * @param initialNotify ignored (present for consistency) */ public CallbackStore registerValueResetCallback( - SimValue value, SimValueCallback2 callback, boolean initialNotify) { + SimValue value, SimValueCallback callback, boolean initialNotify) { int uid = SimDeviceDataJNI.registerSimValueResetCallback( value.getNativeHandle(), callback, initialNotify);