Add missing license headers to packetcable-driver objects
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / objects / MMVersionInfo.java
index 4fa90a58502ea93ae667a9bd8d795e959496471d..9e6cf1fd38911e0ddeea1387d3b18fbc20e67a21 100644 (file)
@@ -1,39 +1,46 @@
-/**
- @header@
+/*
+ * Copyright (c) 2014, 2015 Cable Television Laboratories, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.pcmm.objects;
 
 import org.pcmm.base.impl.PCMMBaseObject;
+import org.umu.cops.stack.COPSMsgParser;
 
 /**
- *
- * PCMM MM version info Object
- *
+ * The Version Info object is used to enable Multimedia applications to adapt their interactions with other devices so
+ * that interoperability can be achieved between products supporting different protocol versions. Both the Major
+ * Version Number and the Minor Version Number are 2 byte unsigned integers. Both the PDP and the PEP must include this
+ * object as specified in Section 6.5.1
  */
 public class MMVersionInfo extends PCMMBaseObject {
 
-    private short majorVersionNB;
-    private short minorVersionNB;
     public static final short DEFAULT_MAJOR_VERSION_INFO = (short) 5;
     public static final short DEFAULT_MINOR_VERSION_INFO = (short) 0;
 
-    public MMVersionInfo() {
-        this(DEFAULT_MAJOR_VERSION_INFO, DEFAULT_MINOR_VERSION_INFO);
-    }
+    /**
+     * The major version number
+     */
+    private final short majorVersionNB;
 
-    public MMVersionInfo(short majorVersionNB, short minorVersionNB) {
-        super((short) 8, (byte) 1, (byte) 16);
-        setShort(this.majorVersionNB = majorVersionNB, (short) 0);
-        setShort(this.minorVersionNB = minorVersionNB, (short) 2);
-    }
+    /**
+     * The minor version number
+     */
+    private final short minorVersionNB;
 
     /**
-     * Parse data and create COPSHandle object
+     * Constructor
+     * @param majorVersionNB - the major version number
+     * @param minorVersionNB - the minor version number
      */
-    public MMVersionInfo(byte[] dataPtr) {
-        super(dataPtr);
-        majorVersionNB = getShort((short) 0);
-        minorVersionNB = getShort((short) 2);
+    public MMVersionInfo(short majorVersionNB, short minorVersionNB) {
+        super(SNum.VERSION_INFO, (byte)1);
+        this.majorVersionNB = majorVersionNB;
+        this.minorVersionNB = minorVersionNB;
     }
 
     /**
@@ -43,14 +50,6 @@ public class MMVersionInfo extends PCMMBaseObject {
         return majorVersionNB;
     }
 
-    /**
-     * @param majorVersionNB
-     *            the majorVersionNB to set
-     */
-    public void setMajorVersionNB(short majorVersionNB) {
-        this.majorVersionNB = majorVersionNB;
-    }
-
     /**
      * @return the minorVersionNB
      */
@@ -58,12 +57,25 @@ public class MMVersionInfo extends PCMMBaseObject {
         return minorVersionNB;
     }
 
+    @Override
+    protected byte[] getBytes() {
+        final byte[] majVerBytes = COPSMsgParser.shortToBytes(majorVersionNB);
+        final byte[] minVerBytes = COPSMsgParser.shortToBytes(minorVersionNB);
+        final byte[] data = new byte[majVerBytes.length + minVerBytes.length];
+        System.arraycopy(majVerBytes, 0, data, 0, majVerBytes.length);
+        System.arraycopy(minVerBytes, 0, data, majVerBytes.length, minVerBytes.length);
+        return data;
+    }
+
     /**
-     * @param minorVersionNB
-     *            the minorVersionNB to set
+     * Returns an MMVersionInfo object from a byte array
+     * @param data - the data to parse
+     * @return - the object
+     * TODO - make me more robust as RuntimeExceptions can be thrown here.
      */
-    public void setMinorVersionNB(short minorVersionNB) {
-        this.minorVersionNB = minorVersionNB;
+    public static MMVersionInfo parse(final byte[] data) {
+        return new MMVersionInfo(COPSMsgParser.bytesToShort(data[0], data[1]),
+                COPSMsgParser.bytesToShort(data[2], data[3]));
     }
 
 }