Gets JNI compiling on all platforms (#563)

This commit is contained in:
Thad House
2017-07-08 07:48:27 -07:00
committed by Peter Johnson
parent aa0a874ad0
commit f826216a28
4 changed files with 29 additions and 3 deletions

View File

@@ -8,7 +8,9 @@
#include <assert.h>
#include <jni.h>
#ifdef CONFIG_ATHENA
#include "FRC_NetworkCommunication/CANSessionMux.h"
#endif
#include "HAL/cpp/Log.h"
#include "HALUtil.h"
#include "edu_wpi_first_wpilibj_can_CANJNI.h"
@@ -37,6 +39,7 @@ extern "C" {
JNIEXPORT void JNICALL
Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxSendMessage(
JNIEnv *env, jclass, jint messageID, jobject data, jint periodMs) {
#ifdef CONFIG_ATHENA
CANJNI_LOG(logDEBUG)
<< "Calling CANJNI FRCNetCommCANSessionMuxSendMessage";
@@ -69,6 +72,9 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxSendMessage(
CANJNI_LOG(logDEBUG) << "Status: " << status;
CheckCANStatus(env, status, messageID);
#else
// TODO: Make this throw
#endif
}
static uint8_t buffer[8];
@@ -82,6 +88,7 @@ JNIEXPORT jobject JNICALL
Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxReceiveMessage(
JNIEnv *env, jclass, jobject messageID, jint messageIDMask,
jobject timeStamp) {
#ifdef CONFIG_ATHENA
CANJNI_LOG(logDEBUG)
<< "Calling CANJNI FRCNetCommCANSessionMuxReceiveMessage";
@@ -118,6 +125,10 @@ Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetCommCANSessionMuxReceiveMessage(
if (!CheckCANStatus(env, status, *messageIDPtr)) return nullptr;
return env->NewDirectByteBuffer(buffer, dataSize);
#else
// TODO: Make throw
return nullptr;
#endif
}
} // extern "C"

View File

@@ -15,7 +15,9 @@
#include <cstring>
#include <string>
#ifdef CONFIG_ATHENA
#include "FRC_NetworkCommunication/CANSessionMux.h"
#endif
#include "HAL/HAL.h"
#include "HAL/DriverStation.h"
#include "HAL/Errors.h"
@@ -78,7 +80,11 @@ void ThrowHalHandleException(JNIEnv *env, int32_t status) {
halHandleExCls.Throw(env, buf.c_str());
}
constexpr const char wpilibjPrefix[] = "edu.wpi.first.wpilibj";
#ifndef _WIN32
constexpr const char JNI_wpilibjPrefix[] = "edu.wpi.first.wpilibj";
#else
extern const char JNI_wpilibjPrefix[] = "edu.wpi.first.wpilibj";
#endif
void ReportError(JNIEnv *env, int32_t status, bool do_throw) {
if (status == 0) return;
@@ -93,7 +99,7 @@ void ReportError(JNIEnv *env, int32_t status, bool do_throw) {
runtimeExCls.Throw(env, buf.c_str());
} else {
std::string func;
auto stack = GetJavaStackTrace<wpilibjPrefix>(env, &func);
auto stack = GetJavaStackTrace<JNI_wpilibjPrefix>(env, &func);
HAL_SendError(1, status, 0, message, func.c_str(), stack.c_str(), 1);
}
}
@@ -122,7 +128,9 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
case kRioStatusSuccess:
// Everything is ok... don't throw.
break;
#ifdef CONFIG_ATHENA
case ERR_CANSessionMux_InvalidBuffer:
#endif
case kRIOStatusBufferInvalidSize: {
static jmethodID invalidBufConstruct = nullptr;
if (!invalidBufConstruct)
@@ -133,7 +141,9 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
env->Throw(static_cast<jthrowable>(exception));
break;
}
#ifdef CONFIG_ATHENA
case ERR_CANSessionMux_MessageNotFound:
#endif
case kRIOStatusOperationTimedOut: {
static jmethodID messageNotFoundConstruct = nullptr;
if (!messageNotFoundConstruct)
@@ -144,7 +154,9 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
env->Throw(static_cast<jthrowable>(exception));
break;
}
#ifdef CONFIG_ATHENA
case ERR_CANSessionMux_NotAllowed:
#endif
case kRIOStatusFeatureNotSupported: {
llvm::SmallString<100> buf;
llvm::raw_svector_ostream oss(buf);
@@ -152,7 +164,9 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
canMessageNotAllowedExCls.Throw(env, buf.c_str());
break;
}
#ifdef CONFIG_ATHENA
case ERR_CANSessionMux_NotInitialized:
#endif
case kRIOStatusResourceNotInitialized: {
static jmethodID notInitConstruct = nullptr;
if (!notInitConstruct)

View File

@@ -164,7 +164,7 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts(
* Method: waitForInterrupt
* Signature: (JD)V
*/
JNIEXPORT int32_t JNICALL
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt(
JNIEnv* env, jclass, jint interruptHandle, jdouble timeout,
jboolean ignorePrevious) {