changeset 175:4328bfd8a8f5

8129216: Complete implementation of new functions at *Config classes Summary: Added functions real implementations Reviewed-by: alkonsta
author snazarki
date Thu, 18 Jun 2015 18:34:23 +0300
parents 4acc8eae476b
children 691950e8cc89
files src/se/classes/com/oracle/dio/utils/ExceptionMessage.java src/share/classes/com/oracle/dio/utils/Utils.java src/share/classes/jdk/dio/adc/ADCChannelConfig.java src/share/classes/jdk/dio/atcmd/ATDeviceConfig.java src/share/classes/jdk/dio/counter/PulseCounterConfig.java src/share/classes/jdk/dio/dac/DACChannelConfig.java src/share/classes/jdk/dio/generic/GenericDeviceConfig.java src/share/classes/jdk/dio/gpio/GPIOPinConfig.java src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java src/share/classes/jdk/dio/pwm/PWMChannelConfig.java src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java src/share/classes/jdk/dio/watchdog/WatchdogTimerConfig.java
diffstat 12 files changed, 209 insertions(+), 237 deletions(-) [+]
line wrap: on
line diff
--- a/src/se/classes/com/oracle/dio/utils/ExceptionMessage.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/se/classes/com/oracle/dio/utils/ExceptionMessage.java	Thu Jun 18 18:34:23 2015 +0300
@@ -95,22 +95,20 @@
     public static final int DAC_LAST = DAC_CANNOT_START_CONVERSION;
 
     public static final int GPIO_FIRST = DAC_LAST + 1;
-    public static final int GPIO_TRIGGER_OR_MODE                     = GPIO_FIRST + 0;
-    public static final int GPIO_MODE_NOT_FOR_DIRINPUTONLY           = GPIO_FIRST + 1;
-    public static final int GPIO_MODE_NOT_FOR_DIROUTPUTONLY          = GPIO_FIRST + 2;
-    public static final int GPIO_MODE_NOT_FOR_DIRBOTH                = GPIO_FIRST + 3;
-    public static final int GPIO_INVALID_DIRECTION                   = GPIO_FIRST + 4;
-    public static final int GPIO_ILLEGAL_DIRECTION_OR_INIT_VALUE     = GPIO_FIRST + 5;
-    public static final int GPIO_DIR_UNSUPPORTED_BY_PIN_CONFIG       = GPIO_FIRST + 6;
-    public static final int GPIO_SET_TO_INPUT_PIN                    = GPIO_FIRST + 7;
-    public static final int GPIO_REGISTER_LISTENER_TO_OUTPUT_PIN     = GPIO_FIRST + 8;
-    public static final int GPIO_CANNOT_START_NOTIFICATION           = GPIO_FIRST + 9;
-    public static final int GPIO_LISTENER_ALREADY_ASSIGNED           = GPIO_FIRST + 10;
-    public static final int GPIO_DIR_SHOULD_BE_INPUT_OR_OUTPUT       = GPIO_FIRST + 11;
-    public static final int GPIO_INCOMPATIBLE_DIR                    = GPIO_FIRST + 12;
-    public static final int GPIO_WRITE_TO_INPUT_PORT                 = GPIO_FIRST + 13;
-    public static final int GPIO_REGISTER_LISTENER_TO_OUTPUT_PORT    = GPIO_FIRST + 14;
-    public static final int GPIO_LAST = GPIO_REGISTER_LISTENER_TO_OUTPUT_PORT;
+    public static final int GPIO_INVALID_TRIGGER                     = GPIO_FIRST + 0;
+    public static final int GPIO_INVALID_DIRECTION                   = GPIO_FIRST + 1;
+    public static final int GPIO_INVALID_MODE                        = GPIO_FIRST + 2;
+    public static final int GPIO_DIR_UNSUPPORTED_BY_PIN_CONFIG       = GPIO_FIRST + 3;
+    public static final int GPIO_SET_TO_INPUT_PIN                    = GPIO_FIRST + 4;
+    public static final int GPIO_REGISTER_LISTENER_TO_OUTPUT_PIN     = GPIO_FIRST + 5;
+    public static final int GPIO_CANNOT_START_NOTIFICATION           = GPIO_FIRST + 6;
+    public static final int GPIO_LISTENER_ALREADY_ASSIGNED           = GPIO_FIRST + 7;
+    public static final int GPIO_DIR_SHOULD_BE_INPUT_OR_OUTPUT       = GPIO_FIRST + 8;
+    public static final int GPIO_INCOMPATIBLE_DIR                    = GPIO_FIRST + 9;
+    public static final int GPIO_WRITE_TO_INPUT_PORT                 = GPIO_FIRST + 10;
+    public static final int GPIO_REGISTER_LISTENER_TO_OUTPUT_PORT    = GPIO_FIRST + 11;
+    public static final int GPIO_INCOMPATIBLE_MODE                   = GPIO_FIRST + 12;
+    public static final int GPIO_LAST = GPIO_INCOMPATIBLE_MODE;
 
     public static final int I2CBUS_FIRST = GPIO_LAST + 1;
     public static final int I2CBUS_ALREADY_TRANSFERRED_MESSAGE       = I2CBUS_FIRST + 0;
@@ -225,11 +223,9 @@
         "Cannot start conversion",
 
         // gpio messages
-        "Trigger or mode",
-        "mode is not for DIR_INPUT_ONLY",
-        "mode is not for DIR_OUTPUT_ONLY",
-        "mode is not for DIR_BOTH: %d",
+        "Invalid trigger",
         "Invalid direction",
+        "Invalid mode",
         "Illegal direction or initValue",
         "Pin config does not support required direction",
         "Try to Set value to input pin",
@@ -240,6 +236,8 @@
         "Incompatible direction",
         "Trying to write to input port",
         "Try to register Listener to output port",
