Skip to content

Add Java bindings generation #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bf6bccd
Add basic java binding generator
dabastynator Dec 11, 2019
089644c
Add java-binding go-file to build-scripts
dabastynator Dec 11, 2019
4d1f29e
Java: handle in/out/return of enums
dabastynator Dec 13, 2019
45d7f7c
Java: handle in/out/return of enums
dabastynator Dec 16, 2019
b34ce03
Java: handle function-callbacks and structarrays
dabastynator Dec 16, 2019
7b4e579
Java: pass structs by explicit memory
dabastynator Dec 18, 2019
a44c8a5
Java: allow array return value
dabastynator Dec 18, 2019
3b65743
Java: fix bool array handling, handle exception message
dabastynator Dec 19, 2019
96170e3
Java: generate jar build script
dabastynator Dec 19, 2019
eabf432
Java: Bundle out/return to return-value-class
dabastynator Dec 20, 2019
4f0a944
Java: Proper component injection, bugfixes
dabastynator Jan 7, 2020
da8be5c
Java: Generated example prints version info
dabastynator Jan 7, 2020
f62a7cb
Java: Proper instance release handling
dabastynator Jan 7, 2020
28219a0
Java: Platform independent build script
dabastynator Jan 7, 2020
f6382d8
Java: Update readme for java binding generation
dabastynator Jan 7, 2020
fde1e4d
Java: Create prime example and description
dabastynator Jan 7, 2020
b3da905
Java: Bugfix for baseclass generation
dabastynator Jan 7, 2020
93602b5
Fix unix build-script
dabastynator Jan 8, 2020
dbb2682
Java: Fully qualify java.lang.Object avoids name collision
dabastynator Jan 16, 2020
e11e6c8
Java: Add binding version tag to switch between finalize and Cleaner
dabastynator Jan 16, 2020
0d9c76d
Java: Update primes example for java-9 version
dabastynator Jan 16, 2020
5c052c2
Java: Remove hardcoded path
dabastynator Jan 16, 2020
bb0bc6e
Java: Bugfix for 2d-struct-field, decorate special functions
dabastynator Jan 17, 2020
489ee5b
Java: Bugfix for size of counter-memory on array out
dabastynator Jan 20, 2020
6e9654f
Java: Bugfix for size of counter-param on array in
dabastynator Jan 20, 2020
a07b3f1
Java: Use long for array out counter
dabastynator Jan 22, 2020
2f1bfca
Java: Fix url to JNA repo
dabastynator Jan 22, 2020
2b235bc
Merge branch 'develop' into JavaBindings
martinweismann Feb 10, 2020
72e5cd5
Java: Fix release method name, improve unknown error handling
dabastynator Feb 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Build/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set startingDir="%CD%"
set basepath="%~dp0"

cd %basepath%\..\Source
set Sources=actutils.go automaticcomponenttoolkit.go buildbindingccpp.go buildbindingcsharp.go buildbindinggo.go buildbindingnode.go buildbindingpascal.go buildbindingpython.go buildimplementationcpp.go buildimplementationpascal.go componentdefinition.go componentdiff.go languagewriter.go languagec.go languagecpp.go languagepascal.go
set Sources=actutils.go automaticcomponenttoolkit.go buildbindingccpp.go buildbindingcsharp.go buildbindinggo.go buildbindingnode.go buildbindingpascal.go buildbindingpython.go buildimplementationcpp.go buildbindingjava.go buildimplementationpascal.go componentdefinition.go componentdiff.go languagewriter.go languagec.go languagecpp.go languagepascal.go
set GOARCH=amd64

set GOOS=windows
Expand Down
15 changes: 10 additions & 5 deletions Build/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#!/bin/bash

failed() {
echo "${1}" 1>&2
exit 1;
}

startingpath="$(pwd)"
basepath="$(cd "$(dirname "$0")" && pwd)"
cd "$basepath/../Source"

Sources="actutils.go automaticcomponenttoolkit.go buildbindingccpp.go buildbindingcsharp.go buildbindinggo.go buildbindingnode.go buildbindingpascal.go buildbindingpython.go buildimplementationcpp.go buildimplementationpascal.go componentdefinition.go componentdiff.go languagewriter.go languagec.go languagecpp.go languagepascal.go"
Sources="actutils.go automaticcomponenttoolkit.go buildbindingccpp.go buildbindingcsharp.go buildbindinggo.go buildbindingnode.go buildbindingpascal.go buildbindingpython.go buildbindingjava.go buildimplementationcpp.go buildimplementationpascal.go componentdefinition.go componentdiff.go languagewriter.go languagec.go languagecpp.go languagepascal.go"
GOARCH="amd64"

echo "Build act.exe"
GOOS="windows"
go build -o ../act.exe $Sources
go build -o ../act.exe $Sources || failed "Error compiling act.exe"

