From fb6627083b83207daa4e5e978f642a3d644b3959 Mon Sep 17 00:00:00 2001 From: Petre Eftime Date: Fri, 28 Aug 2015 18:10:43 +0300 Subject: [PATCH] java: map C buffer pointer and length to Java array for Ublox6 Signed-off-by: Petre Eftime Signed-off-by: Mihai Tudor Panu --- src/mic/javaupm_mic.i | 4 ++-- src/ublox6/javaupm_ublox6.i | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/mic/javaupm_mic.i b/src/mic/javaupm_mic.i index 0dcc4eca..1764429e 100644 --- a/src/mic/javaupm_mic.i +++ b/src/mic/javaupm_mic.i @@ -1,9 +1,9 @@ %module javaupm_mic %include "../upm.i" %include "stdint.i" -%include "typemaps.i" +%include "arrays_java.i" -%apply uint16_t *OUTPUT { uint16_t *buffer }; +%apply unsigned short[] {uint16_t *buffer}; %{ #include "mic.h" diff --git a/src/ublox6/javaupm_ublox6.i b/src/ublox6/javaupm_ublox6.i index 57673b4f..9a93422f 100644 --- a/src/ublox6/javaupm_ublox6.i +++ b/src/ublox6/javaupm_ublox6.i @@ -8,6 +8,23 @@ speed_t int_B9600 = B9600; %} +%typemap(jni) (char *buffer, size_t len) "jbyteArray"; +%typemap(jtype) (char *buffer, size_t len) "byte[]"; +%typemap(jstype) (char *buffer, size_t len) "byte[]"; + +%typemap(in) (char *buffer, size_t len) { + $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, NULL); + $2 = JCALL1(GetArrayLength, jenv, $input); +} + +%typemap(freearg) readData(char *buffer, size_t len) { + JCALL2(ReleaseByteArrayElements, jenv, $input, JNI_ABORT); +} + +%typemap(freearg) writeData(char *buffer, size_t len) { + JCALL2(ReleaseByteArrayElements, jenv, $input, 0); +} + %include "ublox6.h" speed_t int_B9600 = B9600; %array_class(char, charArray);