+        "Incompatible mode",
+
 
         // i2c bus messages
         "the message has already been transferred once",
--- a/src/share/classes/com/oracle/dio/utils/Utils.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/com/oracle/dio/utils/Utils.java	Thu Jun 18 18:34:23 2015 +0300
@@ -174,11 +174,11 @@
     }
 
     /**
-     * Checks if given value is greater than one
+     * Checks if given value is greater than one or UNASSIGNED
      *
      */
     public static void checkGreaterThanOne(final int val) {
-        if (1> val) {
+        if (DeviceConfig.UNASSIGNED > val || 1 > val){
             throw new IllegalArgumentException(Integer.toString(val));
         }
     }
@@ -187,7 +187,7 @@
      * Checks if no NaN and positive value
      */
     public static void checkDoubleGreaterThanOne(double val) {
-        if (val  < 1.0 || Double.NaN == val) {
+        if (val  < 1.0 || Double.NaN == val || Double.POSITIVE_INFINITY == val) {
             throw new IllegalArgumentException(Double.toString(val));
         }
     }
--- a/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -487,7 +487,6 @@
     private void checkValues() throws IllegalArgumentException {
         Utils.checkIntValue(controllerNumber);
         Utils.checkIntValue(channelNumber);
-        Utils.checkIntValue(inputBufferSize);
         Utils.checkGreaterThanOne(resolution);
         Utils.checkGreaterThanOne(samplingInterval);
         Utils.checkGreaterThanOne(samplingTime);
--- a/src/share/classes/jdk/dio/atcmd/ATDeviceConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/atcmd/ATDeviceConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -87,13 +87,10 @@
      *             if {@code controller name} is {@code null}.
      */
     public ATDeviceConfig(String controllerName, int channelNumber) {
-        this.controllerName = controllerName;
-        this.channelNumber = channelNumber;
+        this(DEFAULT, channelNumber);
         // checks for NPE
         controllerName.length();
-        if (DEFAULT > channelNumber) {
-            throw new  IllegalArgumentException();
-        }
+        this.controllerName = controllerName;
     }
 
     /**
@@ -107,11 +104,11 @@
      *             if {@code channelNumber} is not in the defined range.
      */
     public ATDeviceConfig(int controllerNumber, int channelNumber) {
-        this.controllerNumber = controllerNumber;
-        this.channelNumber = channelNumber;
         if (DEFAULT > channelNumber || DEFAULT > controllerNumber) {
             throw new  IllegalArgumentException();
         }
+        this.controllerNumber = controllerNumber;
+        this.channelNumber = channelNumber;
     }
 
     /**
@@ -127,7 +124,7 @@
      * @since 1.1
      */
     public static ATDeviceConfig deserialize(InputStream in) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return (ATDeviceConfig) Platform.deserialize(in);
     }
 
 
@@ -143,7 +140,7 @@
      */
     @Override
     public int serialize(OutputStream out) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return Platform.serialize(this, out);
     }
 
     /**
--- a/src/share/classes/jdk/dio/counter/PulseCounterConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/counter/PulseCounterConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -31,6 +31,7 @@
 
 import com.oracle.dio.impl.Platform;
 import com.oracle.dio.utils.ExceptionMessage;
+import com.oracle.dio.utils.Utils;
 
 import jdk.dio.DeviceConfig;
 import jdk.dio.DeviceDescriptor;
@@ -149,7 +150,8 @@
             if (instance.type == UNASSIGNED) {
                 throw new IllegalStateException();
             }
-            return instance;
+            instance.checkValues();
+            return (PulseCounterConfig) Platform.clone(instance);
         }
 
         /**
@@ -175,8 +177,8 @@
          * the defined range.
          */
         public Builder setChannelNumber(int channelNumber) {
+            Utils.checkIntValue(channelNumber);
             instance.channelNumber = channelNumber;
-            instance.checkChannelNumber();
             return this;
         }
 
@@ -191,8 +193,8 @@
          * in the defined range.
          */
         public Builder setControllerNumber(int controllerNumber) {
+            Utils.checkIntValue(controllerNumber);
             instance.controllerNumber = controllerNumber;
-            instance.checkControllerNumber();
             return this;
         }
 
@@ -207,8 +209,8 @@
          * {@code null} and is not configured for input.
          */
         public Builder setSourceConfig(GPIOPinConfig source) {
+            checkSourceConfig(source);
             instance.sourceConfig = source;
-            instance.checkSourceConfig();
             return this;
         }
 
@@ -223,22 +225,12 @@
          * defined range.
          */
         public Builder setType(int type) {
+            checkType(type);
             instance.type = type;
-            instance.checkType();
             return this;
         }
     }
 
-    private PulseCounterConfig(PulseCounterConfig prototype) {
-        if (prototype != null) {
-            this.controllerName = prototype.controllerName;
-            this.channelNumber = prototype.channelNumber;
-            this.controllerNumber = prototype.controllerNumber;
-            this.sourceConfig = prototype.sourceConfig;
-            this.type = prototype.type;
-        }
-    }
-
     // hidden constructor for serializer
     @DontRenameMethod
     PulseCounterConfig(){}