echo "Build act.linux"
GOOS="linux"
go build -o ../act.linux $Sources
go build -o ../act.linux $Sources || failed "Error compiling act.linux"

echo "Build act.darwin"
GOOS="darwin"
go build -o ../act.darwin $Sources
go build -o ../act.darwin $Sources || failed "Error compiling act.darwin"

echo "Build act.arm"
echo "Build act.arm" || failed "Error compiling act.arm"
GOOS="linux"
GOARCH="arm"
GOARM="5"
Expand Down
10 changes: 10 additions & 0 deletions Examples/Primes/LibPrimes_component/Bindings/Java9/build_jar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

echo "Download JNA"
wget http://repo1.maven.org/maven2/net/java/dev/jna/jna/5.5.0/jna-5.5.0.jar

echo "Compile Java Bindings"
javac -classpath *.jar libprimes/*

echo "Create JAR"
jar cvf libprimes-1.2.0.jar libprimes
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*++

Copyright (C) 2019 PrimeDevelopers

All rights reserved.

This file has been generated by the Automatic Component Toolkit (ACT) version 1.7.0-develop.

Abstract: This is an autogenerated Java file in order to allow an easy
use of Prime Numbers Library

Interface version: 1.2.0

*/

package libprimes;

import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import java.lang.ref.Cleaner;


import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

