changeset 190:f1a65e783681

8129110: pin.setTrigger(trigger) doesn't throw UOE on output GPIOPin Summary: Added check for direction Reviewed-by: alkonsta
author snazarki
date Thu, 18 Jun 2015 14:44:43 +0300
parents dd0fc7e6d5f9
children 03997bac2a18
files src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java
diffstat 1 files changed, 10 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java	Thu Jun 18 13:38:19 2015 +0300
+++ b/src/share/classes/com/oracle/dio/gpio/impl/GPIOPinImpl.java	Thu Jun 18 14:44:43 2015 +0300
@@ -85,14 +85,16 @@
 
     @Override
     public synchronized void setTrigger(int trigger)
-    throws java.io.IOException,
-    UnavailableDeviceException,
-    ClosedDeviceException {
-        checkOpen();
+    throws java.io.IOException, UnavailableDeviceException, ClosedDeviceException {
+        checkPowerState();
         if (GPIOPinConfig.TRIGGER_NONE > trigger ||
             GPIOPinConfig.TRIGGER_BOTH_LEVELS < trigger) {
             throw new IllegalArgumentException(String.valueOf(trigger));
         }
+        if (getOutputMode0()) {
+            throw new UnsupportedOperationException(
+                ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_DIR));
+        }
         setTrigger0( trigger);
     }
 
@@ -111,9 +113,6 @@
         * @return     true if pin is currently high
         */
     public synchronized boolean getValue() throws IOException,UnavailableDeviceException, ClosedDeviceException {
-
-        checkOpen();
-
         checkPowerState();
 
         int ret = readPin0();
@@ -130,9 +129,6 @@
         */
     public synchronized void setValue(boolean value)
     throws IOException,UnavailableDeviceException{
-
-        checkOpen();
-
         checkPowerState();
 
         if (getOutputMode0() == false) {
@@ -157,10 +153,12 @@
         return(getOutputMode0() ? OUTPUT : INPUT );
     }
 
-    public void processNativeEvent(int event, int data) {
+    @Override
+    protected void processNativeEvent(int event, int... data) {
+        final int value = data[0];
         PinListener listener = this.listener;
         if (null != listener) {
-            listener.valueChanged(new PinEvent(this, data > 0));
+            listener.valueChanged(new PinEvent(this, value > 0));
         }
     }
 
@@ -209,8 +207,6 @@
 
         AccessController.checkPermission(new GPIOPinPermission(getSecurityName(), GPIOPinPermission.SET_DIRECTION));
 
-        checkOpen();
-
         checkPowerState();
 
         int dir = ((GPIOPinConfig)dscr.getConfiguration()).getDirection();