Initial Commit

This commit is contained in:
Thad House
2019-09-27 11:31:25 -07:00
commit 615b12a528
19 changed files with 1045 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
#include "jni.h"
#include "com_vendor_jni_VendorJNI.h"
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
// Check to ensure the JNI version is valid
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
return JNI_ERR;
// In here is also where you store things like class references
// if they are ever needed
return JNI_VERSION_1_6;
}
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {}
JNIEXPORT jint JNICALL Java_com_vendor_jni_VendorJNI_initialize
(JNIEnv *, jclass) {
return 0;
}

View File

@@ -0,0 +1,7 @@
#include "driverheader.h"
extern "C" {
void c_doThing() {
}
}

View File

@@ -0,0 +1,5 @@
#pragma once
extern "C" {
void c_doThing();
}

View File

@@ -0,0 +1,4 @@
JNI_OnLoad
JNI_OnUnload
Java_com_vendor_jni_VendorJNI_initialize
c_doThing

View File

@@ -0,0 +1,51 @@
package com.vendor.jni;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import edu.wpi.first.wpiutil.RuntimeLoader;
public class VendorJNI {
static boolean libraryLoaded = false;
static RuntimeLoader<VendorJNI> loader = null;
public static class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);
public static boolean getExtractOnStaticLoad() {
return extractOnStaticLoad.get();
}
public static void setExtractOnStaticLoad(boolean load) {
extractOnStaticLoad.set(load);
}
}
static {
if (Helper.getExtractOnStaticLoad()) {
try {
loader = new RuntimeLoader<>("Vendor", RuntimeLoader.getDefaultExtractionRoot(), VendorJNI.class);
loader.loadLibrary();
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
libraryLoaded = true;
}
}
/**
* Force load the library.
* @throws java.io.IOException thrown if the native library cannot be found
*/
public static synchronized void forceLoad() throws IOException {
if (libraryLoaded) {
return;
}
loader = new RuntimeLoader<>("VendorJNI", RuntimeLoader.getDefaultExtractionRoot(), VendorJNI.class);
loader.loadLibrary();
libraryLoaded = true;
}
public static native int initialize();
}

View File

@@ -0,0 +1,6 @@
#include "header.h"
#include "driverheader.h"
void func() {
c_doThing();
}

View File