// 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 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(&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(&env), JNI_VERSION_1_6) != JNI_OK) { return; } // Delete global references for (auto& c : exceptions) { c.cls->free(env); } } } // extern "C"