public class Base {

protected static final Cleaner mCleaner = Cleaner.create();

protected Pointer mHandle;

protected LibPrimesWrapper mWrapper;

public Base(LibPrimesWrapper wrapper, Pointer handle) {
mHandle = handle;
mWrapper = wrapper;
mCleaner.register(this, new InstanceReleaser(this));
}

public Pointer getHandle() {
return mHandle;
}

protected static class InstanceReleaser implements Runnable{

protected Pointer mHandle;

protected LibPrimesWrapper mWrapper;

protected InstanceReleaser(Base instance) {
mHandle = instance.mHandle;
mWrapper = instance.mWrapper;
}

@Override
public void run() {
try {
mWrapper.checkError(null, mWrapper.libprimes_releaseinstance.invokeInt(new java.lang.Object[]{mHandle}));
} catch (LibPrimesException e) {
e.printStackTrace();
}
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*++

Copyright (C) 2019 PrimeDevelopers

All rights reserved.

This file has been generated by the Automatic Component Toolkit (ACT) version 1.7.0-develop.

Abstract: This is an autogenerated Java file in order to allow an easy
use of Prime Numbers Library

Interface version: 1.2.0

*/

package libprimes;

import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import java.lang.ref.Cleaner;


import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

public class Calculator extends Base {

public Calculator(LibPrimesWrapper wrapper, Pointer handle) {
super(wrapper, handle);
}

/**
* Returns the current value of this Calculator
*
* @return The current value of this Calculator
* @throws LibPrimesException
*/
public long getValue() throws LibPrimesException {
Pointer bufferValue = new Memory(8);
mWrapper.checkError(this, mWrapper.libprimes_calculator_getvalue.invokeInt(new java.lang.Object[]{mHandle, bufferValue}));
return bufferValue.getLong(0);
}

/**
* Sets the value to be factorized
*
* @param value The value to be factorized
* @throws LibPrimesException
*/
public void setValue(long value) throws LibPrimesException {
mWrapper.checkError(this, mWrapper.libprimes_calculator_setvalue.invokeInt(new java.lang.Object[]{mHandle, value}));
}

/**
* Performs the specific calculation of this Calculator
*
* @throws LibPrimesException
*/
public void calculate() throws LibPrimesException {
mWrapper.checkError(this, mWrapper.libprimes_calculator_calculate.invokeInt(new java.lang.Object[]{mHandle}));
}

/**
* Sets the progress callback function
*
* @param progressCallback The progress callback
* @throws LibPrimesException
*/
public void setProgressCallback(LibPrimesWrapper.ProgressCallback progressCallback) throws LibPrimesException {
mWrapper.checkError(this, mWrapper.libprimes_calculator_setprogresscallback.invokeInt(new java.lang.Object[]{mHandle, progressCallback}));
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*++

Copyright (C) 2019 PrimeDevelopers

All rights reserved.

This file has been generated by the Automatic Component Toolkit (ACT) version 1.7.0-develop.

Abstract: This is an autogenerated Java file in order to allow an easy
use of Prime Numbers Library

Interface version: 1.2.0

*/

package libprimes;

import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import java.lang.ref.Cleaner;


import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

public class FactorizationCalculator extends Calculator {

public FactorizationCalculator(LibPrimesWrapper wrapper, Pointer handle) {
super(wrapper, handle);
}

/**
* Returns the prime factors of this number (without multiplicity)
*
* @return The prime factors of this number
* @throws LibPrimesException
*/
public PrimeFactor[] getPrimeFactors() throws LibPrimesException {
Pointer countNeededPrimeFactors = new Memory(4);
mWrapper.checkError(this, mWrapper.libprimes_factorizationcalculator_getprimefactors.invokeInt(new java.lang.Object[]{mHandle, 0, countNeededPrimeFactors, null}));
int countPrimeFactors = countNeededPrimeFactors.getInt(0);
Pointer bufferPrimeFactors = new Memory(Math.max(1, countPrimeFactors * PrimeFactor.SIZE));
mWrapper.checkError(this, mWrapper.libprimes_factorizationcalculator_getprimefactors.invokeInt(new java.lang.Object[]{mHandle, countPrimeFactors, countNeededPrimeFactors, bufferPrimeFactors}));
PrimeFactor primeFactors[] = new PrimeFactor[countPrimeFactors];
for (int i = 0; i < countPrimeFactors; i++) {
primeFactors[i] = new PrimeFactor();
primeFactors[i].readFromPointer(bufferPrimeFactors, i * PrimeFactor.SIZE);
}
return primeFactors;
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*++

Copyright (C) 2019 PrimeDevelopers

All rights reserved.

This file has been generated by the Automatic Component Toolkit (ACT) version 1.7.0-develop.

Abstract: This is an autogenerated Java file in order to allow an easy
use of Prime Numbers Library

Interface version: 1.2.0

*/

package libprimes;

import java.util.HashMap;
import java.util.Map;

public class LibPrimesException extends Exception {

// Error Constants for LibPrimes
public static final int LIBPRIMES_SUCCESS = 0;
public static final int LIBPRIMES_ERROR_NOTIMPLEMENTED = 1;
public static final int LIBPRIMES_ERROR_INVALIDPARAM = 2;
public static final int LIBPRIMES_ERROR_INVALIDCAST = 3;
public static final int LIBPRIMES_ERROR_BUFFERTOOSMALL = 4;
public static final int LIBPRIMES_ERROR_GENERICEXCEPTION = 5;
public static final int LIBPRIMES_ERROR_COULDNOTLOADLIBRARY = 6;
public static final int LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT = 7;
public static final int LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION = 8;
public static final int LIBPRIMES_ERROR_NORESULTAVAILABLE = 9;
public static final int LIBPRIMES_ERROR_CALCULATIONABORTED = 10;

public static final Map<Integer, String> ErrorCodeMap = new HashMap<Integer, String>();
public static final Map<Integer, String> ErrorDescriptionMap = new HashMap<Integer, String>();

static {
ErrorCodeMap.put(LIBPRIMES_ERROR_NOTIMPLEMENTED, "LIBPRIMES_ERROR_NOTIMPLEMENTED");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_NOTIMPLEMENTED, "functionality not implemented");
ErrorCodeMap.put(LIBPRIMES_ERROR_INVALIDPARAM, "LIBPRIMES_ERROR_INVALIDPARAM");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_INVALIDPARAM, "an invalid parameter was passed");
ErrorCodeMap.put(LIBPRIMES_ERROR_INVALIDCAST, "LIBPRIMES_ERROR_INVALIDCAST");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_INVALIDCAST, "a type cast failed");
ErrorCodeMap.put(LIBPRIMES_ERROR_BUFFERTOOSMALL, "LIBPRIMES_ERROR_BUFFERTOOSMALL");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_BUFFERTOOSMALL, "a provided buffer is too small");
ErrorCodeMap.put(LIBPRIMES_ERROR_GENERICEXCEPTION, "LIBPRIMES_ERROR_GENERICEXCEPTION");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_GENERICEXCEPTION, "a generic exception occurred");
ErrorCodeMap.put(LIBPRIMES_ERROR_COULDNOTLOADLIBRARY, "LIBPRIMES_ERROR_COULDNOTLOADLIBRARY");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_COULDNOTLOADLIBRARY, "the library could not be loaded");
ErrorCodeMap.put(LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT, "LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT, "a required exported symbol could not be found in the library");
ErrorCodeMap.put(LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION, "LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION, "the version of the binary interface does not match the bindings interface");
ErrorCodeMap.put(LIBPRIMES_ERROR_NORESULTAVAILABLE, "LIBPRIMES_ERROR_NORESULTAVAILABLE");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_NORESULTAVAILABLE, "no result is available");
ErrorCodeMap.put(LIBPRIMES_ERROR_CALCULATIONABORTED, "LIBPRIMES_ERROR_CALCULATIONABORTED");
ErrorDescriptionMap.put(LIBPRIMES_ERROR_CALCULATIONABORTED, "a calculation has been aborted");
}

protected int mErrorCode;

protected String mErrorString;

protected String mErrorDescription;

public LibPrimesException(int errorCode, String message){
super(message);
mErrorCode = errorCode;
mErrorString = ErrorCodeMap.get(errorCode);
mErrorDescription = ErrorDescriptionMap.get(errorCode);
}

@Override
public String toString() {
return mErrorCode + ": " + mErrorString + " (" + mErrorDescription + " - " + getMessage() + ")";
}
}

Loading