Simplify JNI interfaces.

These changes both simplify the Java code and improve performance across the
JNI boundary.

This also fixes the AnalogCrossConnectTest by adding delays to
setInterruptHigh() and setInterruptLow() to ensure the change in voltage has
time to propagate and extends the timeouts in AbstractInterruptTest.

Detailed changes:

Hoisted status checks to C.  This avoids the need to create direct byte
buffers (expensive) and significantly simplifies the Java code.  The C code
now directly generates the exception or reports the error to the DS.

The JVM pointer is now a global across the JNI, initialized by the OnLoad
function, avoiding the need for some of the class-specific initializers to
get this pointer for callbacks.

Opaque pointers (such as ports) are now passed as long values rather than
with a ByteBuffer wrapper.

Added extern "C" to source files.  This allows earlier detection of JNI
definition mismatches to the Java source headers.

Changed JNI signatures to more closely match HAL signatures (in particular,
boolean is now universally used instead of byte for HAL bool, which cleans
up mapping back and forth to 1/0 from true/false).

Change-Id: I4ea0032cabb0871cd74106a3a70d947258c29d2d
This commit is contained in:
Peter Johnson
2015-11-01 09:11:52 -08:00
committed by Brad Miller (WPI)
parent 927400a43c
commit 7023013c4b
69 changed files with 2232 additions and 3118 deletions

View File

@@ -6,6 +6,7 @@
#include "HAL/HAL.hpp"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HALUtil.h"
// set the logging level
TLogLevel netCommLogLevel = logWARNING;
@@ -14,7 +15,7 @@ TLogLevel netCommLogLevel = logWARNING;
if (level > netCommLogLevel) ; \
else Log().Get(level)
extern "C" {
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
@@ -394,14 +395,13 @@ JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCom
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: setNewDataSem
* Signature: ([B)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setNewDataSem
(JNIEnv * env, jclass, jobject id )
(JNIEnv * env, jclass, jlong id )
{
MULTIWAIT_ID javaId = (MULTIWAIT_ID)env->GetDirectBufferAddress(id);
NETCOMM_LOG(logDEBUG) << "Mutex Ptr = " << javaId;
HALSetNewDataSem(javaId->native_handle());
NETCOMM_LOG(logDEBUG) << "Mutex Ptr = " << (void*)id;
HALSetNewDataSem(((MULTIWAIT_ID)id)->native_handle());
}
/*
@@ -609,27 +609,29 @@ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkComm
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetSystemActive
* Signature: (Ljava/nio/IntBuffer;)Z
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetSystemActive
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return HALGetSystemActive((int32_t*)statusPtr);
int32_t status = 0;
bool val = HALGetSystemActive(&status);
CheckStatus(env, status);
return val;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary
* Method: HALGetBrownedOut
* Signature: (Ljava/nio/IntBuffer;)Z
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetBrownedOut
(JNIEnv * env, jclass, jobject status)
(JNIEnv * env, jclass)
{
jint * statusPtr = (jint*)env->GetDirectBufferAddress(status);
*statusPtr = 0;
return HALGetBrownedOut((int32_t*)statusPtr);
int32_t status = 0;
bool val = HALGetBrownedOut(&status);
CheckStatus(env, status);
return val;
}
/*
@@ -650,3 +652,4 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommun
return returnValue;
}
} // extern "C"