@@ -305,13 +297,9 @@
      */
     @Deprecated
     public PulseCounterConfig(int controllerNumber, int channelNumber, int type, GPIOPinConfig source) {
-        this.controllerNumber = controllerNumber;
-        this.channelNumber = channelNumber;
-        this.type = type;
+        this(controllerNumber, channelNumber, type);
+        checkSourceConfig(source);
         this.sourceConfig = source;
-        // check for null
-        source.getDirection();
-        checkValues();
     }
 
     /**
@@ -339,12 +327,10 @@
      */
     @Deprecated
     public PulseCounterConfig(String controllerName, int channelNumber, int type) {
+        this(DEFAULT, channelNumber, type);
         // checks for null
         controllerName.length();
         this.controllerName = controllerName;
-        this.channelNumber = channelNumber;
-        this.type = type;
-        checkValues();
     }
 
     /**
@@ -378,15 +364,9 @@
      */
     @Deprecated
     public PulseCounterConfig(String controllerName, int channelNumber, int type, GPIOPinConfig source) {
-        // checks for null
-        controllerName.length();
-        this.controllerName = controllerName;
-        this.channelNumber = channelNumber;
-        this.type = type;
+        this(controllerName, channelNumber, type);
+        checkSourceConfig(source);
         this.sourceConfig = source;
-        // checks for null
-        source.getClass();
-        checkValues();
     }
 
     /**
@@ -402,7 +382,7 @@
      * @since 1.1
      */
     public static PulseCounterConfig deserialize(InputStream in) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return (PulseCounterConfig) Platform.deserialize(in);
     }
 
 
@@ -418,7 +398,7 @@
      */
     @Override
     public int serialize(OutputStream out) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return Platform.serialize(this, out);
     }
 
     /**
@@ -513,23 +493,7 @@
         return Platform.equals(this, obj);
     }
 
-    private void checkChannelNumber() {
-        if (channelNumber < UNASSIGNED ) {
-            throw new IllegalArgumentException(
-                ExceptionMessage.format(ExceptionMessage.COUNTER_INVALID_CHANNEL_NUMBER)
-            );
-        }
-    }
-
-    private void checkControllerNumber() {
-        if (controllerNumber < UNASSIGNED) {
-            throw new IllegalArgumentException(
-                ExceptionMessage.format(ExceptionMessage.COUNTER_INVALID_CONTROLLER_NUMBER)
-            );
-        }
-    }
-
-    private void checkType() {
+    private static void checkType(int type) {
         if (TYPE_NEGATIVE_PULSE < type || TYPE_FALLING_EDGE_ONLY > type ) {
             throw new IllegalArgumentException(
                 ExceptionMessage.format(ExceptionMessage.COUNTER_INVALID_TYPE)
@@ -537,31 +501,24 @@
         }
     }
 
-    private void checkSourceConfig() {
-        if  (sourceConfig != null &&
-                    (sourceConfig.getDirection() !=  GPIOPinConfig.DIR_INPUT_ONLY && sourceConfig.getDirection() !=  GPIOPinConfig.DIR_BOTH_INIT_INPUT)) {
-            throw new IllegalArgumentException(
-                    ExceptionMessage.format(ExceptionMessage.COUNTER_CONFIG_CANNOT_BE_USED)
-                );
+    private static void checkSourceConfig(GPIOPinConfig sourceConfig) {
+        if  ((sourceConfig.getDirection() !=  GPIOPinConfig.DIR_INPUT_ONLY && sourceConfig.getDirection() !=  GPIOPinConfig.DIR_BOTH_INIT_INPUT)) {
+            throw new IllegalArgumentException(ExceptionMessage.format(ExceptionMessage.COUNTER_CONFIG_CANNOT_BE_USED));
         }
     }
 
     private void checkValues() throws IllegalArgumentException {
-        checkChannelNumber();
-        checkControllerNumber();
-        checkType();
-        checkSourceConfig();
+        Utils.checkIntValue(controllerNumber);
+        Utils.checkIntValue(channelNumber);
+        checkType(type);
         // rising and falling edges
         if (null != sourceConfig) {
             int trigger = sourceConfig.getTrigger();
             if (((trigger >> 1) != type &&
-                //When the pulse source is a GPIO pin  then this pulse edge type can only be used if the pin is configured with the
+                // When the pulse source is a GPIO pin  then this pulse edge type can only be used if the pin is configured with the
                 // GPIOPinConfig#TRIGGER_BOTH_EDGES trigger mode
-                (type > TYPE_RISING_EDGE_ONLY && trigger != GPIOPinConfig.TRIGGER_BOTH_EDGES))
-                ) {
-                throw new IllegalArgumentException(
-                    ExceptionMessage.format(ExceptionMessage.COUNTER_CONFIG_CANNOT_BE_USED)
-                );
+                (type > TYPE_RISING_EDGE_ONLY && trigger != GPIOPinConfig.TRIGGER_BOTH_EDGES))) {
+                    throw new IllegalArgumentException(ExceptionMessage.format(ExceptionMessage.COUNTER_CONFIG_CANNOT_BE_USED));
             }
         }
     }
--- a/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -31,6 +31,7 @@
 import java.util.Objects;
 
 import com.oracle.dio.impl.Platform;
+import com.oracle.dio.utils.Utils;
 
 import jdk.dio.DeviceConfig;
 import jdk.dio.DeviceManager;
@@ -112,8 +113,7 @@
          * @return a new initialized {@code DACChannelConfig} instance.
          */
         public DACChannelConfig build() {
-            instance.checkValues();
-            return instance;
+            return (DACChannelConfig) Platform.clone(instance);
         }
 
         /**
@@ -138,6 +138,7 @@
          * the defined range.
          */
         public Builder setChannelNumber(int channelNumber) {
+            Utils.checkIntValue(channelNumber);
             instance.channelNumber = channelNumber;
             return this;
         }
@@ -152,6 +153,7 @@
          * in the defined range.
          */
         public Builder setControllerNumber(int controllerNumber) {
+            Utils.checkIntValue(controllerNumber);
             instance.controllerNumber = controllerNumber;
             return this;
         }
@@ -166,6 +168,7 @@
          * defined range.
          */
         public Builder setResolution(int resolution) {
+            Utils.checkGreaterThanOne(resolution);
             instance.resolution = resolution;
             return this;
         }
