1 %module (directors="1",docstring="Java interface to libmraa") mraa 2 3 %feature("autodoc", "3"); 4 5 %typemap(jtype) (uint8_t *txBuf, int length) "byte[]" 6 %typemap(jstype) (uint8_t *txBuf, int length) "byte[]" 7 %typemap(jni) (uint8_t *txBuf, int length) "jbyteArray" 8 %typemap(javain) (uint8_t *txBuf, int length) "$javainput" 9 10 %typemap(in,numinputs=1) (uint8_t *txBuf, int length) { 11 $1 = JCALL2(GetByteArrayElements, jenv, $input, NULL); 12 $2 = JCALL1(GetArrayLength, jenv, $input); 13 } 14 15 %typemap(jtype) (uint8_t *data, int length) "byte[]" 16 %typemap(jstype) (uint8_t *data, int length) "byte[]" 17 %typemap(jni) (uint8_t *data, int length) "jbyteArray" 18 %typemap(javain) (uint8_t *data, int length) "$javainput" 19 20 %typemap(in,numinputs=1) (uint8_t *data, int length) { 21 $1 = JCALL2(GetByteArrayElements, jenv, $input, NULL); 22 $2 = JCALL1(GetArrayLength, jenv, $input); 23 } 24 25 %typemap(argout) (uint8_t *data, int length) { 26 JCALL3(ReleaseByteArrayElements, jenv, $input, $1, JNI_COMMIT); 27 } 28 29 %typemap(jtype) (const uint8_t *data, int length) "byte[]" 30 %typemap(jstype) (const uint8_t *data, int length) "byte[]" 31 %typemap(jni) (const uint8_t *data, int length) "jbyteArray" 32 %typemap(javain) (const uint8_t *data, int length) "$javainput" 33 %typemap(in) (const uint8_t *data, int length) { 34 $1 = JCALL2(GetByteArrayElements, jenv, $input, NULL); 35 $2 = JCALL1(GetArrayLength, jenv, $input); 36 } 37 38 %typemap(jtype) uint8_t * "byte[]" 39 %typemap(jstype) uint8_t * "byte[]" 40 %typemap(jni) uint8_t * "jbyteArray" 41 %typemap(javaout) uint8_t * { 42 return $jnicall; 43 } 44 45 %typemap(jtype) jobject runnable "java.lang.Runnable" 46 %typemap(jstype) jobject runnable "java.lang.Runnable" 47 48 namespace mraa { 49 class Spi; 50 %typemap(out) uint8_t* 51 { 52 /* need to loop over length */ 53 $result = JCALL1(NewByteArray, jenv, arg3); 54 JCALL4(SetByteArrayRegion, jenv, $result, 0, arg3, (jbyte *) $1); 55 free($1); 56 } 57 } 58 59 %ignore write(const char* data, int length); 60 %ignore read(char* data, int length); 61 %ignore globVM; 62 %ignore env_key; 63 %ignore mraa_java_isr_callback; 64 65 %include ../mraa.i 66 67 %wrapper %{ 68 JavaVM *globVM; 69 JNI_OnLoad(JavaVM * vm,void * reserved)70 jint JNI_OnLoad(JavaVM *vm, void *reserved) { 71 /* initialize mraa */ 72 globVM = vm; 73 mraa_init(); 74 return JNI_VERSION_1_8; 75 } 76 %} 77 78 %pragma(java) jniclasscode=%{ 79 static { 80 try { 81 System.loadLibrary("mraajava"); catch(UnsatisfiedLinkError e)82 } catch (UnsatisfiedLinkError e) { 83 System.err.println("Native code library failed to load. \n" + e); 84 System.exit(1); 85 } 86 } 87 %} 88