2024-10-31 08:27:19 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Photon Vision.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.photonvision.jni;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.apriltag.jni.AprilTagJNI;
|
|
|
|
|
import edu.wpi.first.cscore.CameraServerJNI;
|
|
|
|
|
import edu.wpi.first.cscore.OpenCvLoader;
|
|
|
|
|
import edu.wpi.first.hal.JNIWrapper;
|
2024-11-20 23:42:30 -05:00
|
|
|
import edu.wpi.first.math.jni.WPIMathJNI;
|
2024-10-31 08:27:19 -07:00
|
|
|
import edu.wpi.first.net.WPINetJNI;
|
|
|
|
|
import edu.wpi.first.networktables.NetworkTablesJNI;
|
|
|
|
|
import edu.wpi.first.util.WPIUtilJNI;
|
2025-03-11 23:10:15 -04:00
|
|
|
import java.io.IOException;
|
|
|
|
|
import org.opencv.core.Core;
|
2024-10-31 08:27:19 -07:00
|
|
|
|
2025-10-20 10:45:54 -04:00
|
|
|
public class LibraryLoader {
|
|
|
|
|
private static boolean hasWpiLoaded = false;
|
|
|
|
|
private static boolean hasTargetingLoaded = false;
|
2025-03-11 23:10:15 -04:00
|
|
|
|
2025-10-20 10:45:54 -04:00
|
|
|
public static boolean loadWpiLibraries() {
|
|
|
|
|
if (hasWpiLoaded) return true;
|
2024-10-31 08:27:19 -07:00
|
|
|
|
|
|
|
|
NetworkTablesJNI.Helper.setExtractOnStaticLoad(false);
|
|
|
|
|
WPIUtilJNI.Helper.setExtractOnStaticLoad(false);
|
|
|
|
|
CameraServerJNI.Helper.setExtractOnStaticLoad(false);
|
|
|
|
|
OpenCvLoader.Helper.setExtractOnStaticLoad(false);
|
|
|
|
|
JNIWrapper.Helper.setExtractOnStaticLoad(false);
|
|
|
|
|
WPINetJNI.Helper.setExtractOnStaticLoad(false);
|
2024-11-20 23:42:30 -05:00
|
|
|
WPIMathJNI.Helper.setExtractOnStaticLoad(false);
|
2024-10-31 08:27:19 -07:00
|
|
|
AprilTagJNI.Helper.setExtractOnStaticLoad(false);
|
|
|
|
|
try {
|
2025-03-11 23:10:15 -04:00
|
|
|
// Need to load wpiutil first before checking if the MSVC runtime is valid
|
2025-10-20 10:45:54 -04:00
|
|
|
CombinedRuntimeLoader.loadLibraries(LibraryLoader.class, "wpiutiljni");
|
2025-03-11 23:10:15 -04:00
|
|
|
WPIUtilJNI.checkMsvcRuntime();
|
2024-10-31 08:27:19 -07:00
|
|
|
CombinedRuntimeLoader.loadLibraries(
|
2025-10-20 10:45:54 -04:00
|
|
|
LibraryLoader.class,
|
2024-10-31 08:27:19 -07:00
|
|
|
"wpimathjni",
|
|
|
|
|
"ntcorejni",
|
|
|
|
|
"wpinetjni",
|
|
|
|
|
"wpiHaljni",
|
|
|
|
|
"cscorejni",
|
|
|
|
|
"apriltagjni");
|
|
|
|
|
|
2025-10-20 10:45:54 -04:00
|
|
|
CombinedRuntimeLoader.loadLibraries(LibraryLoader.class, Core.NATIVE_LIBRARY_NAME);
|
|
|
|
|
hasWpiLoaded = true;
|
2024-10-31 08:27:19 -07:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
2025-10-20 10:45:54 -04:00
|
|
|
hasWpiLoaded = false;
|
2024-10-31 08:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
2025-10-20 10:45:54 -04:00
|
|
|
return hasWpiLoaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean loadTargeting() {
|
|
|
|
|
if (hasTargetingLoaded) return true;
|
|
|
|
|
try {
|
|
|
|
|
CombinedRuntimeLoader.loadLibraries(LibraryLoader.class, "photontargetingJNI");
|
|
|
|
|
hasTargetingLoaded = true;
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
hasTargetingLoaded = false;
|
|
|
|
|
}
|
|
|
|
|
return hasTargetingLoaded;
|
2024-10-31 08:27:19 -07:00
|
|
|
}
|
|
|
|
|
}
|