@@ -184,6 +187,7 @@
          * @see #setScaleFactor
          */
         public Builder setSamplingInterval(int samplingInterval) {
+            Utils.checkGreaterThanOne(samplingInterval);
             instance.samplingInterval = samplingInterval;
             return this;
         }
@@ -199,6 +203,7 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
+            Utils.checkDoubleGreaterThanOne(scaleFactor);
             instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
             return this;
         }
@@ -214,6 +219,7 @@
          * the defined range.
          */
         public Builder setOutputBufferSize(int outputBufferSize) {
+            Utils.checkIntValue(outputBufferSize);
             instance.outputBufferSize = outputBufferSize;
             return this;
         }
@@ -431,12 +437,10 @@
     }
 
     private void checkValues() {
-        if ((null == controllerName && DEFAULT > controllerNumber) || DEFAULT > channelNumber ||
-            DEFAULT > resolution || 0 == resolution ||
-            DEFAULT > samplingInterval || 0 == samplingInterval ||
-            getScaleFactor() < 0.0) {
-            throw new IllegalArgumentException();
-        }
+        Utils.checkIntValue(controllerNumber);
+        Utils.checkIntValue(channelNumber);
+        Utils.checkGreaterThanOne(resolution);
+        Utils.checkGreaterThanOne(samplingInterval);
     }
 
 }
--- a/src/share/classes/jdk/dio/generic/GenericDeviceConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/generic/GenericDeviceConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -30,6 +30,7 @@
 import java.util.Objects;
 
 import com.oracle.dio.impl.Platform;
+import com.oracle.dio.utils.Utils;
 
 import jdk.dio.DeviceConfig;
 import jdk.dio.DeviceManager;
@@ -134,6 +135,7 @@
          * the defined range.
          */
         public Builder setChannelNumber(int channelNumber) {
+            Utils.checkIntValue(channelNumber);
             instance.channelNumber = channelNumber;
             return this;
         }
@@ -149,6 +151,7 @@
          * in the defined range.
          */
         public Builder setControllerNumber(int controllerNumber) {
+            Utils.checkIntValue(controllerNumber);
             instance.controllerNumber = controllerNumber;
             return this;
         }
@@ -165,6 +168,7 @@
          * the defined range.
          */
         public Builder setInputBufferSize(int inputBufferSize) {
+            Utils.checkIntValue(inputBufferSize);
             instance.inputBufferSize = inputBufferSize;
             return this;
         }
@@ -181,6 +185,7 @@
          * in the defined range.
          */
         public Builder setOutputBufferSize(int outputBufferSize) {
+            Utils.checkIntValue(outputBufferSize);
             instance.outputBufferSize = outputBufferSize;
             return this;
         }
@@ -232,10 +237,10 @@
      */
     @Deprecated
     public GenericDeviceConfig(String controllerName, int channelNumber) {
-        this.controllerName = controllerName;
-        this.channelNumber = channelNumber;
+        this(DEFAULT, channelNumber);
         // NPE check
         controllerName.length();
+        this.controllerName = controllerName;
     }
 
     /**
@@ -251,7 +256,7 @@
      * @since 1.1
      */
     public static GenericDeviceConfig deserialize(InputStream in) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return (GenericDeviceConfig) Platform.deserialize(in);
     }
 
     /**
@@ -266,7 +271,7 @@
      */
     @Override
     public int serialize(OutputStream out) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return Platform.serialize(this, out);
     }
 
     /**
--- a/src/share/classes/jdk/dio/gpio/GPIOPinConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/gpio/GPIOPinConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -31,6 +31,7 @@
 
 import com.oracle.dio.impl.Platform;
 import com.oracle.dio.utils.ExceptionMessage;
+import com.oracle.dio.utils.Utils;
 
 import jdk.dio.DeviceConfig;
 import jdk.dio.DeviceManager;
@@ -193,8 +194,7 @@
          */
         public GPIOPinConfig build() {
             if (instance.direction == UNASSIGNED) {
-                throw new IllegalStateException(
-                ExceptionMessage.format(ExceptionMessage.GPIO_INVALID_DIRECTION));
+                throw new IllegalStateException(ExceptionMessage.format(ExceptionMessage.GPIO_INVALID_DIRECTION));
             }
             instance.checkConsistency();
             return instance;
@@ -222,8 +222,8 @@
          * defined range.
          */
         public Builder setPinNumber(int pinNumber) {
+            Utils.checkIntValue(pinNumber);
             instance.pinNumber = pinNumber;
-            instance.checkPinNumber();
             return this;
         }
 
@@ -238,8 +238,8 @@
          * in the defined range.
          */
         public Builder setControllerNumber(int controllerNumber) {
+            Utils.checkIntValue(controllerNumber);
             instance.controllerNumber = controllerNumber;
-            instance.checkControllerNumber();
             return this;
         }
 
@@ -255,8 +255,8 @@
          * defined range.
          */
         public Builder setDirection(int direction) {
+            checkDirection(direction);
             instance.direction = direction;
-            instance.checkDirection();
             return this;
         }
 
@@ -293,8 +293,8 @@
          * </ul>
          */
         public Builder setDriveMode(int mode) {
+            checkMode(mode);
             instance.mode = mode;
-            instance.checkMode();
             return this;
         }
 
@@ -313,8 +313,8 @@
          * defined range.
          */
         public Builder setTrigger(int trigger) {
+            checkTrigger(trigger);
             instance.trigger = trigger;
-            instance.checkTrigger();
             return this;
         }
     }
