changeset 246:4a3ade651fcc

DIO-9: java.nio.BufferUnderflowException thrown at GPIOInputSample application Summary: javanotify_gpio_xxx_value_changed inserts integer value expected by EventQueueManager Reviewed-by: onazarkina
author snazarkin
date Thu, 10 Dec 2015 12:41:37 +0300
parents bbe5430a5795
children 958f53876e01
files src/se/native/com/oracle/dio/gpio/impl/jni_gpio.cpp
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/se/native/com/oracle/dio/gpio/impl/jni_gpio.cpp	Fri Oct 02 12:44:28 2015 +0300
+++ b/src/se/native/com/oracle/dio/gpio/impl/jni_gpio.cpp	Thu Dec 10 12:41:37 2015 +0300
@@ -370,12 +370,13 @@
     if (device == INVALID_DEVICE_REFERENCE) {
         return;
     }
-    const int size = 8; // reserve 4 bytes for the handle and 4 bytes for the value
+    const int size = 12; // reserve 4 bytes for the handle, 4 for subevent (0 in this case), and 4 bytes for the value
     char payload[size];
+    memset(payload, 0, size);
     payload[0] = (unsigned int)device >> 24, payload[1] = (unsigned int)device >> 16;
     payload[2] = (unsigned int)device >> 8,  payload[3] = (unsigned int)device;
-    payload[4] = value >> 24, payload[5] = value >> 16;
-    payload[6] = value >> 8,  payload[7] = value;
+    payload[8] = value >> 24, payload[9] = value >> 16;
+    payload[10] = value >> 8,  payload[11] = value;
     JavaVM* vm = getGlobalJavaVM();
     event_queue_put_native_event(vm, "jdk.dio.gpio.GPIOPin", payload, size);
 }
@@ -391,12 +392,13 @@
     if (device == INVALID_DEVICE_REFERENCE) {
         return;
     }
-    const int size = 8; // reserve 4 bytes for the handle and 4 bytes for the value
+    const int size = 12; // reserve 4 bytes for the handle, 4 for subevent (0 in this case),  and 4 bytes for the value
     char payload[size];
+    memset(payload, 0, size);
     payload[0] = (unsigned int)device >> 24, payload[1] = (unsigned int)device >> 16;
     payload[2] = (unsigned int)device >> 8,  payload[3] = (unsigned int)device;
-    payload[4] = value >> 24, payload[5] = value >> 16;
-    payload[6] = value >> 8,  payload[7] = value;
+    payload[8] = value >> 24, payload[9] = value >> 16;
+    payload[10] = value >> 8,  payload[11] = value;
     JavaVM* vm = getGlobalJavaVM();
     event_queue_put_native_event(vm, "jdk.dio.gpio.GPIOPort", payload, size);
 }