Skip to content

Commit 9b5a7fe

Browse files
committed
update forceLoad to return true
1 parent 3e19cd4 commit 9b5a7fe

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

photon-core/src/main/java/org/photonvision/jni/PhotonJNICommon.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public abstract class PhotonJNICommon {
3232

3333
protected static Logger logger = null;
3434

35-
protected static synchronized void forceLoad(
35+
protected static synchronized boolean forceLoad(
3636
PhotonJNICommon instance, Class<?> clazz, List<String> libraries) throws IOException {
37-
if (instance.isLoaded()) return;
37+
if (instance.isLoaded()) return true;
3838
if (logger == null) logger = new Logger(clazz, LogGroup.Camera);
3939

4040
for (var libraryName : libraries) {
@@ -46,7 +46,7 @@ protected static synchronized void forceLoad(
4646

4747
if (in == null) {
4848
instance.setLoaded(false);
49-
return;
49+
return false;
5050
}
5151

5252
// It's important that we don't mangle the names of these files on Windows at least
@@ -70,14 +70,15 @@ protected static synchronized void forceLoad(
7070
e.printStackTrace();
7171
// logger.error(System.getProperty("java.library.path"));
7272
instance.setLoaded(false);
73-
return;
73+
return false;
7474
}
7575
}
7676
instance.setLoaded(true);
77+
return instance.isLoaded();
7778
}
7879

79-
protected static synchronized void forceLoad(
80+
protected static synchronized boolean forceLoad(
8081
PhotonJNICommon instance, Class<?> clazz, String libraryName) throws IOException {
81-
forceLoad(instance, clazz, List.of(libraryName));
82+
return forceLoad(instance, clazz, List.of(libraryName));
8283
}
8384
}

photon-core/src/main/java/org/photonvision/jni/RknnDetectorJNI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public static RknnDetectorJNI getInstance() {
3535
return instance;
3636
}
3737

38-
public static synchronized void forceLoad() throws IOException {
38+
public static synchronized boolean forceLoad() throws IOException {
3939
TestUtils.loadLibraries();
4040

41-
forceLoad(getInstance(), RknnDetectorJNI.class, List.of("rga", "rknnrt", "rknn_jni"));
41+
return forceLoad(getInstance(), RknnDetectorJNI.class, List.of("rga", "rknnrt", "rknn_jni"));
4242
}
4343

4444
@Override

photon-core/src/main/java/org/photonvision/mrcal/MrCalJNILoader.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public static synchronized MrCalJNILoader getInstance() {
3737
return instance;
3838
}
3939

40-
public static synchronized void forceLoad() throws IOException {
40+
public static synchronized boolean forceLoad() throws IOException {
4141
// Force load opencv
4242
TestUtils.loadLibraries();
4343

4444
// Library naming is dumb and has "lib" appended for Windows when it ought not to
4545
if (Platform.isWindows()) {
4646
// Order is correct to match dependencies of libraries
47-
forceLoad(
47+
return forceLoad(
4848
MrCalJNILoader.getInstance(),
4949
MrCalJNILoader.class,
5050
List.of(
@@ -62,11 +62,7 @@ public static synchronized void forceLoad() throws IOException {
6262
"mrcal_jni"));
6363
} else {
6464
// Nothing else to do on linux
65-
forceLoad(MrCalJNILoader.getInstance(), MrCalJNILoader.class, List.of("mrcal_jni"));
66-
}
67-
68-
if (!MrCalJNILoader.getInstance().isLoaded()) {
69-
throw new IOException("Unable to load mrcal JNI!");
65+
return forceLoad(MrCalJNILoader.getInstance(), MrCalJNILoader.class, List.of("mrcal_jni"));
7066
}
7167
}
7268

photon-core/src/main/java/org/photonvision/raspi/LibCameraJNILoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public class LibCameraJNILoader {
3131
private static boolean libraryLoaded = false;
3232
private static final Logger logger = new Logger(LibCameraJNILoader.class, LogGroup.Camera);
3333

34-
public static synchronized void forceLoad() throws IOException {
35-
if (libraryLoaded) return;
34+
public static synchronized boolean forceLoad() throws IOException {
35+
if (libraryLoaded) return true;
3636

3737
var libraryName = "photonlibcamera";
3838

@@ -46,7 +46,7 @@ public static synchronized void forceLoad() throws IOException {
4646
if (in == null) {
4747
logger.error("Failed to find internal native library at path " + resourcePath);
4848
libraryLoaded = false;
49-
return;
49+
return false;
5050
}
5151

5252
// It's important that we don't mangle the names of these files on Windows at least
@@ -71,6 +71,7 @@ public static synchronized void forceLoad() throws IOException {
7171
// logger.error(System.getProperty("java.library.path"));
7272
}
7373
libraryLoaded = true;
74+
return libraryLoaded;
7475
}
7576

7677
public static boolean isSupported() {

0 commit comments

Comments
 (0)