@@ -425,17 +425,9 @@
      */
     @Deprecated
     public GPIOPinConfig(String controllerName, int pinNumber, int direction, int mode, int trigger, boolean initValue) {
+        this(DEFAULT, pinNumber, direction, mode, trigger, initValue);
+        controllerName.length();// NPE check
         this.controllerName = controllerName;
-        this.pinNumber = pinNumber;
-        controllerName.length();// NPE check
-        if (pinNumber < DeviceConfig.DEFAULT) {
-            throw new IllegalArgumentException();
-        }
-        this.direction = direction;
-        this.trigger = trigger;
-        this.mode = mode;
-        this.initValue = initValue;
-        checkAll();
     }
 
     /**
@@ -451,7 +443,7 @@
      * @since 1.1
      */
     public static GPIOPinConfig deserialize(InputStream in) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return (GPIOPinConfig) Platform.deserialize(in);
     }
 
 
@@ -467,7 +459,7 @@
      */
     @Override
     public int serialize(OutputStream out) throws IOException {
-      throw new IOException("Unsupported Operation");
+      return Platform.serialize(this, out);
     }
 
     /**
@@ -565,39 +557,26 @@
         return Platform.equals(this, obj);
     }
 
-    private void checkControllerNumber() {
-        // we assume UNASSIGNED = -1
-        if (controllerNumber < UNASSIGNED) {
-            throw new IllegalArgumentException();
+
+    private static void checkDirection(int direction) {
+        if (direction < DIR_INPUT_ONLY || direction > DIR_BOTH_INIT_OUTPUT) {
+            throw new IllegalArgumentException(ExceptionMessage.format(ExceptionMessage.GPIO_INVALID_DIRECTION));
         }
     }
 
-    private void checkPinNumber() {
-        // we assume UNASSIGNED = -1
-        if (pinNumber < UNASSIGNED) {
-            throw new IllegalArgumentException();
-        }
-    }
-
-    private void checkDirection() {
-        if (direction < DIR_INPUT_ONLY || direction > DIR_BOTH_INIT_OUTPUT) {
-            throw new IllegalArgumentException();
-        }
-    }
-
-    private void checkMode() {
+    private static void checkMode(int mode) {
         if (UNASSIGNED != mode
             && (0 == mode
                 || 0 != (mode & ~(GPIOPinConfig.MODE_INPUT_PULL_UP | GPIOPinConfig.MODE_INPUT_PULL_DOWN | GPIOPinConfig.MODE_OUTPUT_PUSH_PULL | GPIOPinConfig.MODE_OUTPUT_OPEN_DRAIN))
                 || (GPIOPinConfig.MODE_INPUT_PULL_UP | GPIOPinConfig.MODE_INPUT_PULL_DOWN) == (mode & (GPIOPinConfig.MODE_INPUT_PULL_UP | GPIOPinConfig.MODE_INPUT_PULL_DOWN))
                 || (GPIOPinConfig.MODE_OUTPUT_PUSH_PULL | GPIOPinConfig.MODE_OUTPUT_OPEN_DRAIN) == (mode & (GPIOPinConfig.MODE_OUTPUT_PUSH_PULL | GPIOPinConfig.MODE_OUTPUT_OPEN_DRAIN)))) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException(ExceptionMessage.format(ExceptionMessage.GPIO_INVALID_MODE));
         }
     }
 
-    private void checkTrigger() {
+    private static void checkTrigger(int trigger) {
         if (trigger < TRIGGER_NONE || trigger > TRIGGER_BOTH_LEVELS) {
-                throw new IllegalArgumentException();
+            throw new IllegalArgumentException(ExceptionMessage.format(ExceptionMessage.GPIO_INVALID_TRIGGER));
         }
     }
 
@@ -606,7 +585,7 @@
     private void checkConsistency() {
         if (direction == DIR_OUTPUT_ONLY && trigger != TRIGGER_NONE) {
             throw new IllegalArgumentException(
-                    ExceptionMessage.format(ExceptionMessage.GPIO_TRIGGER_OR_MODE)
+                    ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_DIR)
                 );
         }
 
@@ -615,7 +594,7 @@
             if (DeviceConfig.DEFAULT != mode &&
                 0 != (mode & ~(GPIOPinConfig.MODE_INPUT_PULL_DOWN | GPIOPinConfig.MODE_INPUT_PULL_UP))) {
                 throw new IllegalArgumentException(
-                    ExceptionMessage.format(ExceptionMessage.GPIO_MODE_NOT_FOR_DIRINPUTONLY)
+                    ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_MODE)
                 );
             }
             break;
@@ -623,7 +602,7 @@
             if (DeviceConfig.DEFAULT != mode &&
                 0 != (mode & ~(GPIOPinConfig.MODE_OUTPUT_OPEN_DRAIN | GPIOPinConfig.MODE_OUTPUT_PUSH_PULL ))) {
                 throw new IllegalArgumentException(
-                    ExceptionMessage.format(ExceptionMessage.GPIO_MODE_NOT_FOR_DIROUTPUTONLY)
+                    ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_MODE)
                 );
             }
             break;
@@ -635,24 +614,24 @@
                 (mode != (MODE_INPUT_PULL_UP   | MODE_OUTPUT_OPEN_DRAIN)) &&
                 (mode != (MODE_INPUT_PULL_UP   | MODE_OUTPUT_PUSH_PULL))) )  {
                 throw new IllegalArgumentException(
-                    ExceptionMessage.format(ExceptionMessage.GPIO_MODE_NOT_FOR_DIRBOTH, mode)
+                    ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_MODE)
                 );
             }
             break;
         default:
             throw new IllegalArgumentException(
-                ExceptionMessage.format(ExceptionMessage.GPIO_INVALID_DIRECTION)
+                ExceptionMessage.format(ExceptionMessage.GPIO_INCOMPATIBLE_MODE)
             );
         }
     }
 
     /** check everything for deprecated @see GPIOPinConfig call */
     private void checkAll() {
-        checkControllerNumber();
-        checkPinNumber();
-        checkDirection();
-        checkMode();
-        checkTrigger();
+        Utils.checkIntValue(controllerNumber);
+        Utils.checkIntValue(pinNumber);
+        checkDirection(direction);
+        checkMode(mode);
+        checkTrigger(trigger);
         checkConsistency();
     }
 }
