├── .gitignore ├── README.md ├── jni ├── package.d ├── JniHelper.d ├── JavaEnv.d ├── JavaString.d ├── JavaVM.d ├── JavaField.d ├── JavaClass.d ├── JavaMethod.d ├── JavaArray.d ├── JavaObject.d ├── JniProxy.d └── jni.d └── Makefile /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DJni 2 | ==== 3 | 4 | A convenient D wrapper around JNI. 5 | -------------------------------------------------------------------------------- /jni/package.d: -------------------------------------------------------------------------------- 1 | public import jni.jni; 2 | public import jni.JniHelper; 3 | public import jni.JniProxy; 4 | public import jni.JavaVM; 5 | public import jni.JavaEnv; 6 | public import jni.JavaObject; 7 | public import jni.JavaClass; 8 | public import jni.JavaString; 9 | public import jni.JavaArray; 10 | public import jni.JavaMethod; 11 | public import jni.JavaField; 12 | -------------------------------------------------------------------------------- /jni/JniHelper.d: -------------------------------------------------------------------------------- 1 | module jni.JniHelper; 2 | 3 | import jni.jni; 4 | import jni.JavaVM; 5 | 6 | 7 | struct JniHelper { 8 | public: 9 | static ref JniJavaVM GetJavaVM() { 10 | if(javaVmInstance == null) 11 | javaVmInstance = new JniJavaVM(); 12 | return *javaVmInstance; 13 | } 14 | static ref JniJavaVM GetJavaVM(string classPath) { 15 | if(javaVmInstance == null) 16 | javaVmInstance = new JniJavaVM(classPath); 17 | return *javaVmInstance; 18 | } 19 | static ref JniJavaVM GetJavaVM(string classPath, jint ver) { 20 | if(javaVmInstance == null) 21 | javaVmInstance = new JniJavaVM(classPath, ver); 22 | return *javaVmInstance; 23 | } 24 | 25 | static ref JniJavaVM GetJavaVM(JavaVM * vm) { 26 | if(javaVmInstance == null) 27 | javaVmInstance = new JniJavaVM(vm); 28 | return *javaVmInstance; 29 | } 30 | static ref JniJavaVM GetJavaVM(JavaVM * vm, jint ver) { 31 | if(javaVmInstance == null) 32 | javaVmInstance = new JniJavaVM(vm, ver); 33 | return *javaVmInstance; 34 | } 35 | 36 | private: 37 | static JniJavaVM * javaVmInstance; 38 | }; 39 | -------------------------------------------------------------------------------- /jni/JavaEnv.d: -------------------------------------------------------------------------------- 1 | module jni.JavaEnv; 2 | 3 | import std.stdio; 4 | import std.algorithm; 5 | 6 | import jni.jni; 7 | import jni.JavaVM; 8 | import jni.JavaClass; 9 | 10 | 11 | struct JavaEnv { 12 | public: 13 | // construct from scratch 14 | this(JNIEnv * env) { 15 | val = env; 16 | } 17 | 18 | // default constructor emulation 19 | static JavaEnv opCall() { 20 | return JavaEnv(null); 21 | } 22 | 23 | JNIEnv * Val() { 24 | return val; 25 | } 26 | 27 | const(JNIEnv) * Val() const { 28 | return val; 29 | } 30 | 31 | bool Valid() const { 32 | return val != null; 33 | } 34 | 35 | bool opEquals(JavaEnv env) const { 36 | return opEquals(env); 37 | } 38 | 39 | bool opEquals(ref const(JavaEnv) env) const { 40 | return val == env.val; 41 | } 42 | 43 | jint Version() const { 44 | return val.GetVersion(); 45 | } 46 | 47 | JniJavaVM GetVM() const { 48 | JavaVM * vm; 49 | if(val.GetJavaVM(&vm) != 0) { 50 | writeln("Error: cannot get JavaVM from JNIEnv!"); 51 | return JniJavaVM(); // return invalid 52 | } 53 | return JniJavaVM(vm, Version()); 54 | } 55 | 56 | JavaClass FindClass(string str) { 57 | return JavaClass(this, str); 58 | } 59 | 60 | private: 61 | JNIEnv * val; 62 | } 63 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(V_OS),) 2 | TMP_UNAME := $(shell uname) 3 | 4 | ifeq ($(TMP_UNAME), Linux) 5 | V_OS := Linux 6 | endif 7 | 8 | ifeq ($(TMP_UNAME), Darwin) 9 | V_OS := Mac 10 | endif 11 | 12 | ifeq ($(firstword $(subst _, ,$(TMP_UNAME))), MINGW32) 13 | V_OS := Win 14 | endif 15 | endif 16 | 17 | ifeq ($(ARCH),) 18 | ARCH := $(shell uname -m) 19 | ifeq ($(ARCH),unknown) 20 | ARCH := $$(shell uname -i) 21 | endif 22 | ifeq ($(ARCH),i686) 23 | ARCH := x86 24 | endif 25 | endif 26 | 27 | ifeq ($(BUILD_MODE),) 28 | BUILD_MODE := DEBUG 29 | #BUILD_MODE := RELEASE 30 | endif 31 | 32 | ################################################### 33 | 34 | SOURSE := jni/jni.d jni/JniHelper.d jni/JniProxy.d jni/JavaVM.d jni/JavaEnv.d jni/JavaObject.d jni/JavaClass.d jni/JavaString.d jni/JavaArray.d jni/JavaMethod.d jni/JavaField.d 35 | HEADERS := 36 | 37 | # arch flag 38 | ifeq ($(ARCH),x86) 39 | COMPILER_ARCH_FLAG := -m32 40 | endif 41 | 42 | ifeq ($(ARCH),x86_64) 43 | COMPILER_ARCH_FLAG := -m64 -version=MSym64 44 | endif 45 | 46 | COMPILER_FlAGS_BASIC := -c $(COMPILER_ARCH_FLAG) 47 | 48 | ifneq ($(V_OS), Win) 49 | COMPILER_FlAGS_BASIC += -fPIC 50 | endif 51 | 52 | COMPILER_FLAGS_DEBUG := -debug 53 | COMPILER_FLAGS_RELEASE := -O -release -inline 54 | 55 | ############### 56 | 57 | COMPILER_FLAGS := $(COMPILER_FlAGS_BASIC) $(COMPILER_FLAGS_$(BUILD_MODE)) 58 | 59 | # Defines RESULT_NAME 60 | # Needs V_OS and OUTPUT_TYPE 61 | 62 | RESULT_NAME := libDJni.a 63 | COMPILER := dmd 64 | 65 | ################################################### 66 | 67 | INCLUDES := $(LOCAL_PATH) 68 | 69 | CFLAGS := $(COMPILER_FLAGS) 70 | 71 | ################################################### 72 | 73 | OBJECTS := $(SOURSE:%.d=%.o) 74 | EXPORT_HEADERS := $(HEADERS) 75 | 76 | ################################################### 77 | 78 | all: build 79 | 80 | %.o: %.d 81 | $(COMPILER) $(CFLAGS) $(addprefix -I, $(INCLUDES)) $< -of$@ 82 | 83 | test: 84 | 85 | $(RESULT_NAME): $(OBJECTS) 86 | ar rvs $@ $(OBJECTS) 87 | 88 | build: $(RESULT_NAME) 89 | 90 | clean: 91 | rm -f $(RESULT_NAME) 92 | rm -f $(OBJECTS) 93 | 94 | rebuild: clean build 95 | -------------------------------------------------------------------------------- /jni/JavaString.d: -------------------------------------------------------------------------------- 1 | module jni.JavaString; 2 | 3 | import std.stdio; 4 | import std.algorithm; 5 | 6 | import jni.jni; 7 | import jni.JavaEnv; 8 | import jni.JavaObject; 9 | 10 | 11 | struct JavaString { 12 | public: 13 | static JavaString opCall() { 14 | writefln("%s", __FUNCTION__); 15 | return JavaString(JavaEnv(), cast(jstring) null); 16 | } 17 | 18 | this(JavaEnv env, jstring c) { 19 | writefln("%s(JavaEnv, jstring)", __FUNCTION__); 20 | base.__ctor(env, c); 21 | Init(); 22 | } 23 | 24 | this(JavaEnv env, string _val) { 25 | writefln("%s(JavaEnv, string)", __FUNCTION__); 26 | this(env, env.Val().NewStringUTF(std.string.toStringz(_val))); 27 | } 28 | 29 | this(JavaString str) { 30 | writefln("%s(JavaString)", __FUNCTION__); 31 | swap(base, str.base); 32 | swap(val, str.val); 33 | str.base = JavaObject(); 34 | str.val = null; 35 | } 36 | 37 | this(ref JavaString str) { 38 | writefln("%s(ref JavaString)", __FUNCTION__); 39 | base.__ctor(str.base); 40 | Init(); 41 | } 42 | 43 | this(this) { 44 | writefln("%s", __FUNCTION__); 45 | } 46 | 47 | ~this() { 48 | writefln("%s", __FUNCTION__); 49 | } 50 | 51 | // swap with rvalue 52 | ref JavaString opAssign(JavaString v) { 53 | writefln("%s(JavaString)", __FUNCTION__); 54 | swap(base, v.base); 55 | swap(val, v.val); 56 | return this; 57 | } 58 | 59 | // destroy and copy from lvalue 60 | ref JavaString opAssign(ref JavaString v) { 61 | writefln("%s(ref JavaString)", __FUNCTION__); 62 | base.opAssign(v.base); 63 | val = v.val; 64 | return this; 65 | } 66 | 67 | bool opEquals(ref const(JavaString) str) const { 68 | writefln("%s(ref JavaString)", __FUNCTION__); 69 | return base == str.base || val == str.val; 70 | } 71 | 72 | bool opEquals(string str) const { 73 | return val == str; 74 | } 75 | 76 | 77 | jstring Val() const { return cast(jstring) _obj; } 78 | 79 | string Value() const { 80 | return val; 81 | } 82 | 83 | jsize Length() const { 84 | return _env.Val().GetStringLength(Val()); 85 | } 86 | 87 | jsize Size() const { 88 | return _env.Val().GetStringUTFLength(Val()); 89 | } 90 | 91 | char opIndex(uint n) const { 92 | return val[n]; 93 | } 94 | 95 | JavaObject base; 96 | alias base this; 97 | 98 | private: 99 | string val; 100 | 101 | void Init() { 102 | if(Valid()) { 103 | const(char) * tmp = _env.Val().GetStringUTFChars(Val(), null); 104 | val = std.conv.to!string(tmp); 105 | _env.Val().ReleaseStringUTFChars(Val(), tmp); 106 | } 107 | } 108 | 109 | void Destroy() { 110 | //if(Valid()) 111 | // _env.Val().ReleaseStringUTFChars(Val(), val); 112 | } 113 | 114 | protected: 115 | void Reset(ref const(JavaString) str) { 116 | Destroy(); 117 | base.Reset(str); 118 | Init(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /jni/JavaVM.d: -------------------------------------------------------------------------------- 1 | module jni.JavaVM; 2 | 3 | import std.stdio; 4 | import std.algorithm; 5 | 6 | import jni.jni; 7 | import jni.JavaEnv; 8 | 9 | 10 | struct JniJavaVM { 11 | public: 12 | static const jint JNI_DEFAULT_VERSION = JNI_VERSION_1_6; 13 | 14 | // construct from scratch 15 | this(JavaVM * v, jint ver = JNI_DEFAULT_VERSION) { 16 | val = v; 17 | _version = ver; 18 | doDestroy = false; 19 | } 20 | 21 | // construct from scratch 22 | this(jint ver) { 23 | val = null; 24 | _version = ver; 25 | doDestroy = true; 26 | JNIEnv * env; 27 | JavaVMInitArgs args; 28 | args._version = _version; 29 | args.nOptions = 0; 30 | if(JNI_CreateJavaVM(&val, cast(void**) &env, &args) != 0) { 31 | writeln("Error: cannot create JavaVM!"); 32 | } 33 | } 34 | 35 | this(string classPath, jint ver = JNI_DEFAULT_VERSION) { 36 | val = null; 37 | _version = ver; 38 | doDestroy = true; 39 | JNIEnv * env; 40 | JavaVMInitArgs args; 41 | args._version = _version; 42 | JavaVMOption options[1]; 43 | args.nOptions = 1; 44 | string argCP = "-Djava.class.path=" ~ classPath; 45 | options[0].optionString = cast(char*) std.string.toStringz(argCP); 46 | args.options = options.ptr; 47 | if(JNI_CreateJavaVM(&val, cast(void**) &env, &args) != 0) { 48 | writeln("Error: cannot create JavaVM!"); 49 | } 50 | } 51 | 52 | // postblit 53 | this(this) { 54 | doDestroy = false; 55 | } 56 | 57 | // move from rvalue 58 | this(JniJavaVM v) { 59 | val = v.val; 60 | _version = v._version; 61 | doDestroy = v.doDestroy; 62 | v.doDestroy = false; // we stole the ownership 63 | } 64 | 65 | // copy from lvalue 66 | this(ref const(JniJavaVM) v) { 67 | val = cast(JavaVM*) v.val; 68 | _version = v._version; 69 | doDestroy = false; 70 | } 71 | 72 | // destructor 73 | ~this() { 74 | Destroy(); 75 | } 76 | 77 | // default constructor emulation 78 | static JniJavaVM opCall() { 79 | return JniJavaVM(JNI_DEFAULT_VERSION); 80 | } 81 | 82 | // swap with rvalue 83 | ref JniJavaVM opAssign(JniJavaVM v) { 84 | swap(val, v.val); 85 | swap(_version, v._version); 86 | swap(doDestroy, v.doDestroy); 87 | return this; 88 | } 89 | 90 | // destroy and copy from lvalue 91 | ref JniJavaVM opAssign(ref const(JniJavaVM) v) { 92 | Destroy(); 93 | val = cast(JavaVM*) v.val; 94 | _version = v._version; 95 | doDestroy = false; 96 | return this; 97 | } 98 | 99 | JavaVM * Val() { 100 | return val; 101 | } 102 | 103 | const(JavaVM) * Val() const { 104 | return val; 105 | } 106 | 107 | jint Version() const { 108 | return _version; 109 | } 110 | 111 | bool Valid() const { 112 | return val != null; 113 | } 114 | 115 | bool opEquals(JniJavaVM vm) const { 116 | return opEquals(vm); 117 | } 118 | 119 | bool opEquals(ref const(JniJavaVM) vm) const { 120 | return val == vm.val; 121 | } 122 | 123 | JavaEnv GetEnv() const { 124 | JNIEnv * env = null; 125 | JavaVMAttachArgs attachArgs; 126 | 127 | jint res = val.GetEnv(cast(void**) &env, Version()); 128 | switch(res) { 129 | case JNI_OK: 130 | break; 131 | case JNI_EDETACHED: 132 | attachArgs._version = Version(); 133 | attachArgs.name = cast(char*) std.string.toStringz(""); 134 | attachArgs.group = null; 135 | res = val.AttachCurrentThread(cast(void**) &env, &attachArgs); 136 | if(res != JNI_OK) { 137 | writeln("getJNIEnv: failed to attach to current thread."); 138 | return JavaEnv(); 139 | } 140 | break; 141 | case JNI_EVERSION: 142 | writeln("getJNIEnv: Unsupported JNI version."); 143 | return JavaEnv(); 144 | default: 145 | writeln("getJNIEnv: JNI API error."); 146 | return JavaEnv(); 147 | } 148 | return JavaEnv(env); 149 | } 150 | 151 | private: 152 | JavaVM * val; 153 | jint _version; 154 | bool doDestroy; 155 | 156 | void Destroy() { 157 | if(doDestroy && Valid()) { 158 | val.DestroyJavaVM(); 159 | val = null; 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /jni/JavaField.d: -------------------------------------------------------------------------------- 1 | module jni.JavaField; 2 | 3 | import std.algorithm; 4 | import std.typetuple; 5 | 6 | import jni.jni; 7 | import jni.JniProxy; 8 | import jni.JavaEnv; 9 | import jni.JavaObject; 10 | import jni.JavaClass; 11 | 12 | 13 | struct JavaField(T) { 14 | public: 15 | static JavaField opCall() { 16 | return JavaField(JavaObject(), null); 17 | } 18 | 19 | this(JavaObject obj, jfieldID mid) { 20 | _obj = obj; 21 | _val = mid; 22 | } 23 | 24 | this(JavaField m) { 25 | swap(_obj, m._obj); 26 | swap(_val, m._val); 27 | m._obj = JavaObject(); 28 | m._val = null; 29 | } 30 | 31 | this(ref JavaField m) { 32 | _obj.__ctor(m._obj); 33 | _val = m._val; 34 | } 35 | 36 | ref JavaField opAssign(JavaField m) { 37 | swap(_obj, m._obj); 38 | swap(_val, m._val); 39 | return this; 40 | } 41 | 42 | ref JavaField opAssign(ref JavaField m) { 43 | _obj = m._obj; 44 | _val = m._val; 45 | return this; 46 | } 47 | 48 | bool opEquals(ref const(JavaField) m) const { 49 | return _obj == m._obj && _val == m._val; 50 | } 51 | 52 | jfieldID Val() const { 53 | return cast(jfieldID) _val; 54 | } 55 | 56 | JavaEnv Env() const { 57 | return _obj.Env(); 58 | } 59 | 60 | bool Valid() const { 61 | return _obj.Valid() && _val !is null; 62 | } 63 | 64 | ref const(JavaObject) GetObject() const { 65 | return _obj; 66 | } 67 | 68 | JavaClass GetClass() const { 69 | return GetObject().GetClass(); 70 | } 71 | 72 | static if(IsPrimitiveJniType!T.Val) { 73 | T Get() const { 74 | mixin("return Env().Val().Get" ~ JniFuncTypeName!T.Name ~ "Field(GetObject().Val(), Val());"); 75 | } 76 | void Set(T val) { 77 | mixin("Env().Val().Set" ~ JniFuncTypeName!T.Name ~ "Field(GetObject().Val(), Val(), val);"); 78 | } 79 | } 80 | else { 81 | T Get() const { 82 | return FromJavaProxy!T(Env(), Env().Val().GetObjectField(GetObject().Val(), Val())).Val(); 83 | } 84 | void Set(T val) { 85 | Env().Val().SetObjectField(GetObject().Val(), Val(), ToJavaProxy!T(Env(), val).Val()); 86 | } 87 | } 88 | 89 | private: 90 | JavaObject _obj; 91 | jfieldID _val; 92 | } 93 | 94 | struct JavaStaticField(T) { 95 | public: 96 | static JavaStaticField opCall() { 97 | return JavaStaticField(JavaClass(), null); 98 | } 99 | 100 | this(JavaClass cls, jfieldID mid) { 101 | _cls = cls; 102 | _val = mid; 103 | } 104 | 105 | this(JavaStaticField m) { 106 | swap(_cls, m._cls); 107 | swap(_val, m._val); 108 | m._cls = JavaClass(); 109 | m._val = null; 110 | } 111 | 112 | this(ref JavaStaticField m) { 113 | _cls.__ctor(m._cls); 114 | _val = m._val; 115 | } 116 | 117 | ref JavaStaticField opAssign(JavaStaticField m) { 118 | swap(_cls, m._cls); 119 | swap(_val, m._val); 120 | return this; 121 | } 122 | 123 | ref JavaStaticField opAssign(ref JavaStaticField m) { 124 | _cls = m._cls; 125 | _val = m._val; 126 | return this; 127 | } 128 | 129 | bool opEquals(ref const(JavaStaticField) m) const { 130 | return _cls == m._cls && _val == m._val; 131 | } 132 | 133 | jfieldID Val() const { 134 | return cast(jfieldID) _val; 135 | } 136 | 137 | JavaEnv Env() const { 138 | return _cls.Env(); 139 | } 140 | 141 | bool Valid() const { 142 | return _cls.Valid() && _val !is null; 143 | } 144 | 145 | ref const(JavaClass) GetClass() const { 146 | return _cls; 147 | } 148 | 149 | static if(IsPrimitiveJniType!T.Val) { 150 | T Get() const { 151 | mixin("return Env().Val().GetStatic" ~ JniFuncTypeName!T.Name ~ "Field(GetClass().Val(), Val());"); 152 | } 153 | void Set(T val) { 154 | mixin("Env().Val().SetStatic" ~ JniFuncTypeName!T.Name ~ "Field(GetClass().Val(), Val(), val);"); 155 | } 156 | } 157 | else { 158 | T Get() const { 159 | return FromJavaProxy!T(Env(), Env().Val().GetStaticObjectField(GetClass().Val(), Val())).Val(); 160 | } 161 | void Set(T val) { 162 | Env().Val().SetStaticObjectField(GetClass().Val(), Val(), ToJavaProxy!T(Env(), val).Val()); 163 | } 164 | } 165 | 166 | private: 167 | JavaClass _cls; 168 | jfieldID _val; 169 | } 170 | -------------------------------------------------------------------------------- /jni/JavaClass.d: -------------------------------------------------------------------------------- 1 | module jni.JavaClass; 2 | 3 | import std.stdio; 4 | import std.algorithm; 5 | 6 | import jni.jni; 7 | import jni.JniProxy; 8 | import jni.JavaEnv; 9 | import jni.JavaObject; 10 | import jni.JavaMethod; 11 | import jni.JavaField; 12 | 13 | 14 | struct JavaClass { 15 | public: 16 | static JavaClass opCall() { 17 | writefln("%s", __FUNCTION__); 18 | return JavaClass(JavaEnv(), cast(jclass) null); 19 | } 20 | 21 | this(JavaEnv env, jclass c) { 22 | writefln("%s(JavaEnv, jclass)", __FUNCTION__); 23 | base.__ctor(env, c); 24 | } 25 | 26 | this(JavaEnv env, string val) { 27 | writefln("%s(JavaEnv, string)", __FUNCTION__); 28 | this(env, GetClass(env, val)); 29 | } 30 | 31 | this(JavaClass cls) { 32 | writefln("%s(JavaClass)", __FUNCTION__); 33 | swap(base, cls.base); 34 | cls.base = JavaObject(); 35 | } 36 | 37 | this(ref JavaClass cls) { 38 | writefln("%s(ref JavaClass)", __FUNCTION__); 39 | base.__ctor(cls.base); 40 | } 41 | 42 | this(this) { 43 | writefln("%s", __FUNCTION__); 44 | } 45 | 46 | ~this() { 47 | writefln("%s", __FUNCTION__); 48 | } 49 | 50 | // swap with rvalue 51 | ref JavaClass opAssign(JavaClass v) { 52 | writefln("%s(JavaClass)", __FUNCTION__); 53 | swap(base, v.base); 54 | return this; 55 | } 56 | 57 | // destroy and copy from lvalue 58 | ref JavaClass opAssign(ref JavaClass v) { 59 | writefln("%s(ref JavaClass)", __FUNCTION__); 60 | base.opAssign(v.base); 61 | return this; 62 | } 63 | 64 | bool opEquals(ref const(JavaClass) cls) const { 65 | writefln("%s(ref JavaClass)", __FUNCTION__); 66 | return base == cls.base; 67 | } 68 | 69 | bool opEquals(string str) const { 70 | return _obj == GetClass(Env(), str); 71 | } 72 | 73 | jclass Val() const { 74 | return cast(jclass) base.Val(); 75 | } 76 | 77 | JavaClass Superclass() const { 78 | return FromJavaProxy!JavaClass(Env(), Env().Val().GetSuperclass(Val())).Val(); 79 | } 80 | 81 | jboolean IsAssignableFrom(JavaClass cls) const { 82 | return IsAssignableFrom(cls); 83 | } 84 | 85 | jboolean IsAssignableFrom(ref const(JavaClass) cls) const { 86 | return Env().Val().IsAssignableFrom(Val(), cls.Val()); 87 | } 88 | 89 | JavaMethod!T GetMethod(T)(ref JavaObject obj, string name) const { 90 | return JavaMethod!T(obj, Env().Val().GetMethodID(Val(), std.string.toStringz(name), std.string.toStringz(JniSignatureBuilder!T.Sign))); 91 | } 92 | 93 | JavaStaticMethod!T GetStaticMethod(T)(string name) { 94 | return JavaStaticMethod!T(this, Env().Val().GetStaticMethodID(Val(), std.string.toStringz(name), std.string.toStringz(JniSignatureBuilder!T.Sign))); 95 | } 96 | 97 | // somehow in JNI constructor is not a static method. 98 | // i made it static just for sanity 99 | JavaStaticMethod!T GetConstructor(T)() { 100 | return JavaStaticMethod!T(this, Env().Val().GetMethodID(Val(), std.string.toStringz(""), std.string.toStringz(JniSignatureBuilder!T.Sign))); 101 | } 102 | 103 | JavaStaticMethod!(void function()) GetDefaultConstructor() { 104 | return GetConstructor!(void function())(); 105 | } 106 | 107 | JavaField!T GetField(T)(ref JavaObject obj, string name) const { 108 | return JavaField!T(this, Env().Val().GetFieldID(Val(), std.string.toStringz(name), std.string.toStringz(JniSignatureBuilder!T.Sign))); 109 | } 110 | 111 | JavaStaticField!T GetStaticField(T)(string name) { 112 | return JavaStaticField!T(this, Env().Val().GetStaticFieldID(Val(), std.string.toStringz(name), std.string.toStringz(JniSignatureBuilder!T.Sign))); 113 | } 114 | 115 | T GetStaticFieldValue(T)(string name) { 116 | return GetStaticField!T(name).Get(); 117 | } 118 | 119 | JavaObject NewObject(T : R function(As), R, As...)(As args) { 120 | return FromJavaProxy!JavaObject(Env(), Env().Val().NewObject(Val(), GetConstructor!T().Val(), ToJavaProxy(Env(), args).Val())).Val(); 121 | } 122 | 123 | JavaObject base; 124 | alias base this; 125 | 126 | private: 127 | static jclass GetClass(JavaEnv env, string name) { 128 | if(!env.Valid()) { 129 | writeln("Cannot load class ", name, ", broken JavaEnv."); 130 | return null; 131 | } 132 | 133 | auto cls = env.Val().FindClass(std.string.toStringz(std.array.replace(name, ".", "/"))); 134 | if(cls is null) { 135 | writeln("Cannot find class ", name, "."); 136 | } 137 | 138 | return cls; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /jni/JavaMethod.d: -------------------------------------------------------------------------------- 1 | module jni.JavaMethod; 2 | 3 | import std.algorithm; 4 | import std.typetuple; 5 | 6 | import jni.jni; 7 | import jni.JniProxy; 8 | import jni.JavaEnv; 9 | import jni.JavaObject; 10 | import jni.JavaClass; 11 | 12 | 13 | private { 14 | template Fun(size_t i, T) { 15 | alias Fun = TypeTuple!(std.string.format(", ToJavaProxy!(As[%d])(Env(), args[%d]).Val()", i, i)); 16 | } 17 | 18 | template ConcatStrings() { 19 | const Val = ""; 20 | } 21 | 22 | template ConcatStrings(T, As...) if(!is(T == string)) { 23 | static assert(T); 24 | } 25 | 26 | template ConcatStrings(string s, As...) { 27 | const Val = s ~ ConcatStrings!As.Val; 28 | } 29 | } 30 | 31 | struct JavaMethod(T : R function(As), R, As...) { 32 | public: 33 | //static JavaMethod opCall() { 34 | // return JavaMethod(JavaObject(), null); 35 | //} 36 | 37 | this(JavaObject obj, jmethodID mid) { 38 | _obj = obj; 39 | _val = mid; 40 | } 41 | 42 | this(JavaMethod m) { 43 | swap(_obj, m._obj); 44 | swap(_val, m._val); 45 | m._obj = JavaObject(); 46 | m._val = null; 47 | } 48 | 49 | this(ref JavaMethod m) { 50 | _obj.__ctor(m._obj); 51 | _val = m._val; 52 | } 53 | 54 | ref JavaMethod opAssign(JavaMethod m) { 55 | swap(_obj, m._obj); 56 | swap(_val, m._val); 57 | return this; 58 | } 59 | 60 | ref JavaMethod opAssign(ref JavaMethod m) { 61 | _obj = m._obj; 62 | _val = m._val; 63 | return this; 64 | } 65 | 66 | bool opEquals(ref const(JavaMethod) m) const { 67 | return _obj == m._obj && _val == m._val; 68 | } 69 | 70 | jmethodID Val() const { 71 | return cast(jmethodID) _val; 72 | } 73 | 74 | JavaEnv Env() const { 75 | return _obj.Env(); 76 | } 77 | 78 | bool Valid() const { 79 | return _obj.Valid() && _val !is null; 80 | } 81 | 82 | ref const(JavaObject) GetObject() const { 83 | return _obj; 84 | } 85 | 86 | JavaClass GetClass() const { 87 | return GetObject().GetClass(); 88 | } 89 | 90 | static if(IsPrimitiveJniType!R.Val) { 91 | R opCall(As args) const { 92 | mixin("return Env().Val().Call" ~ JniFuncTypeName!R.Name ~ "Method(GetObject().Val(), Val()" ~ 93 | ConcatStrings!(staticIndexedMap!(Fun, As)).Val ~ 94 | ");"); 95 | } 96 | } 97 | else { 98 | R opCall(As args) const { 99 | mixin("return FromJavaProxy!R(Env(), Env().Val().CallObjectMethod(GetObject().Val(), Val()" ~ 100 | ConcatStrings!(staticIndexedMap!(Fun, As)).Val ~ 101 | ")).Val();"); 102 | } 103 | } 104 | 105 | private: 106 | JavaObject _obj; 107 | jmethodID _val; 108 | } 109 | 110 | struct JavaStaticMethod(T : R function(As), R, As...) { 111 | public: 112 | //static JavaStaticMethod opCall() { 113 | // return JavaStaticMethod(JavaClass(), null); 114 | //} 115 | 116 | this(JavaClass cls, jmethodID mid) { 117 | _cls = cls; 118 | _val = mid; 119 | } 120 | 121 | this(JavaStaticMethod m) { 122 | swap(_cls, m._cls); 123 | swap(_val, m._val); 124 | m._cls = JavaClass(); 125 | m._val = null; 126 | } 127 | 128 | this(ref JavaStaticMethod m) { 129 | _cls.__ctor(m._cls); 130 | _val = m._val; 131 | } 132 | 133 | ref JavaStaticMethod opAssign(JavaStaticMethod m) { 134 | swap(_cls, m._cls); 135 | swap(_val, m._val); 136 | return this; 137 | } 138 | 139 | ref JavaStaticMethod opAssign(ref JavaStaticMethod m) { 140 | _cls = m._cls; 141 | _val = m._val; 142 | return this; 143 | } 144 | 145 | bool opEquals(ref const(JavaStaticMethod) m) const { 146 | return _cls == m._cls && _val == m._val; 147 | } 148 | 149 | jmethodID Val() const { 150 | return cast(jmethodID) _val; 151 | } 152 | 153 | JavaEnv Env() const { 154 | return _cls.Env(); 155 | } 156 | 157 | bool Valid() const { 158 | return _cls.Valid() && _val !is null; 159 | } 160 | 161 | ref const(JavaClass) GetClass() const { 162 | return _cls; 163 | } 164 | 165 | static if(IsPrimitiveJniType!R.Val) { 166 | R opCall(As args) const { 167 | mixin("return Env().Val().CallStatic" ~ JniFuncTypeName!R.Name ~ "Method(GetClass().Val(), Val()" ~ 168 | ConcatStrings!(staticIndexedMap!(Fun, As)).Val ~ 169 | ");"); 170 | } 171 | } 172 | else { 173 | R opCall(As args) const { 174 | mixin("return FromJavaProxy!R(Env(), Env().Val().CallStaticObjectMethod(GetClass().Val(), Val()" ~ 175 | ConcatStrings!(staticIndexedMap!(Fun, As)).Val ~ 176 | ")).Val();"); 177 | } 178 | } 179 | 180 | private: 181 | JavaClass _cls; 182 | jmethodID _val; 183 | } 184 | -------------------------------------------------------------------------------- /jni/JavaArray.d: -------------------------------------------------------------------------------- 1 | module jni.JavaArray; 2 | 3 | import std.stdio; 4 | import std.algorithm; 5 | 6 | import jni.jni; 7 | import jni.JniProxy; 8 | import jni.JavaEnv; 9 | import jni.JavaObject; 10 | import jni.JavaString; 11 | 12 | 13 | struct JavaArray(Elem) { 14 | mixin template Classspec(T) { 15 | static if(IsPrimitiveJniType!T.Val) { 16 | private void GetData(jsize from, jsize len, T * ptr) const { 17 | mixin("Env().Val().Get" ~ JniFuncTypeName!T.Name ~ "ArrayRegion(Val(), from, len, ptr);"); 18 | } 19 | 20 | private void SetData(jsize from, jsize len, const(T) * ptr) { 21 | mixin("Env().Val().Set" ~ JniFuncTypeName!T.Name ~ "ArrayRegion(Val(), from, len, ptr);"); 22 | } 23 | 24 | public T Get(jsize n) const { 25 | T res; 26 | GetData(n, 1, &res); 27 | return res; 28 | } 29 | 30 | public void Set(jsize n, T val) { 31 | SetData(n, 1, &val); 32 | } 33 | 34 | public T[] ToVector() const { 35 | auto len = Length(); 36 | if(len == 0) 37 | return []; 38 | T[] res = std.array.uninitializedArray!(T[])(len); 39 | GetData(0, len, &res[0]); 40 | return res; 41 | } 42 | 43 | private void FromVector(T[] vec) { 44 | SetData(0, cast(jsize) vec.length, &vec[0]); 45 | } 46 | 47 | alias JniArrayType!T.type Arr; 48 | } 49 | else { 50 | public T Get(jsize n) const { 51 | return FromJavaProxy!T(Env(), Env().Val().GetObjectArrayElement(Val(), n)).Val(); 52 | } 53 | 54 | public void Set(jsize n, T val) { 55 | Env().Val().SetObjectArrayElement(Val(), n, ToJavaProxy!T(Env(), val).Val()); 56 | } 57 | 58 | //public this(JavaEnv env, jsize size) { 59 | // writefln("%s(JavaEnv, jsize)", __FUNCTION__); 60 | // this(env, mixin("env.Val().New" ~ JniFuncTypeName!jobject.Name ~ "Array(size)")); 61 | //} 62 | 63 | public T[] ToVector() const { 64 | auto len = Length(); 65 | if(len == 0) 66 | return []; 67 | T[] res = std.array.uninitializedArray!(T[])(len); 68 | for(auto i = 0; i < len; ++i) 69 | res[i] = Get(i); 70 | return res; 71 | } 72 | 73 | private void FromVector(T[] vec) { 74 | auto len = vec.length; 75 | for(auto i = 0; i < len; ++i) 76 | Set(i, vec[i]); 77 | } 78 | 79 | alias JniArrayType!jobject.type Arr; 80 | } 81 | } 82 | 83 | mixin Classspec!Elem; 84 | 85 | public: 86 | static JavaArray!Elem opCall() { 87 | return JavaArray(JavaEnv(), cast(Arr) null); 88 | } 89 | 90 | this(JavaEnv env, Arr arr) { 91 | writefln("%s(JavaEnv, Arr)", __FUNCTION__); 92 | base.__ctor(env, arr); 93 | } 94 | 95 | this(JavaEnv env, Elem[] vec) { 96 | writefln("%s(JavaEnv, Elem[])", __FUNCTION__); 97 | this(env, cast(jsize) vec.length); 98 | FromVector(vec); 99 | } 100 | 101 | static if(IsPrimitiveJniType!Elem.Val) { 102 | this(JavaEnv env, jsize size) { 103 | writefln("%s(JavaEnv, jsize)", __FUNCTION__); 104 | mixin("this(env, env.Val().New" ~ JniFuncTypeName!Elem.Name ~ "Array(size));"); 105 | } 106 | } 107 | else { 108 | this(JavaEnv env, jsize size) { 109 | writefln("%s(JavaEnv, jsize)", __FUNCTION__); 110 | this(env, env.Val().NewObjectArray(size, env.FindClass(JniSignatureBuilder!Elem.Sign).Val(), null)); 111 | } 112 | } 113 | 114 | this(JavaArray arr) { 115 | writefln("%s(JavaArray)", __FUNCTION__); 116 | swap(base, arr.base); 117 | arr.base = JavaObject(); 118 | } 119 | 120 | this(ref JavaArray arr) { 121 | writefln("%s(ref JavaArray)", __FUNCTION__); 122 | base.__ctor(arr.base); 123 | } 124 | 125 | this(this) { 126 | writefln("%s", __FUNCTION__); 127 | } 128 | 129 | ~this() { 130 | writefln("%s", __FUNCTION__); 131 | } 132 | 133 | // swap with rvalue 134 | ref JavaArray opAssign(JavaArray v) { 135 | writefln("%s(JavaArray)", __FUNCTION__); 136 | swap(base, v.base); 137 | return this; 138 | } 139 | 140 | // destroy and copy from lvalue 141 | ref JavaArray opAssign(ref JavaArray v) { 142 | writefln("%s(ref JavaArray)", __FUNCTION__); 143 | base.opAssign(v.base); 144 | return this; 145 | } 146 | 147 | bool opEquals(ref const(JavaArray) arr) const { 148 | writefln("%s(ref JavaString)", __FUNCTION__); 149 | if(base == arr.base) 150 | return true; 151 | 152 | auto l1 = Length(), l2 = arr.Length(); 153 | if(l1 != l2) 154 | return false; 155 | 156 | return ToVector() == arr.ToVector(); 157 | } 158 | 159 | bool opEquals(Elem[] arr) const { 160 | if(Length() != arr.length) 161 | return false; 162 | return ToVector() == arr; 163 | } 164 | 165 | Elem opIndex(uint n) const { 166 | return Get(n); 167 | } 168 | 169 | jsize Length() const { 170 | return Env().Val().GetArrayLength(Val()); 171 | } 172 | 173 | Arr Val() const { return cast(Arr) _obj; } 174 | 175 | JavaObject base; 176 | alias base this; 177 | } 178 | -------------------------------------------------------------------------------- /jni/JavaObject.d: -------------------------------------------------------------------------------- 1 | module jni.JavaObject; 2 | 3 | import std.stdio; 4 | import std.algorithm; 5 | 6 | import jni.jni; 7 | import jni.JniProxy; 8 | import jni.JavaEnv; 9 | import jni.JavaClass; 10 | import jni.JavaMethod; 11 | import jni.JavaField; 12 | 13 | 14 | version = MSYM_DEBUG_JNI_REF_CNT; 15 | 16 | version(MSYM_DEBUG_JNI_REF_CNT) { 17 | int globalRefCnt = 0; 18 | int maxGlobalRefCnt = 0; 19 | } 20 | 21 | 22 | struct JavaObject { 23 | public: 24 | static JavaObject opCall() { 25 | writefln("%s", __PRETTY_FUNCTION__); 26 | return JavaObject(JavaEnv(), null); 27 | } 28 | 29 | this(JavaEnv env, jobject o) { 30 | writefln("%s(JavaEnv, jobject)", __FUNCTION__); 31 | _env = env; 32 | _obj = o; 33 | version(MSYM_DEBUG_JNI_REF_CNT) { 34 | if(Valid()) { 35 | maxGlobalRefCnt++; 36 | globalRefCnt++; 37 | } 38 | } 39 | } 40 | 41 | this(JavaObject o) { 42 | writefln("%s(JavaObject)", __FUNCTION__); 43 | _env = o._env; 44 | _obj = o._obj; 45 | o._env = JavaEnv(); 46 | o._obj = null; 47 | } 48 | 49 | this(ref JavaObject o) { 50 | writefln("%s(ref JavaObject)", __FUNCTION__); 51 | Init(o); 52 | } 53 | 54 | this(this) { 55 | writefln("%s", __FUNCTION__); 56 | Init(this); 57 | } 58 | 59 | ~this() { 60 | writefln("%s", __FUNCTION__); 61 | Destroy(); 62 | } 63 | 64 | // swap with rvalue 65 | ref JavaObject opAssign(JavaObject v) { 66 | writefln("%s(JavaObject)", __FUNCTION__); 67 | swap(_env, v._env); 68 | swap(_obj, v._obj); 69 | return this; 70 | } 71 | 72 | // destroy and copy from lvalue 73 | ref JavaObject opAssign(ref JavaObject v) { 74 | writefln("%s(ref JavaObject)", __FUNCTION__); 75 | Reset(v); 76 | return this; 77 | } 78 | 79 | bool opEquals(ref const(JavaObject) v) const { 80 | writefln("%s(ref const(JavaObject))", __FUNCTION__); 81 | return Env().Val().IsSameObject(Val(), v.Val()) == JNI_TRUE; 82 | } 83 | 84 | // static JavaObject New(const JavaClass& cls); 85 | // static JavaObject New(JavaEnv env, const std::string& cls); 86 | 87 | // template 88 | // static JavaObject New(const JavaClass& cls, Args&& ... args); 89 | 90 | // template 91 | // static JavaObject New(JavaEnv env, const std::string& cls); 92 | 93 | 94 | JavaClass GetClass() const { 95 | return FromJavaProxy!JavaClass(Env(), Env().Val().GetObjectClass(Val())).Val(); 96 | } 97 | 98 | bool Valid() const { return _env.Valid() && _obj !is null; } 99 | JavaEnv Env() const { return cast(JavaEnv) _env; } 100 | 101 | jobject Val() const { return cast(jobject) _obj; } 102 | 103 | jint MonitorEnter() const { 104 | return _env.Val().MonitorEnter(Val()); 105 | } 106 | 107 | jint MonitorExit() const { 108 | return _env.Val().MonitorExit(Val()); 109 | } 110 | 111 | JavaMethod!T GetMethod(T)(string name) { 112 | return GetClass().GetMethod!T(this, name); 113 | } 114 | 115 | JavaField!T GetField(T)(string name) { 116 | return GetClass().GetField!T(this, name); 117 | } 118 | 119 | T GetFieldValue(T)(string name) { 120 | return GetField!T(name).Get(); 121 | } 122 | 123 | package: 124 | void Reset(ref const(JavaObject) o) { 125 | Destroy(); 126 | Init(o); 127 | } 128 | 129 | private: 130 | void Init(ref const(JavaObject) o) { 131 | _env = cast(JavaEnv) o._env; 132 | if(o.Valid()) { 133 | version(MSYM_DEBUG_JNI_REF_CNT) { 134 | maxGlobalRefCnt++; 135 | globalRefCnt++; 136 | } 137 | _obj = _env.Val().NewLocalRef(cast(jobject) o._obj); 138 | } 139 | } 140 | 141 | void Destroy() { 142 | if(Valid()) { 143 | version(MSYM_DEBUG_JNI_REF_CNT) 144 | globalRefCnt--; 145 | _env.Val().DeleteLocalRef(_obj); 146 | } 147 | } 148 | 149 | package: 150 | JavaEnv _env; 151 | jobject _obj; 152 | } 153 | 154 | struct JavaBoolean { 155 | public: 156 | static JavaBoolean opCall() { 157 | writefln("%s", __PRETTY_FUNCTION__); 158 | return JavaBoolean(JavaEnv(), null); 159 | } 160 | this(JavaEnv env, jobject c) { 161 | writefln("%s(JavaEnv, jobject)", __FUNCTION__); 162 | base.__ctor(env, c); 163 | } 164 | 165 | this(JavaBoolean cls) { 166 | writefln("%s(JavaBoolean)", __FUNCTION__); 167 | swap(base, cls.base); 168 | cls.base = JavaObject(); 169 | } 170 | 171 | this(ref JavaBoolean cls) { 172 | writefln("%s(ref JavaBoolean)", __FUNCTION__); 173 | base.__ctor(cls.base); 174 | } 175 | 176 | this(this) { 177 | writefln("%s", __FUNCTION__); 178 | } 179 | 180 | ~this() { 181 | writefln("%s", __FUNCTION__); 182 | } 183 | 184 | // swap with rvalue 185 | ref JavaBoolean opAssign(JavaBoolean v) { 186 | writefln("%s(JavaBoolean)", __FUNCTION__); 187 | swap(base, v.base); 188 | return this; 189 | } 190 | 191 | // destroy and copy from lvalue 192 | ref JavaBoolean opAssign(ref JavaBoolean v) { 193 | writefln("%s(ref JavaBoolean)", __FUNCTION__); 194 | base.opAssign(v.base); 195 | return this; 196 | } 197 | JavaObject base; 198 | alias base this; 199 | } 200 | -------------------------------------------------------------------------------- /jni/JniProxy.d: -------------------------------------------------------------------------------- 1 | module jni.JniProxy; 2 | 3 | import std.typetuple; 4 | 5 | import jni.jni; 6 | import jni.JavaEnv; 7 | import jni.JavaObject; 8 | import jni.JavaClass; 9 | import jni.JavaString; 10 | import jni.JavaArray; 11 | 12 | 13 | template _staticIndexedMap(alias F, size_t N, T...) 14 | { 15 | static if (T.length == 0) 16 | { 17 | alias _staticIndexedMap = TypeTuple!(); 18 | } 19 | else static if (T.length == 1) 20 | { 21 | alias _staticIndexedMap = TypeTuple!(F!(N, T[0])); 22 | } 23 | else 24 | { 25 | alias _staticIndexedMap = 26 | TypeTuple!( 27 | _staticIndexedMap!(F, N, T[0]), 28 | _staticIndexedMap!(F, N + 1, T[1 .. $ ])); 29 | } 30 | } 31 | 32 | template staticIndexedMap(alias F, T...) 33 | { 34 | alias staticIndexedMap = _staticIndexedMap!(F, 0, T); 35 | } 36 | 37 | unittest 38 | { 39 | template Indexate(size_t i, T) 40 | { 41 | alias Fun = TypeTuple!(i, T); 42 | } 43 | 44 | // empty 45 | alias staticIndexedMap!(Indexate) Empty; 46 | static assert(Empty.length == 0); 47 | 48 | // single 49 | alias staticIndexedMap!(Indexate, int) Single; 50 | static assert(Single[0] == 0 && is(Single[1] == int)); 51 | 52 | alias TL = staticIndexedMap!(Indexate, int, string); 53 | static assert(TL[0] == 0 && is(TL[3] == string)); 54 | } 55 | 56 | 57 | //template _TypeMap(alias MAP, size_t N, TS...) { 58 | // static if (N < TS.length) { 59 | // alias _TypeMap = _TypeMap!(MAP, N + 1, TS[0..N], typeof(MAP(size_t.init, TS[N].init)), TS[N + 1..$]); 60 | // } 61 | // else { 62 | // alias _TypeMap = TS; 63 | // } 64 | //} 65 | 66 | //template TypeMap(alias MAP, TS...) { 67 | // alias TypeMap = _TypeMap!(MAP, 0, TS); 68 | //} 69 | 70 | //struct _ForEach(alias MAP, TS...) { 71 | // //pragma(msg, TS); 72 | // //pragma(msg, TypeMap!(MAP, TS)); 73 | // TypeMap!(MAP, TS) tuple; 74 | 75 | // this(TS values) { 76 | // foreach (size_t i, ref v; values) 77 | // tuple[i] = MAP(i, v); 78 | // } 79 | //} 80 | 81 | //auto ForEach(alias MAP, TS...)(TS ts) { 82 | // return _ForEach!(MAP, TS)(ts); 83 | //} 84 | 85 | 86 | template IsPrimitiveJniType(T) { 87 | static if(is(T == jboolean) || 88 | is(T == jbyte) || 89 | is(T == jchar) || 90 | is(T == jshort) || 91 | is(T == jint) || 92 | is(T == jlong) || 93 | is(T == jfloat) || 94 | is(T == jdouble) || 95 | is(T == void)) 96 | const Val = true; 97 | else 98 | const Val = false; 99 | } 100 | 101 | template JniArrayType(T) { 102 | alias jarray type; 103 | } 104 | 105 | template JniArrayType(T : jboolean) { 106 | alias jbooleanArray type; 107 | } 108 | 109 | template JniArrayType(T : jbyte) { 110 | alias jbyteArray type; 111 | } 112 | 113 | template JniArrayType(T : jchar) { 114 | alias jcharArray type; 115 | } 116 | 117 | template JniArrayType(T : jshort) { 118 | alias jshortArray type; 119 | } 120 | 121 | template JniArrayType(T : jint) { 122 | alias jintArray type; 123 | } 124 | 125 | template JniArrayType(T : jlong) { 126 | alias jlongArray type; 127 | } 128 | 129 | template JniArrayType(T : jfloat) { 130 | alias jfloatArray type; 131 | } 132 | 133 | template JniArrayType(T : jdouble) { 134 | alias jdoubleArray type; 135 | } 136 | 137 | template JniArrayType(T : jobject) { 138 | alias jobjectArray type; 139 | } 140 | 141 | template JniFuncTypeName(T) { 142 | static assert(false); 143 | } 144 | template JniFuncTypeName(T : void) { 145 | const Name = "Void"; 146 | } 147 | template JniFuncTypeName(T : jboolean) { 148 | const Name = "Boolean"; 149 | } 150 | template JniFuncTypeName(T : jbyte) { 151 | const Name = "Byte"; 152 | } 153 | template JniFuncTypeName(T : jchar) { 154 | const Name = "Char"; 155 | } 156 | template JniFuncTypeName(T : jshort) { 157 | const Name = "Short"; 158 | } 159 | template JniFuncTypeName(T : jint) { 160 | const Name = "Int"; 161 | } 162 | template JniFuncTypeName(T : jlong) { 163 | const Name = "Long"; 164 | } 165 | template JniFuncTypeName(T : jfloat) { 166 | const Name = "Float"; 167 | } 168 | template JniFuncTypeName(T : jdouble) { 169 | const Name = "Double"; 170 | } 171 | template JniFuncTypeName(T : jobject) { 172 | const Name = "Object"; 173 | } 174 | 175 | 176 | template JniSignatureBuilder(T) { 177 | static assert(false); 178 | } 179 | template JniSignatureBuilder() { 180 | const Sign = ""; 181 | } 182 | template JniSignatureBuilder(T, Ts...) { 183 | const Sign = JniSignatureBuilder!T.Sign ~ JniSignatureBuilder!Ts.Sign; 184 | } 185 | template JniSignatureBuilder(T : void) { 186 | const Sign = "V"; 187 | } 188 | template JniSignatureBuilder(T : jboolean) { 189 | const Sign = "Z"; 190 | } 191 | template JniSignatureBuilder(T : jbyte) { 192 | const Sign = "B"; 193 | } 194 | template JniSignatureBuilder(T : jchar) { 195 | const Sign = "C"; 196 | } 197 | template JniSignatureBuilder(T : jshort) { 198 | const Sign = "S"; 199 | } 200 | template JniSignatureBuilder(T : jint) { 201 | const Sign = "I"; 202 | } 203 | template JniSignatureBuilder(T : jlong) { 204 | const Sign = "J"; 205 | } 206 | template JniSignatureBuilder(T : jfloat) { 207 | const Sign = "F"; 208 | } 209 | template JniSignatureBuilder(T : jdouble) { 210 | const Sign = "D"; 211 | } 212 | template JniSignatureBuilder(T : JavaObject) { 213 | const Sign = "Ljava/lang/Object;"; 214 | } 215 | template JniSignatureBuilder(T : JavaBoolean) { 216 | const Sign = "Ljava/lang/Boolean;"; 217 | } 218 | template JniSignatureBuilder(T : JavaString) { 219 | const Sign = "Ljava/lang/String;"; 220 | } 221 | template JniSignatureBuilder(T : JavaArray!U, U) { 222 | const Sign = "[" ~ JniSignatureBuilder!U.Sign; 223 | } 224 | template JniSignatureBuilder(T : string) { 225 | const Sign = JniSignatureBuilder!JavaString.Sign; 226 | } 227 | template JniSignatureBuilder(T : U[], U) { 228 | const Sign = JniSignatureBuilder!(JavaArray!U, U).Sign; 229 | } 230 | template JniSignatureBuilder(T : R function(As), R, As...) { 231 | const Sign = "(" ~ JniSignatureBuilder!As.Sign ~ ")" ~ JniSignatureBuilder!R.Sign; 232 | } 233 | 234 | 235 | template JniToJavaProxy(T) { 236 | struct JniToJavaProxy { 237 | this(JavaEnv, T v) { 238 | val = v; 239 | } 240 | T Val() const { return val; } 241 | T val; 242 | } 243 | } 244 | 245 | template JniToJavaProxy(T : JavaObject) { 246 | struct JniToJavaProxy { 247 | this(JavaEnv, ref T v) { 248 | val = v; 249 | } 250 | jobject Val() const { return val.Val(); } 251 | T val; 252 | } 253 | } 254 | 255 | template JniToJavaProxy(T : JavaBoolean) { 256 | struct JniToJavaProxy { 257 | this(JavaEnv, ref T v) { 258 | val = v; 259 | } 260 | jobject Val() const { return val.Val(); } 261 | T val; 262 | } 263 | } 264 | 265 | template JniToJavaProxy(T : JavaClass) { 266 | struct JniToJavaProxy { 267 | this(JavaEnv, ref T v) { 268 | val = v; 269 | } 270 | jobject Val() const { return val.Val(); } 271 | T val; 272 | } 273 | } 274 | 275 | template JniToJavaProxy(T : JavaString) { 276 | struct JniToJavaProxy { 277 | this(JavaEnv, ref T v) { 278 | val = v; 279 | } 280 | jobject Val() const { return val.Val(); } 281 | T val; 282 | } 283 | } 284 | 285 | template JniToJavaProxy(T : JavaArray!U, U) { 286 | struct JniToJavaProxy { 287 | this(JavaEnv, ref T v) { 288 | val = v; 289 | } 290 | jobject Val() const { return val.Val(); } 291 | T val; 292 | } 293 | } 294 | 295 | template JniToJavaProxy(T : string) { 296 | struct JniToJavaProxy { 297 | this(JavaEnv env, ref T v) { 298 | val.__ctor(env, v); 299 | } 300 | jobject Val() const { return val.Val(); } 301 | JavaString val; 302 | } 303 | } 304 | 305 | template JniToJavaProxy(T : U[], U) { 306 | struct JniToJavaProxy { 307 | this(JavaEnv env, ref T v) { 308 | val.__ctor(env, v); 309 | } 310 | jobject Val() const { return val.Val(); } 311 | JavaArray!U val; 312 | } 313 | } 314 | 315 | import std.typecons : tuple; 316 | 317 | auto ToJavaProxy(T)(JavaEnv env, T v) { 318 | return JniToJavaProxy!T(env, v); 319 | } 320 | 321 | auto ToJavaProxy(Ts...)(JavaEnv env, Ts ts) if(ts.length > 1) { 322 | return tuple(ToJavaProxy!(Ts[0])(env, ts[0]).tupleof, ToJavaProxy!(Ts[1..$])(env, ts[1..$]).tupleof); 323 | } 324 | 325 | template JniFromJavaProxy(T : JavaObject) { 326 | struct JniFromJavaProxy { 327 | this(JavaEnv env, jobject obj) { 328 | _env = env; 329 | _obj = obj; 330 | } 331 | T Val() { 332 | return T(_env, _obj); 333 | } 334 | JavaEnv _env; 335 | jobject _obj; 336 | } 337 | } 338 | 339 | template JniFromJavaProxy(T : JavaBoolean) { 340 | struct JniFromJavaProxy { 341 | this(JavaEnv env, jobject obj) { 342 | _env = env; 343 | _obj = obj; 344 | } 345 | T Val() { 346 | return T(_env, _obj); 347 | } 348 | JavaEnv _env; 349 | jobject _obj; 350 | } 351 | } 352 | 353 | template JniFromJavaProxy(T : JavaClass) { 354 | struct JniFromJavaProxy { 355 | this(JavaEnv env, jobject obj) { 356 | _env = env; 357 | _obj = cast(jclass) obj; 358 | } 359 | T Val() { 360 | return T(_env, _obj); 361 | } 362 | JavaEnv _env; 363 | jclass _obj; 364 | } 365 | } 366 | 367 | template JniFromJavaProxy(T : JavaString) { 368 | struct JniFromJavaProxy { 369 | this(JavaEnv env, jobject obj) { 370 | _env = env; 371 | _obj = cast(jstring) obj; 372 | } 373 | T Val() { 374 | return T(_env, _obj); 375 | } 376 | JavaEnv _env; 377 | jstring _obj; 378 | } 379 | } 380 | 381 | template JniFromJavaProxy(T : JavaArray!U, U) { 382 | struct JniFromJavaProxy { 383 | this(JavaEnv env, jobject obj) { 384 | _env = env; 385 | _obj = cast(JniArrayType!U.type) obj; 386 | } 387 | T Val() { 388 | return T(_env, _obj); 389 | } 390 | JavaEnv _env; 391 | JniArrayType!U.type _obj; 392 | } 393 | } 394 | 395 | template JniFromJavaProxy(T : string) { 396 | struct JniFromJavaProxy { 397 | this(JavaEnv env, jobject obj) { 398 | _env = env; 399 | _obj = cast(jstring) obj; 400 | } 401 | T Val() { 402 | return JavaString(_env, _obj).Value(); 403 | } 404 | JavaEnv _env; 405 | jstring _obj; 406 | } 407 | } 408 | 409 | template JniFromJavaProxy(T : U[], U) { 410 | struct JniFromJavaProxy { 411 | this(JavaEnv env, jobject obj) { 412 | _env = env; 413 | _obj = cast(JniArrayType!U.type) obj; 414 | } 415 | T Val() { 416 | return JniFromJavaProxy!(JavaArray!U, U)(_env, _obj).Val().ToVector(); 417 | } 418 | JavaEnv _env; 419 | JniArrayType!U.type _obj; 420 | } 421 | } 422 | 423 | auto FromJavaProxy(T, J)(JavaEnv env, J v) { 424 | return JniFromJavaProxy!(T)(env, v); 425 | } 426 | -------------------------------------------------------------------------------- /jni/jni.d: -------------------------------------------------------------------------------- 1 | module jni.jni; 2 | 3 | import core.vararg; 4 | 5 | 6 | extern (C) { 7 | 8 | alias int jint; 9 | alias long jlong; 10 | alias byte jbyte; 11 | alias ubyte jboolean; 12 | alias ushort jchar; 13 | alias short jshort; 14 | alias float jfloat; 15 | alias double jdouble; 16 | alias jint jsize; 17 | 18 | class _jobject {} 19 | alias _jobject jobject; 20 | alias _jobject jclass; 21 | alias _jobject jthrowable; 22 | alias _jobject jstring; 23 | alias _jobject jarray; 24 | alias _jobject jbooleanArray; 25 | alias _jobject jbyteArray; 26 | alias _jobject jcharArray; 27 | alias _jobject jshortArray; 28 | alias _jobject jintArray; 29 | alias _jobject jlongArray; 30 | alias _jobject jfloatArray; 31 | alias _jobject jdoubleArray; 32 | alias _jobject jobjectArray; 33 | 34 | alias jobject jweak; 35 | 36 | 37 | union jvalue { 38 | jboolean z; 39 | jbyte b; 40 | jchar c; 41 | jshort s; 42 | jint i; 43 | jlong j; 44 | jfloat f; 45 | jdouble d; 46 | jobject l; 47 | } 48 | 49 | 50 | class _jfieldID {} 51 | alias _jfieldID jfieldID; 52 | 53 | struct _jmethodID {} 54 | alias _jmethodID* jmethodID; 55 | 56 | 57 | enum _jobjectType { 58 | JNIInvalidRefType, 59 | JNILocalRefType, 60 | JNIGlobalRefType, 61 | JNIWeakGlobalRefType, 62 | } 63 | 64 | alias _jobjectType jobjectRefType; 65 | 66 | 67 | const JNI_FALSE = 0; 68 | const JNI_TRUE = 1; 69 | 70 | 71 | const JNI_OK = ( 0); /* success */ 72 | const JNI_ERR = (-1); /* unknown error */ 73 | const JNI_EDETACHED = (-2); /* thread detached from the VM */ 74 | const JNI_EVERSION = (-3); /* JNI version error */ 75 | const JNI_ENOMEM = (-4); /* not enough memory */ 76 | const JNI_EEXIST = (-5); /* VM already created */ 77 | const JNI_EINVAL = (-6); /* invalid arguments */ 78 | 79 | 80 | const JNI_COMMIT = 1; 81 | const JNI_ABORT = 2; 82 | 83 | 84 | struct JNINativeMethod { 85 | char *name; 86 | char *signature; 87 | void *fnPtr; 88 | } 89 | 90 | 91 | struct JNINativeInterface_ { 92 | void *reserved0; 93 | void *reserved1; 94 | void *reserved2; 95 | void *reserved3; 96 | jint function(const(JNIEnv_) *env)GetVersion; 97 | jclass function(const(JNIEnv_) *env, const(char) *name, jobject loader, const(jbyte) *buf, jsize len)DefineClass; 98 | jclass function(const(JNIEnv_) *env, const(char) *name)FindClass; 99 | jmethodID function(const(JNIEnv_) *env, jobject method)FromReflectedMethod; 100 | jfieldID function(const(JNIEnv_) *env, jobject field)FromReflectedField; 101 | jobject function(const(JNIEnv_) *env, jclass cls, jmethodID methodID, jboolean isStatic)ToReflectedMethod; 102 | jclass function(const(JNIEnv_) *env, jclass sub)GetSuperclass; 103 | jboolean function(const(JNIEnv_) *env, jclass sub, jclass sup)IsAssignableFrom; 104 | jobject function(const(JNIEnv_) *env, jclass cls, jfieldID fieldID, jboolean isStatic)ToReflectedField; 105 | jint function(const(JNIEnv_) *env, jthrowable obj)Throw; 106 | jint function(const(JNIEnv_) *env, jclass clazz, const(char) *msg)ThrowNew; 107 | jthrowable function(const(JNIEnv_) *env)ExceptionOccurred; 108 | void function(const(JNIEnv_) *env)ExceptionDescribe; 109 | void function(const(JNIEnv_) *env)ExceptionClear; 110 | void function(const(JNIEnv_) *env, const(char) *msg)FatalError; 111 | jint function(const(JNIEnv_) *env, jint capacity)PushLocalFrame; 112 | jobject function(const(JNIEnv_) *env, jobject result)PopLocalFrame; 113 | jobject function(const(JNIEnv_) *env, jobject lobj)NewGlobalRef; 114 | void function(const(JNIEnv_) *env, jobject gref)DeleteGlobalRef; 115 | void function(const(JNIEnv_) *env, jobject obj)DeleteLocalRef; 116 | jboolean function(const(JNIEnv_) *env, jobject obj1, jobject obj2)IsSameObject; 117 | jobject function(const(JNIEnv_) *env, jobject _ref)NewLocalRef; 118 | jint function(const(JNIEnv_) *env, jint capacity)EnsureLocalCapacity; 119 | jobject function(const(JNIEnv_) *env, jclass clazz)AllocObject; 120 | jobject function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)NewObject; 121 | jobject function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)NewObjectV; 122 | jobject function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)NewObjectA; 123 | jclass function(const(JNIEnv_) *env, jobject obj)GetObjectClass; 124 | jboolean function(const(JNIEnv_) *env, jobject obj, jclass clazz)IsInstanceOf; 125 | jmethodID function(const(JNIEnv_) *env, jclass clazz, const(char) *name, const(char) *sig)GetMethodID; 126 | jobject function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallObjectMethod; 127 | jobject function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallObjectMethodV; 128 | jobject function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallObjectMethodA; 129 | jboolean function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallBooleanMethod; 130 | jboolean function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallBooleanMethodV; 131 | jboolean function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallBooleanMethodA; 132 | jbyte function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallByteMethod; 133 | jbyte function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallByteMethodV; 134 | jbyte function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallByteMethodA; 135 | jchar function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallCharMethod; 136 | jchar function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallCharMethodV; 137 | jchar function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallCharMethodA; 138 | jshort function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallShortMethod; 139 | jshort function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallShortMethodV; 140 | jshort function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallShortMethodA; 141 | jint function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallIntMethod; 142 | jint function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallIntMethodV; 143 | jint function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallIntMethodA; 144 | jlong function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallLongMethod; 145 | jlong function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallLongMethodV; 146 | jlong function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallLongMethodA; 147 | jfloat function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallFloatMethod; 148 | jfloat function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallFloatMethodV; 149 | jfloat function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallFloatMethodA; 150 | jdouble function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallDoubleMethod; 151 | jdouble function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallDoubleMethodV; 152 | jdouble function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallDoubleMethodA; 153 | void function(const(JNIEnv_) *env, jobject obj, jmethodID methodID,...)CallVoidMethod; 154 | void function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, va_list args)CallVoidMethodV; 155 | void function(const(JNIEnv_) *env, jobject obj, jmethodID methodID, const(jvalue) *args)CallVoidMethodA; 156 | jobject function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualObjectMethod; 157 | jobject function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualObjectMethodV; 158 | jobject function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualObjectMethodA; 159 | jboolean function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualBooleanMethod; 160 | jboolean function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualBooleanMethodV; 161 | jboolean function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualBooleanMethodA; 162 | jbyte function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualByteMethod; 163 | jbyte function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualByteMethodV; 164 | jbyte function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualByteMethodA; 165 | jchar function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualCharMethod; 166 | jchar function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualCharMethodV; 167 | jchar function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualCharMethodA; 168 | jshort function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualShortMethod; 169 | jshort function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualShortMethodV; 170 | jshort function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualShortMethodA; 171 | jint function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualIntMethod; 172 | jint function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualIntMethodV; 173 | jint function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualIntMethodA; 174 | jlong function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualLongMethod; 175 | jlong function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualLongMethodV; 176 | jlong function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualLongMethodA; 177 | jfloat function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualFloatMethod; 178 | jfloat function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualFloatMethodV; 179 | jfloat function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualFloatMethodA; 180 | jdouble function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualDoubleMethod; 181 | jdouble function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualDoubleMethodV; 182 | jdouble function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualDoubleMethodA; 183 | void function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID,...)CallNonvirtualVoidMethod; 184 | void function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)CallNonvirtualVoidMethodV; 185 | void function(const(JNIEnv_) *env, jobject obj, jclass clazz, jmethodID methodID, const(jvalue) *args)CallNonvirtualVoidMethodA; 186 | jfieldID function(const(JNIEnv_) *env, jclass clazz, const(char) *name, const(char) *sig)GetFieldID; 187 | jobject function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetObjectField; 188 | jboolean function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetBooleanField; 189 | jbyte function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetByteField; 190 | jchar function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetCharField; 191 | jshort function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetShortField; 192 | jint function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetIntField; 193 | jlong function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetLongField; 194 | jfloat function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetFloatField; 195 | jdouble function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID)GetDoubleField; 196 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jobject val)SetObjectField; 197 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jboolean val)SetBooleanField; 198 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jbyte val)SetByteField; 199 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jchar val)SetCharField; 200 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jshort val)SetShortField; 201 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jint val)SetIntField; 202 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jlong val)SetLongField; 203 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jfloat val)SetFloatField; 204 | void function(const(JNIEnv_) *env, jobject obj, jfieldID fieldID, jdouble val)SetDoubleField; 205 | jmethodID function(const(JNIEnv_) *env, jclass clazz, const(char) *name, const(char) *sig)GetStaticMethodID; 206 | jobject function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticObjectMethod; 207 | jobject function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticObjectMethodV; 208 | jobject function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticObjectMethodA; 209 | jboolean function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticBooleanMethod; 210 | jboolean function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticBooleanMethodV; 211 | jboolean function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticBooleanMethodA; 212 | jbyte function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticByteMethod; 213 | jbyte function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticByteMethodV; 214 | jbyte function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticByteMethodA; 215 | jchar function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticCharMethod; 216 | jchar function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticCharMethodV; 217 | jchar function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticCharMethodA; 218 | jshort function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticShortMethod; 219 | jshort function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticShortMethodV; 220 | jshort function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticShortMethodA; 221 | jint function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticIntMethod; 222 | jint function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticIntMethodV; 223 | jint function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticIntMethodA; 224 | jlong function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticLongMethod; 225 | jlong function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticLongMethodV; 226 | jlong function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticLongMethodA; 227 | jfloat function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticFloatMethod; 228 | jfloat function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticFloatMethodV; 229 | jfloat function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticFloatMethodA; 230 | jdouble function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID,...)CallStaticDoubleMethod; 231 | jdouble function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, va_list args)CallStaticDoubleMethodV; 232 | jdouble function(const(JNIEnv_) *env, jclass clazz, jmethodID methodID, const(jvalue) *args)CallStaticDoubleMethodA; 233 | void function(const(JNIEnv_) *env, jclass cls, jmethodID methodID,...)CallStaticVoidMethod; 234 | void function(const(JNIEnv_) *env, jclass cls, jmethodID methodID, va_list args)CallStaticVoidMethodV; 235 | void function(const(JNIEnv_) *env, jclass cls, jmethodID methodID, const(jvalue) *args)CallStaticVoidMethodA; 236 | jfieldID function(const(JNIEnv_) *env, jclass clazz, const(char) *name, const(char) *sig)GetStaticFieldID; 237 | jobject function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticObjectField; 238 | jboolean function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticBooleanField; 239 | jbyte function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticByteField; 240 | jchar function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticCharField; 241 | jshort function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticShortField; 242 | jint function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticIntField; 243 | jlong function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticLongField; 244 | jfloat function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticFloatField; 245 | jdouble function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID)GetStaticDoubleField; 246 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jobject value)SetStaticObjectField; 247 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jboolean value)SetStaticBooleanField; 248 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jbyte value)SetStaticByteField; 249 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jchar value)SetStaticCharField; 250 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jshort value)SetStaticShortField; 251 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jint value)SetStaticIntField; 252 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jlong value)SetStaticLongField; 253 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jfloat value)SetStaticFloatField; 254 | void function(const(JNIEnv_) *env, jclass clazz, jfieldID fieldID, jdouble value)SetStaticDoubleField; 255 | jstring function(const(JNIEnv_) *env, const(jchar) *unicode, jsize len)NewString; 256 | jsize function(const(JNIEnv_) *env, jstring str)GetStringLength; 257 | jchar * function(const(JNIEnv_) *env, jstring str, jboolean *isCopy)GetStringChars; 258 | void function(const(JNIEnv_) *env, jstring str, const(jchar) *chars)ReleaseStringChars; 259 | jstring function(const(JNIEnv_) *env, const(char) *utf)NewStringUTF; 260 | jsize function(const(JNIEnv_) *env, jstring str)GetStringUTFLength; 261 | const(char) * function(const(JNIEnv_) *env, jstring str, jboolean *isCopy)GetStringUTFChars; 262 | void function(const(JNIEnv_) *env, jstring str, const(char) *chars)ReleaseStringUTFChars; 263 | jsize function(const(JNIEnv_) *env, jarray array)GetArrayLength; 264 | jobjectArray function(const(JNIEnv_) *env, jsize len, jclass clazz, jobject init)NewObjectArray; 265 | jobject function(const(JNIEnv_) *env, jobjectArray array, jsize index)GetObjectArrayElement; 266 | void function(const(JNIEnv_) *env, jobjectArray array, jsize index, jobject val)SetObjectArrayElement; 267 | jbooleanArray function(const(JNIEnv_) *env, jsize len)NewBooleanArray; 268 | jbyteArray function(const(JNIEnv_) *env, jsize len)NewByteArray; 269 | jcharArray function(const(JNIEnv_) *env, jsize len)NewCharArray; 270 | jshortArray function(const(JNIEnv_) *env, jsize len)NewShortArray; 271 | jintArray function(const(JNIEnv_) *env, jsize len)NewIntArray; 272 | jlongArray function(const(JNIEnv_) *env, jsize len)NewLongArray; 273 | jfloatArray function(const(JNIEnv_) *env, jsize len)NewFloatArray; 274 | jdoubleArray function(const(JNIEnv_) *env, jsize len)NewDoubleArray; 275 | jboolean * function(const(JNIEnv_) *env, jbooleanArray array, jboolean *isCopy)GetBooleanArrayElements; 276 | jbyte * function(const(JNIEnv_) *env, jbyteArray array, jboolean *isCopy)GetByteArrayElements; 277 | jchar * function(const(JNIEnv_) *env, jcharArray array, jboolean *isCopy)GetCharArrayElements; 278 | jshort * function(const(JNIEnv_) *env, jshortArray array, jboolean *isCopy)GetShortArrayElements; 279 | jint * function(const(JNIEnv_) *env, jintArray array, jboolean *isCopy)GetIntArrayElements; 280 | jlong * function(const(JNIEnv_) *env, jlongArray array, jboolean *isCopy)GetLongArrayElements; 281 | jfloat * function(const(JNIEnv_) *env, jfloatArray array, jboolean *isCopy)GetFloatArrayElements; 282 | jdouble * function(const(JNIEnv_) *env, jdoubleArray array, jboolean *isCopy)GetDoubleArrayElements; 283 | void function(const(JNIEnv_) *env, jbooleanArray array, jboolean *elems, jint mode)ReleaseBooleanArrayElements; 284 | void function(const(JNIEnv_) *env, jbyteArray array, jbyte *elems, jint mode)ReleaseByteArrayElements; 285 | void function(const(JNIEnv_) *env, jcharArray array, jchar *elems, jint mode)ReleaseCharArrayElements; 286 | void function(const(JNIEnv_) *env, jshortArray array, jshort *elems, jint mode)ReleaseShortArrayElements; 287 | void function(const(JNIEnv_) *env, jintArray array, jint *elems, jint mode)ReleaseIntArrayElements; 288 | void function(const(JNIEnv_) *env, jlongArray array, jlong *elems, jint mode)ReleaseLongArrayElements; 289 | void function(const(JNIEnv_) *env, jfloatArray array, jfloat *elems, jint mode)ReleaseFloatArrayElements; 290 | void function(const(JNIEnv_) *env, jdoubleArray array, jdouble *elems, jint mode)ReleaseDoubleArrayElements; 291 | void function(const(JNIEnv_) *env, jbooleanArray array, jsize start, jsize l, jboolean *buf)GetBooleanArrayRegion; 292 | void function(const(JNIEnv_) *env, jbyteArray array, jsize start, jsize len, jbyte *buf)GetByteArrayRegion; 293 | void function(const(JNIEnv_) *env, jcharArray array, jsize start, jsize len, jchar *buf)GetCharArrayRegion; 294 | void function(const(JNIEnv_) *env, jshortArray array, jsize start, jsize len, jshort *buf)GetShortArrayRegion; 295 | void function(const(JNIEnv_) *env, jintArray array, jsize start, jsize len, jint *buf)GetIntArrayRegion; 296 | void function(const(JNIEnv_) *env, jlongArray array, jsize start, jsize len, jlong *buf)GetLongArrayRegion; 297 | void function(const(JNIEnv_) *env, jfloatArray array, jsize start, jsize len, jfloat *buf)GetFloatArrayRegion; 298 | void function(const(JNIEnv_) *env, jdoubleArray array, jsize start, jsize len, jdouble *buf)GetDoubleArrayRegion; 299 | void function(const(JNIEnv_) *env, jbooleanArray array, jsize start, jsize l, const(jboolean) *buf)SetBooleanArrayRegion; 300 | void function(const(JNIEnv_) *env, jbyteArray array, jsize start, jsize len, const(jbyte) *buf)SetByteArrayRegion; 301 | void function(const(JNIEnv_) *env, jcharArray array, jsize start, jsize len, const(jchar) *buf)SetCharArrayRegion; 302 | void function(const(JNIEnv_) *env, jshortArray array, jsize start, jsize len, const(jshort) *buf)SetShortArrayRegion; 303 | void function(const(JNIEnv_) *env, jintArray array, jsize start, jsize len, const(jint) *buf)SetIntArrayRegion; 304 | void function(const(JNIEnv_) *env, jlongArray array, jsize start, jsize len, const(jlong) *buf)SetLongArrayRegion; 305 | void function(const(JNIEnv_) *env, jfloatArray array, jsize start, jsize len, const(jfloat) *buf)SetFloatArrayRegion; 306 | void function(const(JNIEnv_) *env, jdoubleArray array, jsize start, jsize len, const(jdouble) *buf)SetDoubleArrayRegion; 307 | jint function(const(JNIEnv_) *env, jclass clazz, const(JNINativeMethod) *methods, jint nMethods)RegisterNatives; 308 | jint function(const(JNIEnv_) *env, jclass clazz)UnregisterNatives; 309 | jint function(const(JNIEnv_) *env, jobject obj)MonitorEnter; 310 | jint function(const(JNIEnv_) *env, jobject obj)MonitorExit; 311 | jint function(const(JNIEnv_) *env, JavaVM_ **vm)GetJavaVM; 312 | void function(const(JNIEnv_) *env, jstring str, jsize start, jsize len, jchar *buf)GetStringRegion; 313 | void function(const(JNIEnv_) *env, jstring str, jsize start, jsize len, const(char) *buf)GetStringUTFRegion; 314 | void * function(const(JNIEnv_) *env, jarray array, jboolean *isCopy)GetPrimitiveArrayCritical; 315 | void function(const(JNIEnv_) *env, jarray array, void *carray, jint mode)ReleasePrimitiveArrayCritical; 316 | jchar * function(const(JNIEnv_) *env, jstring string, jboolean *isCopy)GetStringCritical; 317 | void function(const(JNIEnv_) *env, jstring string, const(jchar) *cstring)ReleaseStringCritical; 318 | jweak function(const(JNIEnv_) *env, jobject obj)NewWeakGlobalRef; 319 | void function(const(JNIEnv_) *env, jweak _ref)DeleteWeakGlobalRef; 320 | jboolean function(const(JNIEnv_) *env)ExceptionCheck; 321 | jobject function(const(JNIEnv_) *env, void *address, jlong capacity)NewDirectByteBuffer; 322 | void * function(const(JNIEnv_) *env, jobject buf)GetDirectBufferAddress; 323 | jlong function(const(JNIEnv_) *env, jobject buf)GetDirectBufferCapacity; 324 | jobjectRefType function(const(JNIEnv_) *env, jobject obj)GetObjectRefType; 325 | } 326 | 327 | struct JNIEnv_ { 328 | const JNINativeInterface_ *functions; 329 | 330 | jint GetVersion() const { 331 | return functions.GetVersion(&this); 332 | } 333 | jclass DefineClass(const(char) *name, jobject loader, const(jbyte) *buf, 334 | jsize len) const { 335 | return functions.DefineClass(&this, name, loader, buf, len); 336 | } 337 | jclass FindClass(const(char) *name) const { 338 | return functions.FindClass(&this, name); 339 | } 340 | jmethodID FromReflectedMethod(jobject method) const { 341 | return functions.FromReflectedMethod(&this,method); 342 | } 343 | jfieldID FromReflectedField(jobject field) const { 344 | return functions.FromReflectedField(&this,field); 345 | } 346 | 347 | jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic) const { 348 | return functions.ToReflectedMethod(&this, cls, methodID, isStatic); 349 | } 350 | 351 | jclass GetSuperclass(jclass sub) const { 352 | return functions.GetSuperclass(&this, sub); 353 | } 354 | jboolean IsAssignableFrom(jclass sub, jclass sup) const { 355 | return functions.IsAssignableFrom(&this, sub, sup); 356 | } 357 | 358 | jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic) const { 359 | return functions.ToReflectedField(&this,cls,fieldID,isStatic); 360 | } 361 | 362 | jint Throw(jthrowable obj) const { 363 | return functions.Throw(&this, obj); 364 | } 365 | jint ThrowNew(jclass clazz, const(char) *msg) const { 366 | return functions.ThrowNew(&this, clazz, msg); 367 | } 368 | jthrowable ExceptionOccurred() const { 369 | return functions.ExceptionOccurred(&this); 370 | } 371 | void ExceptionDescribe() const { 372 | functions.ExceptionDescribe(&this); 373 | } 374 | void ExceptionClear() const { 375 | functions.ExceptionClear(&this); 376 | } 377 | void FatalError(const(char) *msg) const { 378 | functions.FatalError(&this, msg); 379 | } 380 | 381 | jint PushLocalFrame(jint capacity) const { 382 | return functions.PushLocalFrame(&this,capacity); 383 | } 384 | jobject PopLocalFrame(jobject result) const { 385 | return functions.PopLocalFrame(&this,result); 386 | } 387 | 388 | jobject NewGlobalRef(jobject lobj) const { 389 | return functions.NewGlobalRef(&this,lobj); 390 | } 391 | void DeleteGlobalRef(jobject gref) const { 392 | functions.DeleteGlobalRef(&this,gref); 393 | } 394 | void DeleteLocalRef(jobject obj) const { 395 | functions.DeleteLocalRef(&this, obj); 396 | } 397 | 398 | jboolean IsSameObject(jobject obj1, jobject obj2) const { 399 | return functions.IsSameObject(&this,obj1,obj2); 400 | } 401 | 402 | jobject NewLocalRef(jobject _ref) const { 403 | return functions.NewLocalRef(&this,_ref); 404 | } 405 | jint EnsureLocalCapacity(jint capacity) const { 406 | return functions.EnsureLocalCapacity(&this,capacity); 407 | } 408 | 409 | jobject AllocObject(jclass clazz) const { 410 | return functions.AllocObject(&this,clazz); 411 | } 412 | jobject NewObject(jclass clazz, jmethodID methodID, ...) const { 413 | va_list args; 414 | jobject result; 415 | version(X86_64) { 416 | va_start(args, __va_argsave); 417 | } 418 | else version(X86) { 419 | va_start(args, methodID); 420 | } 421 | else 422 | static assert(false, "Unsupported platform"); 423 | result = functions.NewObjectV(&this,clazz,methodID,args); 424 | va_end(args); 425 | return result; 426 | } 427 | jobject NewObjectV(jclass clazz, jmethodID methodID, 428 | va_list args) const { 429 | return functions.NewObjectV(&this,clazz,methodID,args); 430 | } 431 | jobject NewObjectA(jclass clazz, jmethodID methodID, 432 | const(jvalue) *args) const { 433 | return functions.NewObjectA(&this,clazz,methodID,args); 434 | } 435 | 436 | jclass GetObjectClass(jobject obj) const { 437 | return functions.GetObjectClass(&this,obj); 438 | } 439 | jboolean IsInstanceOf(jobject obj, jclass clazz) const { 440 | return functions.IsInstanceOf(&this,obj,clazz); 441 | } 442 | 443 | jmethodID GetMethodID(jclass clazz, const(char) *name, 444 | const(char) *sig) const { 445 | return functions.GetMethodID(&this,clazz,name,sig); 446 | } 447 | 448 | jobject CallObjectMethod(jobject obj, jmethodID methodID, ...) const { 449 | va_list args; 450 | jobject result; 451 | version(X86_64) { 452 | va_start(args, __va_argsave); 453 | } 454 | else version(X86) { 455 | va_start(args, methodID); 456 | } 457 | else 458 | static assert(false, "Unsupported platform"); 459 | result = functions.CallObjectMethodV(&this,obj,methodID,args); 460 | va_end(args); 461 | return result; 462 | } 463 | jobject CallObjectMethodV(jobject obj, jmethodID methodID, 464 | va_list args) const { 465 | return functions.CallObjectMethodV(&this,obj,methodID,args); 466 | } 467 | jobject CallObjectMethodA(jobject obj, jmethodID methodID, 468 | const(jvalue) * args) const { 469 | return functions.CallObjectMethodA(&this,obj,methodID,args); 470 | } 471 | 472 | jboolean CallBooleanMethod(jobject obj, 473 | jmethodID methodID, ...) const { 474 | va_list args; 475 | jboolean result; 476 | version(X86_64) { 477 | va_start(args, __va_argsave); 478 | } 479 | else version(X86) { 480 | va_start(args, methodID); 481 | } 482 | else 483 | static assert(false, "Unsupported platform"); 484 | result = functions.CallBooleanMethodV(&this,obj,methodID,args); 485 | va_end(args); 486 | return result; 487 | } 488 | jboolean CallBooleanMethodV(jobject obj, jmethodID methodID, 489 | va_list args) const { 490 | return functions.CallBooleanMethodV(&this,obj,methodID,args); 491 | } 492 | jboolean CallBooleanMethodA(jobject obj, jmethodID methodID, 493 | const(jvalue) * args) const { 494 | return functions.CallBooleanMethodA(&this,obj,methodID, args); 495 | } 496 | 497 | jbyte CallByteMethod(jobject obj, jmethodID methodID, ...) const { 498 | va_list args; 499 | jbyte result; 500 | version(X86_64) { 501 | va_start(args, __va_argsave); 502 | } 503 | else version(X86) { 504 | va_start(args, methodID); 505 | } 506 | else 507 | static assert(false, "Unsupported platform"); 508 | result = functions.CallByteMethodV(&this,obj,methodID,args); 509 | va_end(args); 510 | return result; 511 | } 512 | jbyte CallByteMethodV(jobject obj, jmethodID methodID, 513 | va_list args) const { 514 | return functions.CallByteMethodV(&this,obj,methodID,args); 515 | } 516 | jbyte CallByteMethodA(jobject obj, jmethodID methodID, 517 | const(jvalue) * args) const { 518 | return functions.CallByteMethodA(&this,obj,methodID,args); 519 | } 520 | 521 | jchar CallCharMethod(jobject obj, jmethodID methodID, ...) const { 522 | va_list args; 523 | jchar result; 524 | version(X86_64) { 525 | va_start(args, __va_argsave); 526 | } 527 | else version(X86) { 528 | va_start(args, methodID); 529 | } 530 | else 531 | static assert(false, "Unsupported platform"); 532 | result = functions.CallCharMethodV(&this,obj,methodID,args); 533 | va_end(args); 534 | return result; 535 | } 536 | jchar CallCharMethodV(jobject obj, jmethodID methodID, 537 | va_list args) const { 538 | return functions.CallCharMethodV(&this,obj,methodID,args); 539 | } 540 | jchar CallCharMethodA(jobject obj, jmethodID methodID, 541 | const(jvalue) * args) const { 542 | return functions.CallCharMethodA(&this,obj,methodID,args); 543 | } 544 | 545 | jshort CallShortMethod(jobject obj, jmethodID methodID, ...) const { 546 | va_list args; 547 | jshort result; 548 | version(X86_64) { 549 | va_start(args, __va_argsave); 550 | } 551 | else version(X86) { 552 | va_start(args, methodID); 553 | } 554 | else 555 | static assert(false, "Unsupported platform"); 556 | result = functions.CallShortMethodV(&this,obj,methodID,args); 557 | va_end(args); 558 | return result; 559 | } 560 | jshort CallShortMethodV(jobject obj, jmethodID methodID, 561 | va_list args) const { 562 | return functions.CallShortMethodV(&this,obj,methodID,args); 563 | } 564 | jshort CallShortMethodA(jobject obj, jmethodID methodID, 565 | const(jvalue) * args) const { 566 | return functions.CallShortMethodA(&this,obj,methodID,args); 567 | } 568 | 569 | jint CallIntMethod(jobject obj, jmethodID methodID, ...) const { 570 | va_list args; 571 | jint result; 572 | version(X86_64) { 573 | va_start(args, __va_argsave); 574 | } 575 | else version(X86) { 576 | va_start(args, methodID); 577 | } 578 | else 579 | static assert(false, "Unsupported platform"); 580 | result = functions.CallIntMethodV(&this,obj,methodID,args); 581 | va_end(args); 582 | return result; 583 | } 584 | jint CallIntMethodV(jobject obj, jmethodID methodID, 585 | va_list args) const { 586 | return functions.CallIntMethodV(&this,obj,methodID,args); 587 | } 588 | jint CallIntMethodA(jobject obj, jmethodID methodID, 589 | const(jvalue) * args) const { 590 | return functions.CallIntMethodA(&this,obj,methodID,args); 591 | } 592 | 593 | jlong CallLongMethod(jobject obj, jmethodID methodID, ...) const { 594 | va_list args; 595 | jlong result; 596 | version(X86_64) { 597 | va_start(args, __va_argsave); 598 | } 599 | else version(X86) { 600 | va_start(args, methodID); 601 | } 602 | else 603 | static assert(false, "Unsupported platform"); 604 | result = functions.CallLongMethodV(&this,obj,methodID,args); 605 | va_end(args); 606 | return result; 607 | } 608 | jlong CallLongMethodV(jobject obj, jmethodID methodID, 609 | va_list args) const { 610 | return functions.CallLongMethodV(&this,obj,methodID,args); 611 | } 612 | jlong CallLongMethodA(jobject obj, jmethodID methodID, 613 | const(jvalue) * args) const { 614 | return functions.CallLongMethodA(&this,obj,methodID,args); 615 | } 616 | 617 | jfloat CallFloatMethod(jobject obj, jmethodID methodID, ...) const { 618 | va_list args; 619 | jfloat result; 620 | version(X86_64) { 621 | va_start(args, __va_argsave); 622 | } 623 | else version(X86) { 624 | va_start(args, methodID); 625 | } 626 | else 627 | static assert(false, "Unsupported platform"); 628 | result = functions.CallFloatMethodV(&this,obj,methodID,args); 629 | va_end(args); 630 | return result; 631 | } 632 | jfloat CallFloatMethodV(jobject obj, jmethodID methodID, 633 | va_list args) const { 634 | return functions.CallFloatMethodV(&this,obj,methodID,args); 635 | } 636 | jfloat CallFloatMethodA(jobject obj, jmethodID methodID, 637 | const(jvalue) * args) const { 638 | return functions.CallFloatMethodA(&this,obj,methodID,args); 639 | } 640 | 641 | jdouble CallDoubleMethod(jobject obj, jmethodID methodID, ...) const { 642 | va_list args; 643 | jdouble result; 644 | version(X86_64) { 645 | va_start(args, __va_argsave); 646 | } 647 | else version(X86) { 648 | va_start(args, methodID); 649 | } 650 | else 651 | static assert(false, "Unsupported platform"); 652 | result = functions.CallDoubleMethodV(&this,obj,methodID,args); 653 | va_end(args); 654 | return result; 655 | } 656 | jdouble CallDoubleMethodV(jobject obj, jmethodID methodID, 657 | va_list args) const { 658 | return functions.CallDoubleMethodV(&this,obj,methodID,args); 659 | } 660 | jdouble CallDoubleMethodA(jobject obj, jmethodID methodID, 661 | const(jvalue) * args) const { 662 | return functions.CallDoubleMethodA(&this,obj,methodID,args); 663 | } 664 | 665 | void CallVoidMethod(jobject obj, jmethodID methodID, ...) const { 666 | va_list args; 667 | version(X86_64) { 668 | va_start(args, __va_argsave); 669 | } 670 | else version(X86) { 671 | va_start(args, methodID); 672 | } 673 | else 674 | static assert(false, "Unsupported platform"); 675 | functions.CallVoidMethodV(&this,obj,methodID,args); 676 | va_end(args); 677 | } 678 | void CallVoidMethodV(jobject obj, jmethodID methodID, 679 | va_list args) const { 680 | functions.CallVoidMethodV(&this,obj,methodID,args); 681 | } 682 | void CallVoidMethodA(jobject obj, jmethodID methodID, 683 | const(jvalue) * args) const { 684 | functions.CallVoidMethodA(&this,obj,methodID,args); 685 | } 686 | 687 | jobject CallNonvirtualObjectMethod(jobject obj, jclass clazz, 688 | jmethodID methodID, ...) const { 689 | va_list args; 690 | jobject result; 691 | version(X86_64) { 692 | va_start(args, __va_argsave); 693 | } 694 | else version(X86) { 695 | va_start(args, methodID); 696 | } 697 | else 698 | static assert(false, "Unsupported platform"); 699 | result = functions.CallNonvirtualObjectMethodV(&this,obj,clazz, 700 | methodID,args); 701 | va_end(args); 702 | return result; 703 | } 704 | jobject CallNonvirtualObjectMethodV(jobject obj, jclass clazz, 705 | jmethodID methodID, va_list args) const { 706 | return functions.CallNonvirtualObjectMethodV(&this,obj,clazz, 707 | methodID,args); 708 | } 709 | jobject CallNonvirtualObjectMethodA(jobject obj, jclass clazz, 710 | jmethodID methodID, const(jvalue) * args) const { 711 | return functions.CallNonvirtualObjectMethodA(&this,obj,clazz, 712 | methodID,args); 713 | } 714 | 715 | jboolean CallNonvirtualBooleanMethod(jobject obj, jclass clazz, 716 | jmethodID methodID, ...) const { 717 | va_list args; 718 | jboolean result; 719 | version(X86_64) { 720 | va_start(args, __va_argsave); 721 | } 722 | else version(X86) { 723 | va_start(args, methodID); 724 | } 725 | else 726 | static assert(false, "Unsupported platform"); 727 | result = functions.CallNonvirtualBooleanMethodV(&this,obj,clazz, 728 | methodID,args); 729 | va_end(args); 730 | return result; 731 | } 732 | jboolean CallNonvirtualBooleanMethodV(jobject obj, jclass clazz, 733 | jmethodID methodID, va_list args) const { 734 | return functions.CallNonvirtualBooleanMethodV(&this,obj,clazz, 735 | methodID,args); 736 | } 737 | jboolean CallNonvirtualBooleanMethodA(jobject obj, jclass clazz, 738 | jmethodID methodID, const(jvalue) * args) const { 739 | return functions.CallNonvirtualBooleanMethodA(&this,obj,clazz, 740 | methodID, args); 741 | } 742 | 743 | jbyte CallNonvirtualByteMethod(jobject obj, jclass clazz, 744 | jmethodID methodID, ...) const { 745 | va_list args; 746 | jbyte result; 747 | version(X86_64) { 748 | va_start(args, __va_argsave); 749 | } 750 | else version(X86) { 751 | va_start(args, methodID); 752 | } 753 | else 754 | static assert(false, "Unsupported platform"); 755 | result = functions.CallNonvirtualByteMethodV(&this,obj,clazz, 756 | methodID,args); 757 | va_end(args); 758 | return result; 759 | } 760 | jbyte CallNonvirtualByteMethodV(jobject obj, jclass clazz, 761 | jmethodID methodID, va_list args) const { 762 | return functions.CallNonvirtualByteMethodV(&this,obj,clazz, 763 | methodID,args); 764 | } 765 | jbyte CallNonvirtualByteMethodA(jobject obj, jclass clazz, 766 | jmethodID methodID, const(jvalue) * args) const { 767 | return functions.CallNonvirtualByteMethodA(&this,obj,clazz, 768 | methodID,args); 769 | } 770 | 771 | jchar CallNonvirtualCharMethod(jobject obj, jclass clazz, 772 | jmethodID methodID, ...) const { 773 | va_list args; 774 | jchar result; 775 | version(X86_64) { 776 | va_start(args, __va_argsave); 777 | } 778 | else version(X86) { 779 | va_start(args, methodID); 780 | } 781 | else 782 | static assert(false, "Unsupported platform"); 783 | result = functions.CallNonvirtualCharMethodV(&this,obj,clazz, 784 | methodID,args); 785 | va_end(args); 786 | return result; 787 | } 788 | jchar CallNonvirtualCharMethodV(jobject obj, jclass clazz, 789 | jmethodID methodID, va_list args) const { 790 | return functions.CallNonvirtualCharMethodV(&this,obj,clazz, 791 | methodID,args); 792 | } 793 | jchar CallNonvirtualCharMethodA(jobject obj, jclass clazz, 794 | jmethodID methodID, const(jvalue) * args) const { 795 | return functions.CallNonvirtualCharMethodA(&this,obj,clazz, 796 | methodID,args); 797 | } 798 | 799 | jshort CallNonvirtualShortMethod(jobject obj, jclass clazz, 800 | jmethodID methodID, ...) const { 801 | va_list args; 802 | jshort result; 803 | version(X86_64) { 804 | va_start(args, __va_argsave); 805 | } 806 | else version(X86) { 807 | va_start(args, methodID); 808 | } 809 | else 810 | static assert(false, "Unsupported platform"); 811 | result = functions.CallNonvirtualShortMethodV(&this,obj,clazz, 812 | methodID,args); 813 | va_end(args); 814 | return result; 815 | } 816 | jshort CallNonvirtualShortMethodV(jobject obj, jclass clazz, 817 | jmethodID methodID, va_list args) const { 818 | return functions.CallNonvirtualShortMethodV(&this,obj,clazz, 819 | methodID,args); 820 | } 821 | jshort CallNonvirtualShortMethodA(jobject obj, jclass clazz, 822 | jmethodID methodID, const(jvalue) * args) const { 823 | return functions.CallNonvirtualShortMethodA(&this,obj,clazz, 824 | methodID,args); 825 | } 826 | 827 | jint CallNonvirtualIntMethod(jobject obj, jclass clazz, 828 | jmethodID methodID, ...) const { 829 | va_list args; 830 | jint result; 831 | version(X86_64) { 832 | va_start(args, __va_argsave); 833 | } 834 | else version(X86) { 835 | va_start(args, methodID); 836 | } 837 | else 838 | static assert(false, "Unsupported platform"); 839 | result = functions.CallNonvirtualIntMethodV(&this,obj,clazz, 840 | methodID,args); 841 | va_end(args); 842 | return result; 843 | } 844 | jint CallNonvirtualIntMethodV(jobject obj, jclass clazz, 845 | jmethodID methodID, va_list args) const { 846 | return functions.CallNonvirtualIntMethodV(&this,obj,clazz, 847 | methodID,args); 848 | } 849 | jint CallNonvirtualIntMethodA(jobject obj, jclass clazz, 850 | jmethodID methodID, const(jvalue) * args) const { 851 | return functions.CallNonvirtualIntMethodA(&this,obj,clazz, 852 | methodID,args); 853 | } 854 | 855 | jlong CallNonvirtualLongMethod(jobject obj, jclass clazz, 856 | jmethodID methodID, ...) const { 857 | va_list args; 858 | jlong result; 859 | version(X86_64) { 860 | va_start(args, __va_argsave); 861 | } 862 | else version(X86) { 863 | va_start(args, methodID); 864 | } 865 | else 866 | static assert(false, "Unsupported platform"); 867 | result = functions.CallNonvirtualLongMethodV(&this,obj,clazz, 868 | methodID,args); 869 | va_end(args); 870 | return result; 871 | } 872 | jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz, 873 | jmethodID methodID, va_list args) const { 874 | return functions.CallNonvirtualLongMethodV(&this,obj,clazz, 875 | methodID,args); 876 | } 877 | jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz, 878 | jmethodID methodID, const(jvalue) * args) const { 879 | return functions.CallNonvirtualLongMethodA(&this,obj,clazz, 880 | methodID,args); 881 | } 882 | 883 | jfloat CallNonvirtualFloatMethod(jobject obj, jclass clazz, 884 | jmethodID methodID, ...) const { 885 | va_list args; 886 | jfloat result; 887 | version(X86_64) { 888 | va_start(args, __va_argsave); 889 | } 890 | else version(X86) { 891 | va_start(args, methodID); 892 | } 893 | else 894 | static assert(false, "Unsupported platform"); 895 | result = functions.CallNonvirtualFloatMethodV(&this,obj,clazz, 896 | methodID,args); 897 | va_end(args); 898 | return result; 899 | } 900 | jfloat CallNonvirtualFloatMethodV(jobject obj, jclass clazz, 901 | jmethodID methodID, 902 | va_list args) const { 903 | return functions.CallNonvirtualFloatMethodV(&this,obj,clazz, 904 | methodID,args); 905 | } 906 | jfloat CallNonvirtualFloatMethodA(jobject obj, jclass clazz, 907 | jmethodID methodID, 908 | const(jvalue) * args) const { 909 | return functions.CallNonvirtualFloatMethodA(&this,obj,clazz, 910 | methodID,args); 911 | } 912 | 913 | jdouble CallNonvirtualDoubleMethod(jobject obj, jclass clazz, 914 | jmethodID methodID, ...) const { 915 | va_list args; 916 | jdouble result; 917 | version(X86_64) { 918 | va_start(args, __va_argsave); 919 | } 920 | else version(X86) { 921 | va_start(args, methodID); 922 | } 923 | else 924 | static assert(false, "Unsupported platform"); 925 | result = functions.CallNonvirtualDoubleMethodV(&this,obj,clazz, 926 | methodID,args); 927 | va_end(args); 928 | return result; 929 | } 930 | jdouble CallNonvirtualDoubleMethodV(jobject obj, jclass clazz, 931 | jmethodID methodID, 932 | va_list args) const { 933 | return functions.CallNonvirtualDoubleMethodV(&this,obj,clazz, 934 | methodID,args); 935 | } 936 | jdouble CallNonvirtualDoubleMethodA(jobject obj, jclass clazz, 937 | jmethodID methodID, 938 | const(jvalue) * args) const { 939 | return functions.CallNonvirtualDoubleMethodA(&this,obj,clazz, 940 | methodID,args); 941 | } 942 | 943 | void CallNonvirtualVoidMethod(jobject obj, jclass clazz, 944 | jmethodID methodID, ...) const { 945 | va_list args; 946 | version(X86_64) { 947 | va_start(args, __va_argsave); 948 | } 949 | else version(X86) { 950 | va_start(args, methodID); 951 | } 952 | else 953 | static assert(false, "Unsupported platform"); 954 | functions.CallNonvirtualVoidMethodV(&this,obj,clazz,methodID,args); 955 | va_end(args); 956 | } 957 | void CallNonvirtualVoidMethodV(jobject obj, jclass clazz, 958 | jmethodID methodID, 959 | va_list args) const { 960 | functions.CallNonvirtualVoidMethodV(&this,obj,clazz,methodID,args); 961 | } 962 | void CallNonvirtualVoidMethodA(jobject obj, jclass clazz, 963 | jmethodID methodID, 964 | const(jvalue) * args) const { 965 | functions.CallNonvirtualVoidMethodA(&this,obj,clazz,methodID,args); 966 | } 967 | 968 | jfieldID GetFieldID(jclass clazz, const(char) *name, 969 | const(char) *sig) const { 970 | return functions.GetFieldID(&this,clazz,name,sig); 971 | } 972 | 973 | jobject GetObjectField(jobject obj, jfieldID fieldID) const { 974 | return functions.GetObjectField(&this,obj,fieldID); 975 | } 976 | jboolean GetBooleanField(jobject obj, jfieldID fieldID) const { 977 | return functions.GetBooleanField(&this,obj,fieldID); 978 | } 979 | jbyte GetByteField(jobject obj, jfieldID fieldID) const { 980 | return functions.GetByteField(&this,obj,fieldID); 981 | } 982 | jchar GetCharField(jobject obj, jfieldID fieldID) const { 983 | return functions.GetCharField(&this,obj,fieldID); 984 | } 985 | jshort GetShortField(jobject obj, jfieldID fieldID) const { 986 | return functions.GetShortField(&this,obj,fieldID); 987 | } 988 | jint GetIntField(jobject obj, jfieldID fieldID) const { 989 | return functions.GetIntField(&this,obj,fieldID); 990 | } 991 | jlong GetLongField(jobject obj, jfieldID fieldID) const { 992 | return functions.GetLongField(&this,obj,fieldID); 993 | } 994 | jfloat GetFloatField(jobject obj, jfieldID fieldID) const { 995 | return functions.GetFloatField(&this,obj,fieldID); 996 | } 997 | jdouble GetDoubleField(jobject obj, jfieldID fieldID) const { 998 | return functions.GetDoubleField(&this,obj,fieldID); 999 | } 1000 | 1001 | void SetObjectField(jobject obj, jfieldID fieldID, jobject val) const { 1002 | functions.SetObjectField(&this,obj,fieldID,val); 1003 | } 1004 | void SetBooleanField(jobject obj, jfieldID fieldID, 1005 | jboolean val) const { 1006 | functions.SetBooleanField(&this,obj,fieldID,val); 1007 | } 1008 | void SetByteField(jobject obj, jfieldID fieldID, 1009 | jbyte val) const { 1010 | functions.SetByteField(&this,obj,fieldID,val); 1011 | } 1012 | void SetCharField(jobject obj, jfieldID fieldID, 1013 | jchar val) const { 1014 | functions.SetCharField(&this,obj,fieldID,val); 1015 | } 1016 | void SetShortField(jobject obj, jfieldID fieldID, 1017 | jshort val) const { 1018 | functions.SetShortField(&this,obj,fieldID,val); 1019 | } 1020 | void SetIntField(jobject obj, jfieldID fieldID, 1021 | jint val) const { 1022 | functions.SetIntField(&this,obj,fieldID,val); 1023 | } 1024 | void SetLongField(jobject obj, jfieldID fieldID, 1025 | jlong val) const { 1026 | functions.SetLongField(&this,obj,fieldID,val); 1027 | } 1028 | void SetFloatField(jobject obj, jfieldID fieldID, 1029 | jfloat val) const { 1030 | functions.SetFloatField(&this,obj,fieldID,val); 1031 | } 1032 | void SetDoubleField(jobject obj, jfieldID fieldID, 1033 | jdouble val) const { 1034 | functions.SetDoubleField(&this,obj,fieldID,val); 1035 | } 1036 | 1037 | jmethodID GetStaticMethodID(jclass clazz, const(char) *name, 1038 | const(char) *sig) const { 1039 | return functions.GetStaticMethodID(&this,clazz,name,sig); 1040 | } 1041 | 1042 | jobject CallStaticObjectMethod(jclass clazz, jmethodID methodID, 1043 | ...) const { 1044 | va_list args; 1045 | jobject result; 1046 | version(X86_64) { 1047 | va_start(args, __va_argsave); 1048 | } 1049 | else version(X86) { 1050 | va_start(args, methodID); 1051 | } 1052 | else 1053 | static assert(false, "Unsupported platform"); 1054 | result = functions.CallStaticObjectMethodV(&this,clazz,methodID,args); 1055 | va_end(args); 1056 | return result; 1057 | } 1058 | jobject CallStaticObjectMethodV(jclass clazz, jmethodID methodID, 1059 | va_list args) const { 1060 | return functions.CallStaticObjectMethodV(&this,clazz,methodID,args); 1061 | } 1062 | jobject CallStaticObjectMethodA(jclass clazz, jmethodID methodID, 1063 | const(jvalue) *args) const { 1064 | return functions.CallStaticObjectMethodA(&this,clazz,methodID,args); 1065 | } 1066 | 1067 | jboolean CallStaticBooleanMethod(jclass clazz, 1068 | jmethodID methodID, ...) const { 1069 | va_list args; 1070 | jboolean result; 1071 | version(X86_64) { 1072 | va_start(args, __va_argsave); 1073 | } 1074 | else version(X86) { 1075 | va_start(args, methodID); 1076 | } 1077 | else 1078 | static assert(false, "Unsupported platform"); 1079 | result = functions.CallStaticBooleanMethodV(&this,clazz,methodID,args); 1080 | va_end(args); 1081 | return result; 1082 | } 1083 | jboolean CallStaticBooleanMethodV(jclass clazz, 1084 | jmethodID methodID, va_list args) const { 1085 | return functions.CallStaticBooleanMethodV(&this,clazz,methodID,args); 1086 | } 1087 | jboolean CallStaticBooleanMethodA(jclass clazz, 1088 | jmethodID methodID, const(jvalue) *args) const { 1089 | return functions.CallStaticBooleanMethodA(&this,clazz,methodID,args); 1090 | } 1091 | 1092 | jbyte CallStaticByteMethod(jclass clazz, 1093 | jmethodID methodID, ...) const { 1094 | va_list args; 1095 | jbyte result; 1096 | version(X86_64) { 1097 | va_start(args, __va_argsave); 1098 | } 1099 | else version(X86) { 1100 | va_start(args, methodID); 1101 | } 1102 | else 1103 | static assert(false, "Unsupported platform"); 1104 | result = functions.CallStaticByteMethodV(&this,clazz,methodID,args); 1105 | va_end(args); 1106 | return result; 1107 | } 1108 | jbyte CallStaticByteMethodV(jclass clazz, 1109 | jmethodID methodID, va_list args) const { 1110 | return functions.CallStaticByteMethodV(&this,clazz,methodID,args); 1111 | } 1112 | jbyte CallStaticByteMethodA(jclass clazz, 1113 | jmethodID methodID, const(jvalue) *args) const { 1114 | return functions.CallStaticByteMethodA(&this,clazz,methodID,args); 1115 | } 1116 | 1117 | jchar CallStaticCharMethod(jclass clazz, 1118 | jmethodID methodID, ...) const { 1119 | va_list args; 1120 | jchar result; 1121 | version(X86_64) { 1122 | va_start(args, __va_argsave); 1123 | } 1124 | else version(X86) { 1125 | va_start(args, methodID); 1126 | } 1127 | else 1128 | static assert(false, "Unsupported platform"); 1129 | result = functions.CallStaticCharMethodV(&this,clazz,methodID,args); 1130 | va_end(args); 1131 | return result; 1132 | } 1133 | jchar CallStaticCharMethodV(jclass clazz, 1134 | jmethodID methodID, va_list args) const { 1135 | return functions.CallStaticCharMethodV(&this,clazz,methodID,args); 1136 | } 1137 | jchar CallStaticCharMethodA(jclass clazz, 1138 | jmethodID methodID, const(jvalue) *args) const { 1139 | return functions.CallStaticCharMethodA(&this,clazz,methodID,args); 1140 | } 1141 | 1142 | jshort CallStaticShortMethod(jclass clazz, 1143 | jmethodID methodID, ...) const { 1144 | va_list args; 1145 | jshort result; 1146 | version(X86_64) { 1147 | va_start(args, __va_argsave); 1148 | } 1149 | else version(X86) { 1150 | va_start(args, methodID); 1151 | } 1152 | else 1153 | static assert(false, "Unsupported platform"); 1154 | result = functions.CallStaticShortMethodV(&this,clazz,methodID,args); 1155 | va_end(args); 1156 | return result; 1157 | } 1158 | jshort CallStaticShortMethodV(jclass clazz, 1159 | jmethodID methodID, va_list args) const { 1160 | return functions.CallStaticShortMethodV(&this,clazz,methodID,args); 1161 | } 1162 | jshort CallStaticShortMethodA(jclass clazz, 1163 | jmethodID methodID, const(jvalue) *args) const { 1164 | return functions.CallStaticShortMethodA(&this,clazz,methodID,args); 1165 | } 1166 | 1167 | jint CallStaticIntMethod(jclass clazz, 1168 | jmethodID methodID, ...) const { 1169 | va_list args; 1170 | jint result; 1171 | version(X86_64) { 1172 | va_start(args, __va_argsave); 1173 | } 1174 | else version(X86) { 1175 | va_start(args, methodID); 1176 | } 1177 | else 1178 | static assert(false, "Unsupported platform"); 1179 | result = functions.CallStaticIntMethodV(&this,clazz,methodID,args); 1180 | va_end(args); 1181 | return result; 1182 | } 1183 | jint CallStaticIntMethodV(jclass clazz, 1184 | jmethodID methodID, va_list args) const { 1185 | return functions.CallStaticIntMethodV(&this,clazz,methodID,args); 1186 | } 1187 | jint CallStaticIntMethodA(jclass clazz, 1188 | jmethodID methodID, const(jvalue) *args) const { 1189 | return functions.CallStaticIntMethodA(&this,clazz,methodID,args); 1190 | } 1191 | 1192 | jlong CallStaticLongMethod(jclass clazz, 1193 | jmethodID methodID, ...) const { 1194 | va_list args; 1195 | jlong result; 1196 | version(X86_64) { 1197 | va_start(args, __va_argsave); 1198 | } 1199 | else version(X86) { 1200 | va_start(args, methodID); 1201 | } 1202 | else 1203 | static assert(false, "Unsupported platform"); 1204 | result = functions.CallStaticLongMethodV(&this,clazz,methodID,args); 1205 | va_end(args); 1206 | return result; 1207 | } 1208 | jlong CallStaticLongMethodV(jclass clazz, 1209 | jmethodID methodID, va_list args) const { 1210 | return functions.CallStaticLongMethodV(&this,clazz,methodID,args); 1211 | } 1212 | jlong CallStaticLongMethodA(jclass clazz, 1213 | jmethodID methodID, const(jvalue) *args) const { 1214 | return functions.CallStaticLongMethodA(&this,clazz,methodID,args); 1215 | } 1216 | 1217 | jfloat CallStaticFloatMethod(jclass clazz, 1218 | jmethodID methodID, ...) const { 1219 | va_list args; 1220 | jfloat result; 1221 | version(X86_64) { 1222 | va_start(args, __va_argsave); 1223 | } 1224 | else version(X86) { 1225 | va_start(args, methodID); 1226 | } 1227 | else 1228 | static assert(false, "Unsupported platform"); 1229 | result = functions.CallStaticFloatMethodV(&this,clazz,methodID,args); 1230 | va_end(args); 1231 | return result; 1232 | } 1233 | jfloat CallStaticFloatMethodV(jclass clazz, 1234 | jmethodID methodID, va_list args) const { 1235 | return functions.CallStaticFloatMethodV(&this,clazz,methodID,args); 1236 | } 1237 | jfloat CallStaticFloatMethodA(jclass clazz, 1238 | jmethodID methodID, const(jvalue) *args) const { 1239 | return functions.CallStaticFloatMethodA(&this,clazz,methodID,args); 1240 | } 1241 | 1242 | jdouble CallStaticDoubleMethod(jclass clazz, 1243 | jmethodID methodID, ...) const { 1244 | va_list args; 1245 | jdouble result; 1246 | version(X86_64) { 1247 | va_start(args, __va_argsave); 1248 | } 1249 | else version(X86) { 1250 | va_start(args, methodID); 1251 | } 1252 | else 1253 | static assert(false, "Unsupported platform"); 1254 | result = functions.CallStaticDoubleMethodV(&this,clazz,methodID,args); 1255 | va_end(args); 1256 | return result; 1257 | } 1258 | jdouble CallStaticDoubleMethodV(jclass clazz, 1259 | jmethodID methodID, va_list args) const { 1260 | return functions.CallStaticDoubleMethodV(&this,clazz,methodID,args); 1261 | } 1262 | jdouble CallStaticDoubleMethodA(jclass clazz, 1263 | jmethodID methodID, const(jvalue) *args) const { 1264 | return functions.CallStaticDoubleMethodA(&this,clazz,methodID,args); 1265 | } 1266 | 1267 | void CallStaticVoidMethod(jclass cls, jmethodID methodID, ...) const { 1268 | va_list args; 1269 | version(X86_64) { 1270 | va_start(args, __va_argsave); 1271 | } 1272 | else version(X86) { 1273 | va_start(args, methodID); 1274 | } 1275 | else 1276 | static assert(false, "Unsupported platform"); 1277 | functions.CallStaticVoidMethodV(&this,cls,methodID,args); 1278 | va_end(args); 1279 | } 1280 | void CallStaticVoidMethodV(jclass cls, jmethodID methodID, 1281 | va_list args) const { 1282 | functions.CallStaticVoidMethodV(&this,cls,methodID,args); 1283 | } 1284 | void CallStaticVoidMethodA(jclass cls, jmethodID methodID, 1285 | const(jvalue) * args) const { 1286 | functions.CallStaticVoidMethodA(&this,cls,methodID,args); 1287 | } 1288 | 1289 | jfieldID GetStaticFieldID(jclass clazz, const(char) *name, 1290 | const(char) *sig) const { 1291 | return functions.GetStaticFieldID(&this,clazz,name,sig); 1292 | } 1293 | jobject GetStaticObjectField(jclass clazz, jfieldID fieldID) const { 1294 | return functions.GetStaticObjectField(&this,clazz,fieldID); 1295 | } 1296 | jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID) const { 1297 | return functions.GetStaticBooleanField(&this,clazz,fieldID); 1298 | } 1299 | jbyte GetStaticByteField(jclass clazz, jfieldID fieldID) const { 1300 | return functions.GetStaticByteField(&this,clazz,fieldID); 1301 | } 1302 | jchar GetStaticCharField(jclass clazz, jfieldID fieldID) const { 1303 | return functions.GetStaticCharField(&this,clazz,fieldID); 1304 | } 1305 | jshort GetStaticShortField(jclass clazz, jfieldID fieldID) const { 1306 | return functions.GetStaticShortField(&this,clazz,fieldID); 1307 | } 1308 | jint GetStaticIntField(jclass clazz, jfieldID fieldID) const { 1309 | return functions.GetStaticIntField(&this,clazz,fieldID); 1310 | } 1311 | jlong GetStaticLongField(jclass clazz, jfieldID fieldID) const { 1312 | return functions.GetStaticLongField(&this,clazz,fieldID); 1313 | } 1314 | jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID) const { 1315 | return functions.GetStaticFloatField(&this,clazz,fieldID); 1316 | } 1317 | jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID) const { 1318 | return functions.GetStaticDoubleField(&this,clazz,fieldID); 1319 | } 1320 | 1321 | void SetStaticObjectField(jclass clazz, jfieldID fieldID, 1322 | jobject value) const { 1323 | functions.SetStaticObjectField(&this,clazz,fieldID,value); 1324 | } 1325 | void SetStaticBooleanField(jclass clazz, jfieldID fieldID, 1326 | jboolean value) const { 1327 | functions.SetStaticBooleanField(&this,clazz,fieldID,value); 1328 | } 1329 | void SetStaticByteField(jclass clazz, jfieldID fieldID, 1330 | jbyte value) const { 1331 | functions.SetStaticByteField(&this,clazz,fieldID,value); 1332 | } 1333 | void SetStaticCharField(jclass clazz, jfieldID fieldID, 1334 | jchar value) const { 1335 | functions.SetStaticCharField(&this,clazz,fieldID,value); 1336 | } 1337 | void SetStaticShortField(jclass clazz, jfieldID fieldID, 1338 | jshort value) const { 1339 | functions.SetStaticShortField(&this,clazz,fieldID,value); 1340 | } 1341 | void SetStaticIntField(jclass clazz, jfieldID fieldID, 1342 | jint value) const { 1343 | functions.SetStaticIntField(&this,clazz,fieldID,value); 1344 | } 1345 | void SetStaticLongField(jclass clazz, jfieldID fieldID, 1346 | jlong value) const { 1347 | functions.SetStaticLongField(&this,clazz,fieldID,value); 1348 | } 1349 | void SetStaticFloatField(jclass clazz, jfieldID fieldID, 1350 | jfloat value) const { 1351 | functions.SetStaticFloatField(&this,clazz,fieldID,value); 1352 | } 1353 | void SetStaticDoubleField(jclass clazz, jfieldID fieldID, 1354 | jdouble value) const { 1355 | functions.SetStaticDoubleField(&this,clazz,fieldID,value); 1356 | } 1357 | 1358 | jstring NewString(const(jchar) *unicode, jsize len) const { 1359 | return functions.NewString(&this,unicode,len); 1360 | } 1361 | jsize GetStringLength(jstring str) const { 1362 | return functions.GetStringLength(&this,str); 1363 | } 1364 | const(jchar) *GetStringChars(jstring str, jboolean *isCopy) const { 1365 | return functions.GetStringChars(&this,str,isCopy); 1366 | } 1367 | void ReleaseStringChars(jstring str, const(jchar) *chars) const { 1368 | functions.ReleaseStringChars(&this,str,chars); 1369 | } 1370 | 1371 | jstring NewStringUTF(const(char) *utf) const { 1372 | return functions.NewStringUTF(&this,utf); 1373 | } 1374 | jsize GetStringUTFLength(jstring str) const { 1375 | return functions.GetStringUTFLength(&this,str); 1376 | } 1377 | const(char)* GetStringUTFChars(jstring str, jboolean *isCopy) const { 1378 | return functions.GetStringUTFChars(&this,str,isCopy); 1379 | } 1380 | void ReleaseStringUTFChars(jstring str, const(char)* chars) const { 1381 | functions.ReleaseStringUTFChars(&this,str,chars); 1382 | } 1383 | 1384 | jsize GetArrayLength(jarray array) const { 1385 | return functions.GetArrayLength(&this,array); 1386 | } 1387 | 1388 | jobjectArray NewObjectArray(jsize len, jclass clazz, 1389 | jobject init) const { 1390 | return functions.NewObjectArray(&this,len,clazz,init); 1391 | } 1392 | jobject GetObjectArrayElement(jobjectArray array, jsize index) const { 1393 | return functions.GetObjectArrayElement(&this,array,index); 1394 | } 1395 | void SetObjectArrayElement(jobjectArray array, jsize index, 1396 | jobject val) const { 1397 | functions.SetObjectArrayElement(&this,array,index,val); 1398 | } 1399 | 1400 | jbooleanArray NewBooleanArray(jsize len) const { 1401 | return functions.NewBooleanArray(&this,len); 1402 | } 1403 | jbyteArray NewByteArray(jsize len) const { 1404 | return functions.NewByteArray(&this,len); 1405 | } 1406 | jcharArray NewCharArray(jsize len) const { 1407 | return functions.NewCharArray(&this,len); 1408 | } 1409 | jshortArray NewShortArray(jsize len) const { 1410 | return functions.NewShortArray(&this,len); 1411 | } 1412 | jintArray NewIntArray(jsize len) const { 1413 | return functions.NewIntArray(&this,len); 1414 | } 1415 | jlongArray NewLongArray(jsize len) const { 1416 | return functions.NewLongArray(&this,len); 1417 | } 1418 | jfloatArray NewFloatArray(jsize len) const { 1419 | return functions.NewFloatArray(&this,len); 1420 | } 1421 | jdoubleArray NewDoubleArray(jsize len) const { 1422 | return functions.NewDoubleArray(&this,len); 1423 | } 1424 | 1425 | jboolean * GetBooleanArrayElements(jbooleanArray array, jboolean *isCopy) const { 1426 | return functions.GetBooleanArrayElements(&this,array,isCopy); 1427 | } 1428 | jbyte * GetByteArrayElements(jbyteArray array, jboolean *isCopy) const { 1429 | return functions.GetByteArrayElements(&this,array,isCopy); 1430 | } 1431 | jchar * GetCharArrayElements(jcharArray array, jboolean *isCopy) const { 1432 | return functions.GetCharArrayElements(&this,array,isCopy); 1433 | } 1434 | jshort * GetShortArrayElements(jshortArray array, jboolean *isCopy) const { 1435 | return functions.GetShortArrayElements(&this,array,isCopy); 1436 | } 1437 | jint * GetIntArrayElements(jintArray array, jboolean *isCopy) const { 1438 | return functions.GetIntArrayElements(&this,array,isCopy); 1439 | } 1440 | jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) const { 1441 | return functions.GetLongArrayElements(&this,array,isCopy); 1442 | } 1443 | jfloat * GetFloatArrayElements(jfloatArray array, jboolean *isCopy) const { 1444 | return functions.GetFloatArrayElements(&this,array,isCopy); 1445 | } 1446 | jdouble * GetDoubleArrayElements(jdoubleArray array, jboolean *isCopy) const { 1447 | return functions.GetDoubleArrayElements(&this,array,isCopy); 1448 | } 1449 | 1450 | void ReleaseBooleanArrayElements(jbooleanArray array, 1451 | jboolean *elems, 1452 | jint mode) const { 1453 | functions.ReleaseBooleanArrayElements(&this,array,elems,mode); 1454 | } 1455 | void ReleaseByteArrayElements(jbyteArray array, 1456 | jbyte *elems, 1457 | jint mode) const { 1458 | functions.ReleaseByteArrayElements(&this,array,elems,mode); 1459 | } 1460 | void ReleaseCharArrayElements(jcharArray array, 1461 | jchar *elems, 1462 | jint mode) const { 1463 | functions.ReleaseCharArrayElements(&this,array,elems,mode); 1464 | } 1465 | void ReleaseShortArrayElements(jshortArray array, 1466 | jshort *elems, 1467 | jint mode) const { 1468 | functions.ReleaseShortArrayElements(&this,array,elems,mode); 1469 | } 1470 | void ReleaseIntArrayElements(jintArray array, 1471 | jint *elems, 1472 | jint mode) const { 1473 | functions.ReleaseIntArrayElements(&this,array,elems,mode); 1474 | } 1475 | void ReleaseLongArrayElements(jlongArray array, 1476 | jlong *elems, 1477 | jint mode) const { 1478 | functions.ReleaseLongArrayElements(&this,array,elems,mode); 1479 | } 1480 | void ReleaseFloatArrayElements(jfloatArray array, 1481 | jfloat *elems, 1482 | jint mode) const { 1483 | functions.ReleaseFloatArrayElements(&this,array,elems,mode); 1484 | } 1485 | void ReleaseDoubleArrayElements(jdoubleArray array, 1486 | jdouble *elems, 1487 | jint mode) const { 1488 | functions.ReleaseDoubleArrayElements(&this,array,elems,mode); 1489 | } 1490 | 1491 | void GetBooleanArrayRegion(jbooleanArray array, 1492 | jsize start, jsize len, jboolean *buf) const { 1493 | functions.GetBooleanArrayRegion(&this,array,start,len,buf); 1494 | } 1495 | void GetByteArrayRegion(jbyteArray array, 1496 | jsize start, jsize len, jbyte *buf) const { 1497 | functions.GetByteArrayRegion(&this,array,start,len,buf); 1498 | } 1499 | void GetCharArrayRegion(jcharArray array, 1500 | jsize start, jsize len, jchar *buf) const { 1501 | functions.GetCharArrayRegion(&this,array,start,len,buf); 1502 | } 1503 | void GetShortArrayRegion(jshortArray array, 1504 | jsize start, jsize len, jshort *buf) const { 1505 | functions.GetShortArrayRegion(&this,array,start,len,buf); 1506 | } 1507 | void GetIntArrayRegion(jintArray array, 1508 | jsize start, jsize len, jint *buf) const { 1509 | functions.GetIntArrayRegion(&this,array,start,len,buf); 1510 | } 1511 | void GetLongArrayRegion(jlongArray array, 1512 | jsize start, jsize len, jlong *buf) const { 1513 | functions.GetLongArrayRegion(&this,array,start,len,buf); 1514 | } 1515 | void GetFloatArrayRegion(jfloatArray array, 1516 | jsize start, jsize len, jfloat *buf) const { 1517 | functions.GetFloatArrayRegion(&this,array,start,len,buf); 1518 | } 1519 | void GetDoubleArrayRegion(jdoubleArray array, 1520 | jsize start, jsize len, jdouble *buf) const { 1521 | functions.GetDoubleArrayRegion(&this,array,start,len,buf); 1522 | } 1523 | 1524 | void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len, 1525 | const(jboolean) *buf) const { 1526 | functions.SetBooleanArrayRegion(&this,array,start,len,buf); 1527 | } 1528 | void SetByteArrayRegion(jbyteArray array, jsize start, jsize len, 1529 | const(jbyte) *buf) const { 1530 | functions.SetByteArrayRegion(&this,array,start,len,buf); 1531 | } 1532 | void SetCharArrayRegion(jcharArray array, jsize start, jsize len, 1533 | const(jchar) *buf) const { 1534 | functions.SetCharArrayRegion(&this,array,start,len,buf); 1535 | } 1536 | void SetShortArrayRegion(jshortArray array, jsize start, jsize len, 1537 | const(jshort) *buf) const { 1538 | functions.SetShortArrayRegion(&this,array,start,len,buf); 1539 | } 1540 | void SetIntArrayRegion(jintArray array, jsize start, jsize len, 1541 | const(jint) *buf) const { 1542 | functions.SetIntArrayRegion(&this,array,start,len,buf); 1543 | } 1544 | void SetLongArrayRegion(jlongArray array, jsize start, jsize len, 1545 | const(jlong) *buf) const { 1546 | functions.SetLongArrayRegion(&this,array,start,len,buf); 1547 | } 1548 | void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len, 1549 | const(jfloat) *buf) const { 1550 | functions.SetFloatArrayRegion(&this,array,start,len,buf); 1551 | } 1552 | void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len, 1553 | const(jdouble) *buf) const { 1554 | functions.SetDoubleArrayRegion(&this,array,start,len,buf); 1555 | } 1556 | 1557 | jint RegisterNatives(jclass clazz, const(JNINativeMethod) *methods, 1558 | jint nMethods) const { 1559 | return functions.RegisterNatives(&this,clazz,methods,nMethods); 1560 | } 1561 | jint UnregisterNatives(jclass clazz) const { 1562 | return functions.UnregisterNatives(&this,clazz); 1563 | } 1564 | 1565 | jint MonitorEnter(jobject obj) const { 1566 | return functions.MonitorEnter(&this,obj); 1567 | } 1568 | jint MonitorExit(jobject obj) const { 1569 | return functions.MonitorExit(&this,obj); 1570 | } 1571 | 1572 | jint GetJavaVM(JavaVM **vm) const { 1573 | return functions.GetJavaVM(&this,vm); 1574 | } 1575 | 1576 | void GetStringRegion(jstring str, jsize start, jsize len, jchar *buf) const { 1577 | functions.GetStringRegion(&this,str,start,len,buf); 1578 | } 1579 | void GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf) const { 1580 | functions.GetStringUTFRegion(&this,str,start,len,buf); 1581 | } 1582 | 1583 | void * GetPrimitiveArrayCritical(jarray array, jboolean *isCopy) const { 1584 | return functions.GetPrimitiveArrayCritical(&this,array,isCopy); 1585 | } 1586 | void ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode) const { 1587 | functions.ReleasePrimitiveArrayCritical(&this,array,carray,mode); 1588 | } 1589 | 1590 | const(jchar) * GetStringCritical(jstring string, jboolean *isCopy) const { 1591 | return functions.GetStringCritical(&this,string,isCopy); 1592 | } 1593 | void ReleaseStringCritical(jstring string, const(jchar) *cstring) const { 1594 | functions.ReleaseStringCritical(&this,string,cstring); 1595 | } 1596 | 1597 | jweak NewWeakGlobalRef(jobject obj) const { 1598 | return functions.NewWeakGlobalRef(&this,obj); 1599 | } 1600 | void DeleteWeakGlobalRef(jweak _ref) const { 1601 | functions.DeleteWeakGlobalRef(&this,_ref); 1602 | } 1603 | 1604 | jboolean ExceptionCheck() const { 1605 | return functions.ExceptionCheck(&this); 1606 | } 1607 | 1608 | jobject NewDirectByteBuffer(void* address, jlong capacity) const { 1609 | return functions.NewDirectByteBuffer(&this, address, capacity); 1610 | } 1611 | void* GetDirectBufferAddress(jobject buf) const { 1612 | return functions.GetDirectBufferAddress(&this, buf); 1613 | } 1614 | jlong GetDirectBufferCapacity(jobject buf) const { 1615 | return functions.GetDirectBufferCapacity(&this, buf); 1616 | } 1617 | jobjectRefType GetObjectRefType(jobject obj) const { 1618 | return functions.GetObjectRefType(&this, obj); 1619 | } 1620 | 1621 | }; 1622 | 1623 | alias JNIEnv_ JNIEnv; 1624 | 1625 | 1626 | struct JavaVMOption { 1627 | char *optionString; 1628 | void *extraInfo; 1629 | } 1630 | 1631 | struct JavaVMInitArgs { 1632 | jint _version; 1633 | jint nOptions; 1634 | JavaVMOption *options; 1635 | jboolean ignoreUnrecognized; 1636 | } 1637 | 1638 | struct JavaVMAttachArgs { 1639 | jint _version; 1640 | char *name; 1641 | jobject group; 1642 | } 1643 | 1644 | 1645 | struct JNIInvokeInterface_ { 1646 | void *reserved0; 1647 | void *reserved1; 1648 | void *reserved2; 1649 | jint function(const(JavaVM_) *vm)DestroyJavaVM; 1650 | jint function(const(JavaVM_) *vm, void **penv, void *args)AttachCurrentThread; 1651 | jint function(const(JavaVM_) *vm)DetachCurrentThread; 1652 | jint function(const(JavaVM_) *vm, void **penv, jint _version)GetEnv; 1653 | jint function(const(JavaVM_) *vm, void **penv, void *args)AttachCurrentThreadAsDaemon; 1654 | } 1655 | 1656 | struct JavaVM_ { 1657 | const JNIInvokeInterface_ *functions; 1658 | 1659 | jint DestroyJavaVM() const { 1660 | return functions.DestroyJavaVM(&this); 1661 | } 1662 | jint AttachCurrentThread(void **penv, void *args) const { 1663 | return functions.AttachCurrentThread(&this, penv, args); 1664 | } 1665 | jint DetachCurrentThread() const { 1666 | return functions.DetachCurrentThread(&this); 1667 | } 1668 | 1669 | jint GetEnv(void **penv, jint _version) const { 1670 | return functions.GetEnv(&this, penv, _version); 1671 | } 1672 | jint AttachCurrentThreadAsDaemon(void **penv, void *args) const { 1673 | return functions.AttachCurrentThreadAsDaemon(&this, penv, args); 1674 | } 1675 | }; 1676 | 1677 | alias JavaVM_ JavaVM; 1678 | 1679 | 1680 | jint JNI_GetDefaultJavaVMInitArgs(void *args); 1681 | jint JNI_CreateJavaVM(JavaVM_ **pvm, void **penv, void *args); 1682 | jint JNI_GetCreatedJavaVMs(JavaVM_ **, jsize , jsize *); 1683 | 1684 | /* Defined by native libraries. */ 1685 | jint JNI_OnLoad(JavaVM_ *vm, void *reserved); 1686 | void JNI_OnUnload(JavaVM_ *vm, void *reserved); 1687 | 1688 | 1689 | const JNI_VERSION_1_1 = 0x00010001; 1690 | const JNI_VERSION_1_2 = 0x00010002; 1691 | const JNI_VERSION_1_4 = 0x00010004; 1692 | const JNI_VERSION_1_6 = 0x00010006; 1693 | 1694 | } 1695 | --------------------------------------------------------------------------------