Initial Commit
This commit is contained in:
22
src/main/driver/cpp/VendorJNI.cpp
Normal file
22
src/main/driver/cpp/VendorJNI.cpp
Normal 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;
|
||||
}
|
||||
7
src/main/driver/cpp/driversource.cpp
Normal file
7
src/main/driver/cpp/driversource.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "driverheader.h"
|
||||
|
||||
extern "C" {
|
||||
void c_doThing() {
|
||||
|
||||
}
|
||||
}
|
||||
5
src/main/driver/include/driverheader.h
Normal file
5
src/main/driver/include/driverheader.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
void c_doThing();
|
||||
}
|
||||
4
src/main/driver/symbols.txt
Normal file
4
src/main/driver/symbols.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
JNI_OnLoad
|
||||
JNI_OnUnload
|
||||
Java_com_vendor_jni_VendorJNI_initialize
|
||||
c_doThing
|
||||
51
src/main/java/com/vendor/jni/VendorJNI.java
vendored
Normal file
51
src/main/java/com/vendor/jni/VendorJNI.java
vendored
Normal 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();
|
||||
}
|
||||
6
src/main/native/cpp/source.cpp
Normal file
6
src/main/native/cpp/source.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "header.h"
|
||||
#include "driverheader.h"
|
||||
|
||||
void func() {
|
||||
c_doThing();
|
||||
}
|
||||
0
src/main/native/include/header.h
Normal file
0
src/main/native/include/header.h
Normal file
Reference in New Issue
Block a user