--- a/src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/i2cbus/I2CDeviceConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -30,6 +30,7 @@
 import java.util.Objects;
 
 import com.oracle.dio.impl.Platform;
+import com.oracle.dio.utils.Utils;
 
 import jdk.dio.DeviceConfig;
 import jdk.dio.DeviceManager;
@@ -121,8 +122,10 @@
          * </ul>
          */
         public I2CDeviceConfig build() {
-            instance.checkValues();
-            return instance;
+            if (UNASSIGNED ==instance.address) {
+                throw new IllegalStateException();
+            }
+            return (I2CDeviceConfig) Platform.clone(instance);
         }
 
         /**
@@ -152,6 +155,8 @@
          * </ul>
          */
         public Builder setAddress(int address, int addressSize) {
+            Utils.checkIntValue(address);
+            checkAddressSize(addressSize);
             instance.address = address;
             instance.addressSize = addressSize;
             return this;
@@ -168,6 +173,7 @@
          * in the defined range.
          */
         public Builder setControllerNumber(int controllerNumber) {
+            Utils.checkIntValue(controllerNumber);
             instance.controllerNumber = controllerNumber;
             return this;
         }
@@ -184,6 +190,7 @@
          * the defined range.
          */
         public Builder setInputBufferSize(int inputBufferSize) {
+            Utils.checkIntValue(inputBufferSize);
             instance.inputBufferSize = inputBufferSize;
             return this;
         }
@@ -200,6 +207,7 @@
          * in the defined range.
          */
         public Builder setOutputBufferSize(int outputBufferSize) {
+            Utils.checkIntValue(outputBufferSize);
             instance.outputBufferSize = outputBufferSize;
             return this;
         }
@@ -215,6 +223,7 @@
          * the defined range.
          */
         public Builder setClockFrequency(int clockFrequency) {
+            Utils.checkGreaterThanOne(clockFrequency);
             instance.clockFrequency = clockFrequency;
             return this;
         }
@@ -290,13 +299,10 @@
      */
     @Deprecated
     public I2CDeviceConfig(String controllerName, int address, int addressSize, int clockFrequency) {
-        this.controllerName = controllerName;
-        this.address = address;
-        this.addressSize = addressSize;
-        this.clockFrequency = clockFrequency;
+        this(DEFAULT, address, addressSize, clockFrequency);
         // check for null
         controllerName.length();
-        checkValues();
+        this.controllerName = controllerName;
     }
 
     /**
@@ -312,7 +318,7 @@
      * @since 1.1
      */
     public static I2CDeviceConfig deserialize(InputStream in) throws IOException {
-      throw new IOException("Unsupported Operation");
+      return (I2CDeviceConfig) Platform.deserialize(in);
     }
 
     /**
@@ -327,7 +333,7 @@
      */
     @Override
     public int serialize(OutputStream out) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return Platform.serialize(this, out);
     }
 
     /**
@@ -433,13 +439,18 @@
         return Platform.equals(this, obj);
     }
 
-    private void checkValues() {
-        if ((null == controllerName && DEFAULT > controllerNumber) ||
-            0 > address ||
-            (ADDR_SIZE_7 != addressSize && ADDR_SIZE_10 != addressSize && DEFAULT != addressSize) ||
-            DEFAULT > clockFrequency || 0 == clockFrequency) {
-            throw new IllegalArgumentException();
+
+    private static void checkAddressSize(int addressSize) {
+        if (ADDR_SIZE_7 != addressSize && ADDR_SIZE_10 != addressSize && DEFAULT != addressSize) {
+            throw new IllegalArgumentException(Integer.toString(addressSize));
         }
     }
 
+    private void checkValues() {
+        Utils.checkIntValue(controllerNumber);
+        Utils.checkIntValue(address);
+        Utils.checkGreaterThanOne(clockFrequency);
+        checkAddressSize(addressSize);
+    }
+
 }
--- a/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -31,6 +31,7 @@
 
 import com.oracle.dio.impl.Platform;
 import com.oracle.dio.utils.ExceptionMessage;
+import com.oracle.dio.utils.Utils;
 
 import jdk.dio.DeviceConfig;
 import jdk.dio.DeviceManager;
@@ -62,7 +63,7 @@
  */
 @SerializeMe
 @apimarker.API("device-io_1.1_pwm")
-public class PWMChannelConfig implements DeviceConfig<PWMChannel>, DeviceConfig.HardwareAddressing {
+public final class PWMChannelConfig implements DeviceConfig<PWMChannel>, DeviceConfig.HardwareAddressing {
 
     /**
      * High idle state. The idle state is the state of the PWM output when no pulse is generated.
@@ -137,7 +138,7 @@
          * @return a new initialized {@code PWMChannelConfig} instance.
          */
         public PWMChannelConfig build() {
-            return instance;
+            return (PWMChannelConfig)Platform.clone(instance);
         }
 
         /**
@@ -162,8 +163,8 @@
          * the defined range.
          */
         public Builder setChannelNumber(int channelNumber) {
+            Utils.checkIntValue(channelNumber);
             instance.channelNumber = channelNumber;
-            instance.checkParameters();
             return this;
         }
 
@@ -177,8 +178,8 @@
          * in the defined range.
          */
         public Builder setControllerNumber(int controllerNumber) {
+            Utils.checkIntValue(controllerNumber);
             instance.controllerNumber = controllerNumber;
-            instance.checkParameters();
             return this;
         }
 
@@ -193,8 +194,8 @@
          * {@code null} and is not configured for output.
          */
         public Builder setOutputConfig(GPIOPinConfig outputConfig) {
+            checkOutput(outputConfig);
             instance.outputConfig = outputConfig;
-            instance.checkParameters();
             return this;
         }
 
@@ -208,8 +209,8 @@
          * defined range.
          */
         public Builder setIdleState(int idleState) {
+            checkIdle(idleState);
             instance.idleState = idleState;
-            instance.checkParameters();
             return this;
         }
 
@@ -227,8 +228,8 @@
          * @see #setScaleFactor
          */
         public Builder setPulsePeriod(int pulsePeriod) {
+            Utils.checkGreaterThanOne(pulsePeriod);
             instance.pulsePeriod = pulsePeriod;
-            instance.checkParameters();
             return this;
         }
 
@@ -241,8 +242,8 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
+            Utils.checkDoubleGreaterThanOne(scaleFactor);
             instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
-            instance.checkParameters();
             return this;
         }
 
@@ -256,8 +257,8 @@
          * defined range.
          */
         public Builder setPulseAlignment(int pulseAlignment) {
+            checkAligment(pulseAlignment);
             instance.pulseAlignment = pulseAlignment;
-            instance.checkParameters();
             return this;
         }
 
@@ -272,8 +273,8 @@
          * the defined range.
          */
         public Builder setOutputBufferSize(int outputBufferSize) {
+            Utils.checkIntValue(outputBufferSize);
             instance.outputBufferSize = outputBufferSize;
-            instance.checkParameters();
             return this;
         }
     }
