mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
|
|
// 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.
|
||
|
|
|
||
|
|
#include "WPIMathJNI_Exceptions.h"
|
||
|
|
|
||
|
|
#include <jni.h>
|
||
|
|
|
||
|
|
using namespace wpi::java;
|
||
|
|
|
||
|
|
//
|
||
|
|
// Globals and load/unload
|
||
|
|
//
|
||
|
|
|
||
|
|
JException illegalArgEx;
|
||
|
|
JException ioEx;
|
||
|
|
JException trajectorySerializationEx;
|
||
|
|
|
||
|
|
static const JExceptionInit exceptions[] = {
|
||
|
|
{"java/lang/IllegalArgumentException", &illegalArgEx},
|
||
|
|
{"java/io/IOException", &ioEx},
|
||
|
|
{"edu/wpi/first/math/trajectory/"
|
||
|
|
"TrajectoryUtil$TrajectorySerializationException",
|
||
|
|
&trajectorySerializationEx}};
|
||
|
|
|
||
|
|
extern "C" {
|
||
|
|
|
||
|
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||
|
|
JNIEnv* env;
|
||
|
|
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||
|
|
return JNI_ERR;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Cache references to exceptions
|
||
|
|
for (auto& c : exceptions) {
|
||
|
|
*c.cls = JException(env, c.name);
|
||
|
|
if (!*c.cls) {
|
||
|
|
return JNI_ERR;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return JNI_VERSION_1_6;
|
||
|
|
}
|
||
|
|
|
||
|
|
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
|
||
|
|
JNIEnv* env;
|
||
|
|
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
// Delete global references
|
||
|
|
for (auto& c : exceptions) {
|
||
|
|
c.cls->free(env);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
} // extern "C"
|