Skip to content

Commit

Permalink
fix java jni and bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaDizzy committed Jan 26, 2025
1 parent bc25c2e commit 27f63bd
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 deletions.
3 changes: 1 addition & 2 deletions libdatalog/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources")

cc_library(
name = "libdatalog.static",
Expand All @@ -15,5 +14,5 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//wpiutil:wpiutil.static",
]
],
)
59 changes: 57 additions & 2 deletions libdatalog/src/main/java/edu/wpi/first/datalog/DataLogJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,71 @@

package edu.wpi.first.datalog;

import edu.wpi.first.util.WPIUtilJNI;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;

import edu.wpi.first.util.RuntimeLoader;

/**
* DataLog wpiutil JNI Functions.
*
* @see "wpiutil/DataLog.h"
*/
public class DataLogJNI extends WPIUtilJNI {
public class DataLogJNI {
static boolean libraryLoaded = false;

/** Sets whether JNI should be loaded in the static block. */
public static class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);

/**
* Returns true if the JNI should be loaded in the static block.
*
* @return True if the JNI should be loaded in the static block.
*/
public static boolean getExtractOnStaticLoad() {
return extractOnStaticLoad.get();
}

/**
* Sets whether the JNI should be loaded in the static block.
*
* @param load Whether the JNI should be loaded in the static block.
*/
public static void setExtractOnStaticLoad(boolean load) {
extractOnStaticLoad.set(load);
}

/** Utility class. */
private Helper() {}
}

static {
if (Helper.getExtractOnStaticLoad()) {
try {
RuntimeLoader.loadLibrary("datalogjni");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
libraryLoaded = true;
}
}

/**
* Force load the library.
*
* @throws IOException if the library failed to load
*/
public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
RuntimeLoader.loadLibrary("datalogjni");
libraryLoaded = true;
}

/**
* Create a new Data Log background writer. The log will be initially created with a temporary
* filename.
Expand Down
10 changes: 5 additions & 5 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/DataLogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

package edu.wpi.first.wpilibj;

import edu.wpi.first.datalog.DataLog;
import edu.wpi.first.datalog.DataLogBackgroundWriter;
import edu.wpi.first.datalog.FileLogger;
import edu.wpi.first.datalog.IntegerLogEntry;
import edu.wpi.first.datalog.StringLogEntry;
import edu.wpi.first.hal.FRCNetComm.tInstances;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.datalog.FileLogger;
import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.util.concurrent.Event;
import edu.wpi.first.datalog.DataLog;
import edu.wpi.first.datalog.DataLogBackgroundWriter;
import edu.wpi.first.datalog.IntegerLogEntry;
import edu.wpi.first.datalog.StringLogEntry;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down
10 changes: 5 additions & 5 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/DriverStation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

package edu.wpi.first.wpilibj;

import edu.wpi.first.datalog.BooleanArrayLogEntry;
import edu.wpi.first.datalog.BooleanLogEntry;
import edu.wpi.first.datalog.DataLog;
import edu.wpi.first.datalog.FloatArrayLogEntry;
import edu.wpi.first.datalog.IntegerArrayLogEntry;
import edu.wpi.first.hal.AllianceStationID;
import edu.wpi.first.hal.ControlWord;
import edu.wpi.first.hal.DriverStationJNI;
Expand All @@ -16,11 +21,6 @@
import edu.wpi.first.networktables.StringTopic;
import edu.wpi.first.util.EventVector;
import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.datalog.BooleanArrayLogEntry;
import edu.wpi.first.datalog.BooleanLogEntry;
import edu.wpi.first.datalog.DataLog;
import edu.wpi.first.datalog.FloatArrayLogEntry;
import edu.wpi.first.datalog.IntegerArrayLogEntry;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import static edu.wpi.first.units.Units.Second;
import static edu.wpi.first.units.Units.Volts;

import edu.wpi.first.datalog.DoubleLogEntry;
import edu.wpi.first.datalog.StringLogEntry;
import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.units.measure.AngularAcceleration;
import edu.wpi.first.units.measure.AngularVelocity;
Expand All @@ -20,8 +22,6 @@
import edu.wpi.first.units.measure.LinearAcceleration;
import edu.wpi.first.units.measure.LinearVelocity;
import edu.wpi.first.units.measure.Voltage;
import edu.wpi.first.datalog.DoubleLogEntry;
import edu.wpi.first.datalog.StringLogEntry;
import edu.wpi.first.wpilibj.DataLogManager;
import java.util.HashMap;
import java.util.Map;
Expand Down

0 comments on commit 27f63bd

Please sign in to comment.