@@ -366,20 +367,9 @@
     @Deprecated
     public PWMChannelConfig(int controllerNumber, int channelNumber, int idleState, int pulsePeriod,
             int pulseAlignment, GPIOPinConfig output) {
-        // checks for null as well
-        if (output.getDirection() != GPIOPinConfig.DIR_OUTPUT_ONLY &&
-            output.getDirection() != GPIOPinConfig.DIR_BOTH_INIT_OUTPUT){
-            throw new IllegalArgumentException(
-                ExceptionMessage.format(ExceptionMessage.PWM_OUTPUT_PIN_NOT_CONFIGURED)
-            );
-        }
-        this.controllerNumber = controllerNumber;
-        this.channelNumber = channelNumber;
-        this.idleState = idleState;
-        this.pulsePeriod = pulsePeriod;
+        this(controllerNumber, channelNumber, idleState, pulsePeriod, pulseAlignment);
+        checkOutput(output);
         this.outputConfig = output;
-        this.pulseAlignment = pulseAlignment;
-        checkParameters();
     }
 
     /**
@@ -469,19 +459,31 @@
        this.controllerName = controllerName;
     }
 
+    private static void checkOutput(final GPIOPinConfig output) {
+        if (output.getDirection() != GPIOPinConfig.DIR_OUTPUT_ONLY &&
+            output.getDirection() != GPIOPinConfig.DIR_BOTH_INIT_OUTPUT) {
+            throw new IllegalArgumentException(output.toString());
+        }
+    }
+
+    private static void checkIdle(final int idleState) {
+        if (idleState < UNASSIGNED || idleState > IDLE_STATE_LOW) {
+            throw new IllegalArgumentException(Integer.toString(idleState));
+        }
+    }
+
+    private static void checkAligment(final int pulseAlignment) {
+        if ( pulseAlignment < UNASSIGNED || pulseAlignment > ALIGN_RIGHT) {
+            throw new IllegalArgumentException(Integer.toString(pulseAlignment));
+        }
+    }
+
     private void checkParameters(){
-        if ( (controllerNumber  < UNASSIGNED) ||
-             (idleState != UNASSIGNED && idleState != IDLE_STATE_HIGH && idleState != IDLE_STATE_LOW) ||
-             (pulsePeriod < UNASSIGNED || pulsePeriod == 0) ||
-             (pulseAlignment != UNASSIGNED && pulseAlignment != ALIGN_CENTER && pulseAlignment != ALIGN_RIGHT && pulseAlignment != ALIGN_LEFT) ||
-             channelNumber < UNASSIGNED  ||
-             getScaleFactor() < 0.0 ||
-             (outputConfig != null && outputConfig.getDirection() != GPIOPinConfig.DIR_OUTPUT_ONLY
-                    && outputConfig.getDirection() != GPIOPinConfig.DIR_BOTH_INIT_OUTPUT) ||
-             (outputBufferSize < UNASSIGNED)
-            ) {
-            throw new IllegalArgumentException();
-        }
+        Utils.checkIntValue(controllerNumber);
+        Utils.checkIntValue(channelNumber);
+        checkIdle(idleState);
+        Utils.checkGreaterThanOne(pulsePeriod);
+        checkAligment(pulseAlignment);
     }
 
     /**
@@ -497,7 +499,7 @@
      * @since 1.1
      */
     public static PWMChannelConfig deserialize(InputStream in) throws IOException {
-      throw new IOException("Unsupported Operation");
+      return (PWMChannelConfig)Platform.deserialize(in);
     }
 
     /**
@@ -512,7 +514,7 @@
      */
     @Override
     public int serialize(OutputStream  out) throws IOException {
-      throw new IOException("Unsupported Operation");
+      return Platform.serialize(this, out);
     }
 
     /**
--- a/src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/spibus/SPIDeviceConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -30,6 +30,7 @@
 import java.util.Objects;
 
 import com.oracle.dio.impl.Platform;
+import com.oracle.dio.utils.Utils;
 
 import jdk.dio.DeviceConfig;
 import jdk.dio.DeviceManager;
@@ -164,7 +165,9 @@
          * </ul>
          */
         public SPIDeviceConfig build() {
-            instance.checkParameters();
+            if (UNASSIGNED == instance.address) {
+                throw new IllegalStateException();
+            }
             return instance;
         }
 
@@ -193,6 +196,7 @@
          * </ul>
          */
         public Builder setAddress(int address) {
+            Utils.checkGreaterThanOne(address);
             instance.address = address;
             return this;
         }
