feat(rustadapter): using rifgen and flapigen-rs to generate interface
This commit is contained in:
parent
69b9f018b7
commit
e292058b5c
15 changed files with 1724 additions and 30 deletions
54
app/src/main/java/net/mbess/popequer/Foo.java
Normal file
54
app/src/main/java/net/mbess/popequer/Foo.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// Automatically generated by flapigen
|
||||
package net.mbess.popequer;
|
||||
|
||||
|
||||
public final class Foo {
|
||||
|
||||
public Foo(int val) {
|
||||
mNativeObj = init(val);
|
||||
}
|
||||
private static native long init(int val);
|
||||
|
||||
public final int f(int a, int b) {
|
||||
int ret = do_f(mNativeObj, a, b);
|
||||
|
||||
return ret;
|
||||
}
|
||||
private static native int do_f(long self, int a, int b);
|
||||
|
||||
public final int getData() {
|
||||
int ret = do_getData(mNativeObj);
|
||||
|
||||
return ret;
|
||||
}
|
||||
private static native int do_getData(long self);
|
||||
/**
|
||||
* Custom doc comment
|
||||
*/
|
||||
public final void setField(int v) {
|
||||
do_setField(mNativeObj, v);
|
||||
}
|
||||
private static native void do_setField(long self, int v);
|
||||
|
||||
public synchronized void delete() {
|
||||
if (mNativeObj != 0) {
|
||||
do_delete(mNativeObj);
|
||||
mNativeObj = 0;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
delete();
|
||||
}
|
||||
finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
private static native void do_delete(long me);
|
||||
/*package*/ Foo(InternalPointerMarker marker, long ptr) {
|
||||
assert marker == InternalPointerMarker.RAW_PTR;
|
||||
this.mNativeObj = ptr;
|
||||
}
|
||||
/*package*/ long mNativeObj;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
// Automatically generated by flapigen
|
||||
package net.mbess.popequer;
|
||||
|
||||
/*package*/ enum InternalPointerMarker {
|
||||
RAW_PTR;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
// Automatically generated by flapigen
|
||||
package net.mbess.popequer;
|
||||
|
||||
/*package*/ final class JNIReachabilityFence {
|
||||
private JNIReachabilityFence() {}
|
||||
/*package*/ static native void reachabilityFence1(Object ref1);
|
||||
/*package*/ static native void reachabilityFence2(Object ref1, Object ref2);
|
||||
/*package*/ static native void reachabilityFence3(Object ref1, Object ref2, Object ref3);
|
||||
/*package*/ static native void reachabilityFence4(Object ref1, Object ref2, Object ref3, Object ref4);
|
||||
/*package*/ static native void reachabilityFence5(Object ref1, Object ref2, Object ref3, Object ref4, Object ref5);
|
||||
/*package*/ static native void reachabilityFence6(Object ref1, Object ref2, Object ref3, Object ref4, Object ref5, Object ref6);
|
||||
/*package*/ static native void reachabilityFence7(Object ref1, Object ref2, Object ref3, Object ref4, Object ref5, Object ref6, Object ref7);
|
||||
/*package*/ static native void reachabilityFence8(Object ref1, Object ref2, Object ref3, Object ref4, Object ref5, Object ref6, Object ref7, Object ref8);}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package net.mbess.popequer
|
||||
|
||||
object Native {
|
||||
init {
|
||||
System.loadLibrary("rustsandbox")
|
||||
}
|
||||
external fun add(a: Int, b: Int): Int
|
||||
}
|
||||
|
|
@ -14,16 +14,21 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import net.mbess.popequer.AppContext
|
||||
import net.mbess.popequer.Native
|
||||
import net.mbess.popequer.Foo
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
Native.add(143, 54).let {
|
||||
println("From foreign rust result: $it")
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val appContext = AppContext(this)
|
||||
//Native.fsInfo(appContext.gitActions.cloneFolder.absolutePath).let {
|
||||
// Log.d("MainActivity", "From foreign rust result fsInfo $it")
|
||||
//}
|
||||
System.loadLibrary("rustadapter")
|
||||
val foo_instance = Foo(10)
|
||||
Log.d("MainActivity", "From rust: " + foo_instance.f(32, 43))
|
||||
foo_instance.setField(154)
|
||||
Log.d("MainActivity", "${foo_instance.data}")
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
Looper.prepare()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue