changeset 260:ae4dc5f2d281

DIO-6: Loopback UART connection is not robust Summary: VTS 1.1 detects multiple failures of UART tests when they are running in group. Reviewed-by: alkonsta
author snazarki
date Thu, 01 Oct 2015 15:30:18 +0300
parents db2fb33c280e
children f49f6cc6b93d
files src/se/classes/com/oracle/dio/impl/EventQueueManager.java src/share/linux/native/com/oracle/dio/uart/serial.c src/share/linux/native/com/oracle/dio/uart/uart.c
diffstat 3 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/se/classes/com/oracle/dio/impl/EventQueueManager.java	Thu Oct 01 15:24:32 2015 +0300
+++ b/src/se/classes/com/oracle/dio/impl/EventQueueManager.java	Thu Oct 01 15:30:18 2015 +0300
@@ -38,6 +38,7 @@
 
 public final class EventQueueManager implements EventHandler {
 
+    private final Vector<Integer> registeredTypes = new Vector<>();
     private final Hashtable<Integer, AbstractPeripheral> listenerRegistry = new Hashtable();
 
     private static final EventQueueManager instance = new EventQueueManager();
@@ -58,7 +59,12 @@
     public void setEventListener(Class<? extends Device> clazz, int eventSubType, AbstractPeripheral listener) {
         final int eventType = clazz.hashCode();
         final int nativeHandle = listener.getHandle().getNativeHandle();
-        queue.registerForEvent(clazz, this);
+        if (!registeredTypes.contains(eventType)) {
+            // prevent overriding that leads to message losses
+            queue.registerForEvent(clazz, this);
+            registeredTypes.add(eventType);
+        }
+
         listenerRegistry.put(getHash(eventType, eventSubType, nativeHandle), listener);
     }
 
--- a/src/share/linux/native/com/oracle/dio/uart/serial.c	Thu Oct 01 15:24:32 2015 +0300
+++ b/src/share/linux/native/com/oracle/dio/uart/serial.c	Thu Oct 01 15:30:18 2015 +0300
@@ -380,8 +380,6 @@
      * all incoming java buffer is written
      */
     if(size == p->out_total_written){
-        p->write_complete_cb(p, 0, JAVACALL_OK);
-        cleanup_write_buffer(p);
         return JAVACALL_OK;
     }
 
@@ -773,10 +771,10 @@
 
         tcdrain(p->fd);// wait until whole packet is transmitted
 
+        cleanup_write_buffer(p);
         p->out_total_written += current_buffer_offset;
         //send signal or event in DA
         p->write_complete_cb(p, current_buffer_offset, error==JAVACALL_TRUE?JAVACALL_FAIL:JAVACALL_OK);
-        cleanup_write_buffer(p);
         pthread_cond_wait(&p->out_buffer_ready, &p->write_lock);
     }while(1);
 
@@ -818,7 +816,7 @@
         if ( !JAVACALL_SUCCEEDED(res) ) {
             p->buffer_overrun_cb(p, 0,JAVACALL_OK);
         }
-        p->new_data_avail_cb(p, 0,JAVACALL_OK);
+        p->new_data_avail_cb(p, num, JAVACALL_OK);
 
         pthread_mutex_unlock( &(p->lock) );
     }
--- a/src/share/linux/native/com/oracle/dio/uart/uart.c	Thu Oct 01 15:24:32 2015 +0300
+++ b/src/share/linux/native/com/oracle/dio/uart/uart.c	Thu Oct 01 15:30:18 2015 +0300
@@ -122,20 +122,17 @@
     int bytesAvailable;
     javacall_dio_result res;
 
+    ((uart_handle)handle)->notifiedEvents &= ~(SERIAL_IN_AVAILABLE | SERIAL_IN_OVERRUN);
+
     pthread_mutex_lock( &((serial_handle)handle)->lock );
 
     if (JAVACALL_FAIL == jc_serial_read_common((serial_handle)handle, buffer, size, bytesRead, &bytesAvailable)){
         JAVACALL_REPORT_INFO(JC_SERIAL, "javacall_serial_read_start: cannot read from the internal buffer");
         res = JAVACALL_DIO_FAIL;
     }else{
-
-        ((uart_handle)handle)->notifiedEvents &= ~SERIAL_IN_AVAILABLE;
         if(bytesAvailable > 0){
-        ((serial_handle)handle)->new_data_avail_cb((serial_handle)handle, bytesAvailable, JAVACALL_DIO_OK);
+            ((serial_handle)handle)->new_data_avail_cb((serial_handle)handle, bytesAvailable, JAVACALL_DIO_OK);
         }
-        /*  read from the internal buffer complete, buffer may overrun again
-        */
-        ((uart_handle)handle)->notifiedEvents &= ~SERIAL_IN_OVERRUN;
         res = JAVACALL_DIO_OK;
     }
     pthread_mutex_unlock( &((serial_handle)handle)->lock );