From 026edffed4e5738c7b362919618b77797aee8c2f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 14 Nov 2018 23:00:25 +0100 Subject: [PATCH] Java-C connection works Pointers can be passed freely --- .gitignore | 2 ++ .../src/sznp/virtualcomputer/PXCLib.java | 5 +++++ .../src/sznp/virtualcomputer/Test.java | 19 +++++++++++++++++++ libpxc/makefile | 1 + libpxc/pxc.c | 10 ++++++++++ 5 files changed, 37 insertions(+) create mode 100644 VirtualComputer/src/sznp/virtualcomputer/PXCLib.java create mode 100644 VirtualComputer/src/sznp/virtualcomputer/Test.java diff --git a/.gitignore b/.gitignore index f144156..cea9d96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +libpxc.so + ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/VirtualComputer/src/sznp/virtualcomputer/PXCLib.java b/VirtualComputer/src/sznp/virtualcomputer/PXCLib.java new file mode 100644 index 0000000..eb373a1 --- /dev/null +++ b/VirtualComputer/src/sznp/virtualcomputer/PXCLib.java @@ -0,0 +1,5 @@ +package sznp.virtualcomputer; + +public interface PXCLib { + int convert(int[] px, long[] out); +} diff --git a/VirtualComputer/src/sznp/virtualcomputer/Test.java b/VirtualComputer/src/sznp/virtualcomputer/Test.java new file mode 100644 index 0000000..6d6f171 --- /dev/null +++ b/VirtualComputer/src/sznp/virtualcomputer/Test.java @@ -0,0 +1,19 @@ +package sznp.virtualcomputer; + +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import jnr.ffi.LibraryLoader; + +import java.io.File; +import java.nio.ByteBuffer; + +public class Test { + public static void main(String[] args) { + System.out.println(new File("").getAbsolutePath()); + PXCLib pxc = LibraryLoader.create(PXCLib.class).search(new File("").getAbsolutePath()).load("pxc"); + ByteBuffer bb = ByteBuffer.allocateDirect(2); + long[] x = new long[]{Pointer.nativeValue(Native.getDirectBufferPointer(bb))}; + pxc.convert(new int[]{5, 10}, x); + System.out.println(bb.get(0)); //19 AYY + } +} diff --git a/libpxc/makefile b/libpxc/makefile index c695180..b4745c1 100644 --- a/libpxc/makefile +++ b/libpxc/makefile @@ -7,4 +7,5 @@ pxct: pxct.c pxc pxc: pxc.c $(CC) -Wall -c -fpic pxc.c -o obj/pxc.o $(CC) -Wall -shared obj/pxc.o -o out/libpxc.so + cp out/libpxc.so ../ diff --git a/libpxc/pxc.c b/libpxc/pxc.c index 176f1a0..bc47f53 100644 --- a/libpxc/pxc.c +++ b/libpxc/pxc.c @@ -1,7 +1,17 @@ #include +typedef long long int lli; + +void* image=NULL; + +void setSource(lli address) { + image=(void*)address; +} + int convert(int px[], int *out[]) { printf("convert...\n"); + printf("px0: %d\n", px[0]); + *out[0]=19; return 0; }