refactor protocol version and project version management (no longer use version value)
Change-Id: I4dbaac445a40307e412da04a2b35e796c38dce7b
Signed-off-by: greatim <jaewon81.lim@samsung.com>
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";
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
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;
// *******************************************************
// 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;
}
setDevice(CommonConstants.SPACE);
}
- setVersion(AnalyzerConstants.CURRENT_SAVE_FORMAT_VERSION);
+ setVersion(ProjectVersion.VERSION_LAST);
SimpleDateFormat format = new SimpleDateFormat(DEFAULT_TIME_FORMAT);
Date date = new Date();
}
// initialize variable
- version = null;
+ version = ProjectVersion.VERSION_UNKNOWN;
protocolVersion = null;
device = null;
packageID = null;
}
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;
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);
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
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();
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>();
return targetName;
}
- public int getProtocolVersion() {
+ public Protocol getProtocolVersion() {
return protocolVersion;
}
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)) {
// 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());
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 {
// 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();
@Override
public void run() {
try {
- if (dataSocket == null || protocolVersion < 0) {
+ if (dataSocket == null || protocolVersion == Protocol.VERSION_UNKNOWN) {
return; // go to finally block
}
}
public UnsignedInt getVariableID() throws UnsupportedProtocolException {
- if (protocolVersion != Protocol.VERSION_40.getID()) {
+ if (protocolVersion == Protocol.VERSION_30) {
throw new UnsupportedProtocolException();
}
return variableID;
}
public UnsignedInt getSize() throws UnsupportedProtocolException {
- if (protocolVersion != Protocol.VERSION_40.getID()) {
+ if (protocolVersion == Protocol.VERSION_30) {
throw new UnsupportedProtocolException();
}
return size;
}
public byte[] getData() throws UnsupportedProtocolException {
- if (protocolVersion != Protocol.VERSION_40.getID()) {
+ if (protocolVersion == Protocol.VERSION_30) {
throw new UnsupportedProtocolException();
}
return data;
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;
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() {
tid = getInt();
// removed from protocol 4.0 and later
- if (protocolVersion == Protocol.VERSION_30.getID()) {
+ if (protocolVersion == Protocol.VERSION_30) {
probeType = getShort();
probeSubType = getShort();
}
tid = getInt();
// removed from protocol 4.0 and later
- if (protocolVersion == Protocol.VERSION_30.getID()) {
+ if (protocolVersion == Protocol.VERSION_30) {
probeType = getShort();
probeSubType = getShort();
}
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) {
}
public int getProbeType() throws UnsupportedProtocolException {
- if (protocolVersion == Protocol.VERSION_30.getID()) {
+ if (protocolVersion == Protocol.VERSION_30) {
return probeType;
} else {
throw new UnsupportedProtocolException();
}
public int getProbeSubType() throws UnsupportedProtocolException {
- if (protocolVersion == Protocol.VERSION_30.getID()) {
+ if (protocolVersion == Protocol.VERSION_30) {
return probeSubType;
} else {
throw new UnsupportedProtocolException();
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;
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;