INTERNAL: refactor Protocol version and Project version management
authorgreatim <jaewon81.lim@samsung.com>
Wed, 24 Jun 2015 15:49:31 +0000 (00:49 +0900)
committergreatim <jaewon81.lim@samsung.com>
Wed, 24 Jun 2015 16:19:39 +0000 (01:19 +0900)
refactor protocol version and project version management (no longer use version value)

Change-Id: I4dbaac445a40307e412da04a2b35e796c38dce7b
Signed-off-by: greatim <jaewon81.lim@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/ProjectVersion.java [new file with mode: 0644]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/protocol/Protocol.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/setting/TargetData.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/DataChannelThread.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/data/FunctionBodyInstrumentData.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/data/LogData.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/data/ProfileData.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/SaveFilesTable.java

index 50548d8..7bee1bd 100644 (file)
@@ -31,8 +31,6 @@ import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
 
 public class AnalyzerConstants {
        // if log change occurs then increase save data version!!
-       public static final String CURRENT_SAVE_FORMAT_VERSION = "1.0"; //$NON-NLS-1$
-       public static final String[] SUPPORTED_SAVE_FORMAT_VERSION = { "1.0" }; //$NON-NLS-1$
        public static final boolean CHECK_INTERNAL = true;
 
        public static final String DA_VERSION = "DA-2014-10-07";
@@ -152,7 +150,7 @@ public class AnalyzerConstants {
        public static final int PAGE_SUMMARY = 7;
        public static final int PAGE_RANGE = 8;
        public static final int PAGE_INTERACTIVE = 9;
-       
+
        /* value for ID */
        public static final int UNKNOWN_ID = -1; // ID resolving is valid, but cannot found
        public static final int INVALID_ID = -2; // ID resolving is not valid
index f749efd..7c14931 100755 (executable)
@@ -94,7 +94,7 @@ public class Project {
        private static final String PROFILE_START_TIME = "profilingStartTime";
        private static final String PAGE_TAB_LIST = "pageTabList";
 
-       private String version = null;
+       private ProjectVersion version = ProjectVersion.VERSION_UNKNOWN;
        private String protocolVersion = null;
        private String device = null;
        private String packageID = null;
@@ -154,11 +154,11 @@ public class Project {
        // *******************************************************
        // getter and setter of primitive project information
        // *******************************************************
-       public String getVersion() {
+       public ProjectVersion getVersion() {
                return version;
        }
 
-       public void setVersion(String version) {
+       public void setVersion(ProjectVersion version) {
                this.version = version;
        }
 
@@ -471,7 +471,7 @@ public class Project {
                        setDevice(CommonConstants.SPACE);
                }
 
-               setVersion(AnalyzerConstants.CURRENT_SAVE_FORMAT_VERSION);
+               setVersion(ProjectVersion.VERSION_LAST);
 
                SimpleDateFormat format = new SimpleDateFormat(DEFAULT_TIME_FORMAT);
                Date date = new Date();
@@ -545,7 +545,7 @@ public class Project {
                }
 
                // initialize variable
-               version = null;
+               version = ProjectVersion.VERSION_UNKNOWN;
                protocolVersion = null;
                device = null;
                packageID = null;
@@ -560,8 +560,8 @@ public class Project {
        }
 
        public boolean isValid() {
-               if (null == getVersion() || null == getAppName() || null == getPackageID()
-                               || null == getDevice()) {
+               if (ProjectVersion.VERSION_UNKNOWN == getVersion() || null == getAppName()
+                               || null == getPackageID() || null == getDevice()) {
                        return false;
                }
                return true;
@@ -753,19 +753,11 @@ public class Project {
                                String infoKey = splitData[0];
                                String val = splitData[1];
                                if (infoKey.equals(VERSION)) {
-                                       String[] vers = AnalyzerConstants.SUPPORTED_SAVE_FORMAT_VERSION;
-                                       int i;
-                                       for (i = 0; i < vers.length; i++) {
-                                               if (vers[i].equals(val)) {
-                                                       break;
-                                               }
-                                       }
-
-                                       if (i == vers.length) {
+                                       ProjectVersion version = ProjectVersion.getVersion(val);
+                                       setVersion(version);
+                                       if (version == ProjectVersion.VERSION_UNKNOWN) {
                                                ret = VERSION;
                                                break;
-                                       } else {
-                                               setVersion(val);
                                        }
                                } else if (infoKey.equals(PROTOCOL_VERSION)) {
                                        setProtocolVersion(val);
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/ProjectVersion.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/ProjectVersion.java
new file mode 100644 (file)
index 0000000..7cd7ac0
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *  Dynamic Analyzer
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Jaewon Lim <jaewon81.lim@samsung.com>
+ * Woojin Jung <woojin2.jung@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ * 
+ */
+package org.tizen.dynamicanalyzer.project;
+
+public enum ProjectVersion {
+       VERSION_UNKNOWN("unknown"),
+       VERSION_10("1.0"),
+       VERSION_20("2.0");
+
+       public static final ProjectVersion VERSION_LAST = VERSION_20;
+
+       private String versionName = null;
+
+       private ProjectVersion(String verName) {
+               this.versionName = verName;
+       }
+
+       @Override
+       public String toString() {
+               return versionName;
+       }
+
+       public static ProjectVersion getVersion(String versionName) {
+               ProjectVersion[] versions = ProjectVersion.values();
+               for (int i = 0; i < versions.length; i++) {
+                       if (versions[i].versionName.equals(versionName)) {
+                               return versions[i];
+                       }
+               }
+
+               return ProjectVersion.VERSION_UNKNOWN;
+       }
+}
index 39a147c..a974312 100644 (file)
@@ -35,11 +35,11 @@ import org.tizen.dynamicanalyzer.protocol.p40.ProtocolConfig40;
 import org.tizen.dynamicanalyzer.setting.Feature;
 
 public enum Protocol {
-       VERSION_30(0, "3.0"),
-       VERSION_40(1, "4.0");
+       VERSION_UNKNOWN(CommonConstants.EMPTY),
+       VERSION_30("3.0"),
+       VERSION_40("4.0");
 
-       private int ID = -1;
-       private String versionName = null;
+       private String versionName;
 
        // data channel message name map for printing debug info
        private static final Map<Integer, String> dataMsgNameMap;
@@ -89,50 +89,33 @@ public enum Protocol {
                dataMsgNameMap = Collections.unmodifiableMap(tempMap);
        }
 
-       private Protocol(int id, String versionName) {
-               this.ID = id;
+       private Protocol(String versionName) {
                this.versionName = versionName;
        }
 
-       public int getID() {
-               return ID;
-       }
-
-       public String getVerionString() {
+       @Override
+       public String toString() {
                return versionName;
        }
 
-       // convert version string to specific integer value equal or greater than zero
-       // return negative value if version string is not found
-       public static int getVersionValue(String versionStr) {
-               Protocol[] versions = Protocol.values();
-               for (Protocol ver : versions) {
-                       if (ver.getVerionString().equals(versionStr)) {
-                               return ver.getID();
-                       }
-               }
-
-               return -1; // not found
-       }
-
-       public static String getVersionString(int protocolValue) {
+       public static Protocol getVersion(String versionString) {
                Protocol[] versions = Protocol.values();
                for (Protocol ver : versions) {
-                       if (ver.getID() == protocolValue) {
-                               return ver.getVerionString();
+                       if (ver.versionName.equals(versionString)) {
+                               return ver;
                        }
                }
 
-               return CommonConstants.EMPTY;
+               return Protocol.VERSION_UNKNOWN; // not found
        }
 
-       public static IProtocolConfig[] getProtocolConfig(int protocolVersion, Feature feature)
+       public static IProtocolConfig[] getProtocolConfig(Protocol protocolVersion, Feature feature)
                        throws UnknownProtocolException {
                IProtocolConfig[] configs = null;
 
-               if (protocolVersion == VERSION_30.getID()) { // protocol 3.0
+               if (protocolVersion == VERSION_30) { // protocol 3.0
                        configs = ProtocolConfig30.getProtocolConfig(feature);
-               } else if (protocolVersion == VERSION_40.getID()) { // protocol 4.0
+               } else if (protocolVersion == VERSION_40) { // protocol 4.0
                        configs = ProtocolConfig40.getProtocolConfig(feature);
                } else { // unknown protocol
                        throw new UnknownProtocolException();
index 3a85d0f..be1a594 100644 (file)
@@ -38,7 +38,7 @@ import org.tizen.dynamicanalyzer.util.Logger;
 public class TargetData {
        /** read information **/
        private String targetName = null;
-       private int protocolVersion = -1;
+       private Protocol protocolVersion = Protocol.VERSION_UNKNOWN;
 
        // available information
        private List<Template> availableTemplateList = new ArrayList<Template>();
@@ -62,7 +62,7 @@ public class TargetData {
                return targetName;
        }
 
-       public int getProtocolVersion() {
+       public Protocol getProtocolVersion() {
                return protocolVersion;
        }
 
@@ -161,7 +161,7 @@ public class TargetData {
        public void makeDetailInformation(String list[]) {
                // written unit test for each of the sub method
                if (list[1].equals(SettingConstants.KEY_PROTOCOL_VERSION)) {
-                       protocolVersion = Protocol.getVersionValue(list[2]);
+                       protocolVersion = Protocol.getVersion(list[2]);
                } else if (list[1].equals(SettingConstants.KEY_AVAILABLE_TEMPLATE_LIST)) {
                        makeAvailableTemplateList(list);
                } else if (list[1].equals(SettingConstants.KEY_SELECTED_TEMPLATE)) {
@@ -233,7 +233,7 @@ public class TargetData {
                // written unit test for each of the sub method
                writer.println(targetName + SettingConstants.WRITE_CSV_SEPARATOR
                                + SettingConstants.KEY_PROTOCOL_VERSION + SettingConstants.WRITE_CSV_SEPARATOR
-                               + Protocol.getVersionString(protocolVersion));
+                               + protocolVersion);
                writer.println(targetName + SettingConstants.WRITE_CSV_SEPARATOR
                                + SettingConstants.KEY_AVAILABLE_TEMPLATE_LIST
                                + SettingConstants.WRITE_CSV_SEPARATOR + writeAvailableTemplateListData());
index feafb97..4016edf 100644 (file)
@@ -61,7 +61,7 @@ public class DataChannelThread extends DataThread<Object> {
        private boolean dropMode = false;
 
        private Socket dataSocket = null;
-       private int protocolVersion = -1;
+       private Protocol protocolVersion = Protocol.VERSION_UNKNOWN;
        private int socketTimeout = -1;
 
        private enum STATE {
@@ -118,7 +118,7 @@ public class DataChannelThread extends DataThread<Object> {
                // set data socket variable
                dataSocket = Global.getCurrentDeviceInfo().getCommunicator().getSubCommunicator()
                                .getDataSocket(0);
-               protocolVersion = Protocol.getVersionValue(Global.getCurrentDeviceInfo().getCommunicator()
+               protocolVersion = Protocol.getVersion(Global.getCurrentDeviceInfo().getCommunicator()
                                .getProtocolVersion());
 
                clearSocketReceiveBuffer();
@@ -168,7 +168,7 @@ public class DataChannelThread extends DataThread<Object> {
        @Override
        public void run() {
                try {
-                       if (dataSocket == null || protocolVersion < 0) {
+                       if (dataSocket == null || protocolVersion == Protocol.VERSION_UNKNOWN) {
                                return; // go to finally block
                        }
 
index 80a25fe..a4685a0 100644 (file)
@@ -62,7 +62,7 @@ public class FunctionBodyInstrumentData extends ProbeCommonData {
        }
 
        public UnsignedInt getVariableID() throws UnsupportedProtocolException {
-               if (protocolVersion != Protocol.VERSION_40.getID()) {
+               if (protocolVersion == Protocol.VERSION_30) {
                        throw new UnsupportedProtocolException();
                }
                return variableID;
@@ -73,7 +73,7 @@ public class FunctionBodyInstrumentData extends ProbeCommonData {
        }
 
        public UnsignedInt getSize() throws UnsupportedProtocolException {
-               if (protocolVersion != Protocol.VERSION_40.getID()) {
+               if (protocolVersion == Protocol.VERSION_30) {
                        throw new UnsupportedProtocolException();
                }
                return size;
@@ -84,7 +84,7 @@ public class FunctionBodyInstrumentData extends ProbeCommonData {
        }
 
        public byte[] getData() throws UnsupportedProtocolException {
-               if (protocolVersion != Protocol.VERSION_40.getID()) {
+               if (protocolVersion == Protocol.VERSION_30) {
                        throw new UnsupportedProtocolException();
                }
                return data;
index 0591816..0253736 100644 (file)
@@ -38,7 +38,7 @@ import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
 public class LogData extends ProtocolParser implements Cloneable {
        public static final LogData END_OF_QUEUE = new LogData();
 
-       protected int protocolVersion = -1;
+       protected Protocol protocolVersion = Protocol.VERSION_UNKNOWN;
 
        protected int msgID = -1;
        protected long seq = -1;
@@ -109,8 +109,8 @@ public class LogData extends ProtocolParser implements Cloneable {
                return (int) (seq ^ (seq >>> 32));
        }
 
-       public void setProtocolVersion(int versionValue) {
-               this.protocolVersion = versionValue;
+       public void setProtocolVersion(Protocol version) {
+               this.protocolVersion = version;
        }
 
        public final int getMsgID() {
index a265da0..810ae50 100644 (file)
@@ -114,7 +114,7 @@ public class ProfileData extends LogData {
                        tid = getInt();
 
                        // removed from protocol 4.0 and later
-                       if (protocolVersion == Protocol.VERSION_30.getID()) {
+                       if (protocolVersion == Protocol.VERSION_30) {
                                probeType = getShort();
                                probeSubType = getShort();
                        }
@@ -131,7 +131,7 @@ public class ProfileData extends LogData {
                        tid = getInt();
 
                        // removed from protocol 4.0 and later
-                       if (protocolVersion == Protocol.VERSION_30.getID()) {
+                       if (protocolVersion == Protocol.VERSION_30) {
                                probeType = getShort();
                                probeSubType = getShort();
                        }
@@ -152,7 +152,7 @@ public class ProfileData extends LogData {
                        break;
                }
 
-               if (protocolVersion != Protocol.VERSION_30.getID()
+               if (protocolVersion != Protocol.VERSION_30
                                || probeType != ProtocolConstants.FUNCTION_TYPE_FILE) {
                        binaryId = Global.getBinaryID(pid, time, pcAddr);
                        if (binaryId == AnalyzerConstants.INVALID_ID) {
@@ -182,7 +182,7 @@ public class ProfileData extends LogData {
        }
 
        public int getProbeType() throws UnsupportedProtocolException {
-               if (protocolVersion == Protocol.VERSION_30.getID()) {
+               if (protocolVersion == Protocol.VERSION_30) {
                        return probeType;
                } else {
                        throw new UnsupportedProtocolException();
@@ -194,7 +194,7 @@ public class ProfileData extends LogData {
        }
 
        public int getProbeSubType() throws UnsupportedProtocolException {
-               if (protocolVersion == Protocol.VERSION_30.getID()) {
+               if (protocolVersion == Protocol.VERSION_30) {
                        return probeSubType;
                } else {
                        throw new UnsupportedProtocolException();
index c01f13b..3959549 100644 (file)
@@ -34,12 +34,12 @@ import java.util.List;
 import org.eclipse.nebula.widgets.grid.GridItem;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
-import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
 import org.tizen.dynamicanalyzer.common.Global;
 import org.tizen.dynamicanalyzer.common.path.PathManager;
 import org.tizen.dynamicanalyzer.model.TableInput;
 import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
 import org.tizen.dynamicanalyzer.project.Project;
+import org.tizen.dynamicanalyzer.project.ProjectVersion;
 import org.tizen.dynamicanalyzer.resources.ColorResources;
 import org.tizen.dynamicanalyzer.ui.widgets.table.DATableComposite;
 import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
@@ -147,10 +147,8 @@ public class SaveFilesTable extends DATableComposite {
                isVaildVersion = true;
                Project project = Project.getProjectInfoFromFile(path);
 
-               String version = project.getVersion();
-               if (null != version
-                               && (version.isEmpty() || !version
-                                               .equals(AnalyzerConstants.CURRENT_SAVE_FORMAT_VERSION))) {
+               ProjectVersion version = project.getVersion();
+               if (version != ProjectVersion.VERSION_LAST) {
                        isVaildVersion = false;
                } else {
                        isVaildVersion = true;