aboutsummaryrefslogtreecommitdiff
path: root/flow/src/main/native/posix/flow_jni.c
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2014-03-28 16:50:26 +0100
committerJakob Odersky <jodersky@gmail.com>2014-03-28 16:50:26 +0100
commitdddd1b4509cec1f4c25e6189f10186562f115fac (patch)
tree30c6456bb5255372fa8bfe393c0e2c3b5913838a /flow/src/main/native/posix/flow_jni.c
parentb6f27be4eda4ec0e50aaca8eb3a117db60b4067e (diff)
downloadakka-serial-dddd1b4509cec1f4c25e6189f10186562f115fac.tar.gz
akka-serial-dddd1b4509cec1f4c25e6189f10186562f115fac.tar.bz2
akka-serial-dddd1b4509cec1f4c25e6189f10186562f115fac.zip
implement direct buffers
Diffstat (limited to 'flow/src/main/native/posix/flow_jni.c')
-rw-r--r--flow/src/main/native/posix/flow_jni.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/flow/src/main/native/posix/flow_jni.c b/flow/src/main/native/posix/flow_jni.c
index 9e0ec5e..8ec2aed 100644
--- a/flow/src/main/native/posix/flow_jni.c
+++ b/flow/src/main/native/posix/flow_jni.c
@@ -50,7 +50,21 @@ JNIEXPORT jlong JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_open
*/
JNIEXPORT jint JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_readDirect
(JNIEnv *env, jclass clazz, jlong config, jobject buffer) {
- return 0;
+
+ char* local_buffer = (char*) (*env)->GetDirectBufferAddress(env, buffer);
+ if (local_buffer == NULL) {
+ throwException(env, "java/lang/IllegalArgumentException", "ByteBuffer not direct");
+ return -1;
+ }
+ jlong size = (*env)->GetDirectBufferCapacity(env, buffer);
+
+ int r = serial_read((struct serial_config*) config, local_buffer, (size_t) size);
+ if (r < 0) {
+ check(env, r);
+ return -1;
+ }
+ return r;
+
}
/*
@@ -97,7 +111,18 @@ JNIEXPORT void JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_cance
JNIEXPORT jint JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_writeDirect
(JNIEnv *env, jclass clazz, jlong config, jobject buffer, jint size) {
- return 0;
+ char* local_buffer = (char *) (*env)->GetDirectBufferAddress(env, buffer);
+ if (local_buffer == NULL) {
+ throwException(env, "java/lang/IllegalArgumentException", "ByteBuffer not direct");
+ return -1;
+ }
+
+ int r = serial_write((struct serial_config*) config, local_buffer, (size_t) size);
+ if (r < 0) {
+ check(env, r);
+ return -1;
+ }
+ return r;
}