@@ -208,6 +212,7 @@
          * in the defined range.
          */
         public Builder setControllerNumber(int controllerNumber) {
+            Utils.checkIntValue(controllerNumber);
             instance.controllerNumber = controllerNumber;
             return this;
         }
@@ -224,6 +229,7 @@
          * the defined range.
          */
         public Builder setInputBufferSize(int inputBufferSize) {
+            Utils.checkIntValue(inputBufferSize);
             instance.inputBufferSize = inputBufferSize;
             return this;
         }
@@ -240,6 +246,7 @@
          * in the defined range.
          */
         public Builder setOutputBufferSize(int outputBufferSize) {
+            Utils.checkIntValue(outputBufferSize);
             instance.outputBufferSize = outputBufferSize;
             return this;
         }
@@ -256,6 +263,7 @@
          * defined range.
          */
         public Builder setCSActiveLevel(int csActive) {
+            checkCsActive(csActive);
             instance.csActive = csActive;
             return this;
         }
@@ -273,6 +281,7 @@
          * defined range.
          */
         public Builder setBitOrdering(int bitOrdering) {
+            checkBitOrdering(bitOrdering);
             instance.bitOrdering = bitOrdering;
             return this;
         }
@@ -288,6 +297,7 @@
          * defined range.
          */
         public Builder setClockMode(int clockMode) {
+            checkClockMode(clockMode);
             instance.clockMode = clockMode;
             return this;
         }
@@ -303,6 +313,7 @@
          * defined range.
          */
         public Builder setWordLength(int wordLength) {
+            Utils.checkGreaterThanOne(wordLength);
             instance.wordLength = wordLength;
             return this;
         }
@@ -318,6 +329,7 @@
          * the defined range.
          */
         public Builder setClockFrequency(int clockFrequency) {
+            Utils.checkGreaterThanOne(clockFrequency);
             instance.clockFrequency = clockFrequency;
             return this;
         }
@@ -489,16 +501,10 @@
     @Deprecated
     public SPIDeviceConfig(String controllerName, int address, int csActive, int clockFrequency, int clockMode, int wordLength,
             int bitOrdering) {
+        this(DEFAULT, address, csActive, clockFrequency, clockMode, wordLength, bitOrdering);
         // checks for null
         controllerName.length();
-        this.controllerName = controllerName;
-        this.address = address;
-        this.csActive = csActive;
-        this.clockFrequency = clockFrequency;
-        this.clockMode = clockMode;
-        this.wordLength = wordLength;
-        this.bitOrdering = bitOrdering;
-        checkParameters();
+        this.controllerName  = controllerName;
     }
 
     /**
@@ -514,7 +520,7 @@
      * @since 1.1
      */
     public static SPIDeviceConfig deserialize(InputStream  in) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return (SPIDeviceConfig) Platform.deserialize(in);
     }
 
     /**
@@ -529,7 +535,7 @@
      */
     @Override
     public int serialize(OutputStream  out) throws IOException  {
-      throw new IOException("Unsupported Operation");
+        return Platform.serialize(this, out);
     }
 
     /**
@@ -664,16 +670,30 @@
         return Platform.equals(this, obj);
     }
 
-    private void checkParameters(){
-        if ((DEFAULT > controllerNumber) ||
-            address < 0 ||
-            (csActive != DEFAULT && csActive != CS_ACTIVE_LOW && csActive != CS_ACTIVE_HIGH && csActive != CS_NOT_CONTROLLED) ||
-            (clockFrequency < DEFAULT || clockFrequency == 0) ||
-            (clockMode < 0 || clockMode > 4) ||
-            (wordLength < DEFAULT || wordLength == 0) ||
-            (bitOrdering != DEFAULT && bitOrdering != SPIDevice.BIG_ENDIAN &&
-            bitOrdering != SPIDevice.LITTLE_ENDIAN && bitOrdering != SPIDevice.MIXED_ENDIAN) ) {
-            throw new IllegalArgumentException();
+    private static void checkCsActive(int csActive) {
+        if (csActive < DEFAULT || csActive > CS_NOT_CONTROLLED) {
+            throw new IllegalArgumentException(Integer.toString(csActive));
         }
     }
+
+    private static void checkClockMode(int clockMode) {
+        if (clockMode < 0 || clockMode > 4) {
+            throw new IllegalArgumentException(Integer.toString(clockMode));
+        }
+    }
+
+    private static void checkBitOrdering(int bitOrdering) {
+        if (bitOrdering < DEFAULT || bitOrdering > SPIDevice.MIXED_ENDIAN) {
+            throw new IllegalArgumentException(Integer.toString(bitOrdering));
+        }
+    }
+
+    private void checkParameters(){
+        Utils.checkIntValue(address);
+        Utils.checkGreaterThanOne(clockFrequency);
+        checkCsActive(csActive);
+        checkClockMode(clockMode);
+        checkBitOrdering(bitOrdering);
+        Utils.checkGreaterThanOne(wordLength);
+    }
 }
--- a/src/share/classes/jdk/dio/watchdog/WatchdogTimerConfig.java	Thu Jun 18 16:40:53 2015 +0300
+++ b/src/share/classes/jdk/dio/watchdog/WatchdogTimerConfig.java	Thu Jun 18 18:34:23 2015 +0300
@@ -126,7 +126,7 @@
      * @since 1.1
      */
     public static WatchdogTimerConfig deserialize(InputStream in) throws IOException {
-      throw new IOException("Unsupported Operation");
+        return (WatchdogTimerConfig) Platform.deserialize(in);
     }
 
     /**
@@ -141,7 +141,7 @@
      */
     @Override
     public int serialize(OutputStream out) throws IOException {
-      throw new IOException("Unsupported Operation");
+      return Platform.serialize(this, out);
     }
 
     /**