import java.io.File;
+import org.tizen.emulator.manager.device.xml.template.Device;
import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration;
+import org.tizen.emulator.manager.device.xml.template.DeviceItem;
+import org.tizen.emulator.manager.device.xml.template.ObjectFactory;
import org.tizen.emulator.manager.platform.Profile;
import org.tizen.emulator.manager.platform.ProfileList;
+import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.StringResources;
-import org.tizen.emulator.manager.vms.helper.VMWorkerException;
public class DeviceTemplate {
private File templateFile;
- private long lastModified;
+ private long lastModified = 0;
private DeviceConfiguration conf;
private DeviceTemplateValue value;
+ // for create device template
+ public DeviceTemplate() {
+
+ }
+
public DeviceTemplate(File file, DeviceConfiguration conf) {
this.templateFile = file;
this.lastModified = file.lastModified();
this.conf = conf;
}
- public DeviceTemplate(DeviceTemplateValue value) {
- this.value = value;
- }
-
public void reloadDeviceTemplate() {
DeviceTemplateList.reloadDeviceConfiguration(this);
this.lastModified = templateFile.lastModified();
return lastModified;
}
- public void delete() throws VMWorkerException{
+ /////////////////////////////////////////////////////////////////////////////////////
+ // device template worker
+ // delete, create(clone), modify
+ /////////////////////////////////////////////////////////////////////////////////////
+
+ public void delete() throws DeviceWorkerException{
// lock.acquire
if (!templateFile.exists()) {
- throw new VMWorkerException("Failed to delete device template"
+ throw new DeviceWorkerException("Failed to delete device template"
+ StringResources.NEW_LINE
+ "Device template file does not exist: "
+ StringResources.NEW_LINE
}
if (!templateFile.delete()) {
- throw new VMWorkerException("Failed to delete device template"
+ throw new DeviceWorkerException("Failed to delete device template"
+ StringResources.NEW_LINE
+ "Check your device template file: "
+ StringResources.NEW_LINE
// TODO
Profile profile = ProfileList.getProfile(value.getProfile());
profile.removeDeviceTemplate(this);
+ // lock.release
+ }
+
+ public void modify(DeviceTemplateValue newValue) throws DeviceWorkerException {
+ // lock.acquire
+ if (value.equals(newValue)) {
+ return;
+ }
+
+ DeviceConfiguration newConf = settingConfiguration(newValue);
+ if (newConf != null) {
+ if (DeviceTemplateList.saveDeviceConfiguration(newConf, templateFile)) {
+ this.conf = newConf;
+ this.value = newValue;
+ } else {
+ throw new DeviceWorkerException("Failed to modfiy device template"
+ + StringResources.NEW_LINE
+ + "Check emulator manager log file: "
+ + StringResources.NEW_LINE
+ + FilePathResources.getTizenVmsPath());
+ }
+ }
+ // lock.release
+ }
+ public void create(DeviceTemplateValue newValue) throws DeviceWorkerException {
+ // lock.acquire
+ if (newValue == null) {
+ return;
+ }
+
+ DeviceConfiguration newConf = settingConfiguration(newValue);
+ if (newConf != null) {
+ if (templateFile == null) {
+ String filePath = FilePathResources.getTizenSdkDataDevicePath()
+ + File.separator + newValue.getName() + ".xml";
+ templateFile = new File(filePath);
+ }
+
+ if (DeviceTemplateList.saveDeviceConfiguration(newConf, templateFile)) {
+ this.conf = newConf;
+ this.value = newValue;
+ // TODO
+ Profile profile = ProfileList.getProfile(value.getProfile());
+ profile.addDeviceTemplate(this);
+ } else {
+ throw new DeviceWorkerException("Failed to create device template"
+ + StringResources.NEW_LINE
+ + "Check emulator manager log file: "
+ + StringResources.NEW_LINE
+ + FilePathResources.getTizenVmsPath());
+ }
+ }
// lock.release
}
-}
+
+ private DeviceConfiguration settingConfiguration(DeviceTemplateValue value) {
+ ObjectFactory factory = new ObjectFactory();
+ DeviceConfiguration conf = factory.createDeviceConfiguration();
+ conf.setBaseInformation(factory.createBaseInformation());
+ conf.setDisplay(factory.createDisplay());
+ conf.setRam(factory.createRam());
+ conf.setCpu(factory.createCpu());
+
+ // base information
+ conf.getBaseInformation().setName(value.getName());
+ conf.getBaseInformation().setType(value.getType());
+ conf.getBaseInformation().setProfile(value.getProfile());
+ if (value.getExtenstion() != null && !value.getExtenstion().isEmpty()) {
+ conf.getBaseInformation().setExtension(value.getExtenstion());
+ }
+
+ conf.getBaseInformation().setVersion(value.getVersion());
+ conf.getBaseInformation().setPriority(value.getPriority());
+ if (value.getManufacturer() != null && !value.getManufacturer().isEmpty()) {
+ conf.getBaseInformation().setManufacturer(value.getManufacturer());
+ }
+
+ // display
+ conf.getDisplay().setResolution(factory.createDisplayResolution());
+ conf.getDisplay().getResolution().setWidth(value.getDisplayWidth());
+ conf.getDisplay().getResolution().setHeight(value.getDisplayHeight());
+
+ conf.getDisplay().setScreenSize(factory.createDisplayScreenSize());
+ conf.getDisplay().getScreenSize().setUnit(value.getDisplaySizeUnit());
+ conf.getDisplay().getScreenSize().setValue(value.getDisplaySize());
+
+ conf.getDisplay().setSkin(factory.createDisplaySkin());
+ if (value.getSkin() != null) {
+ conf.getDisplay().getSkin().setName(value.getSkinName());
+ conf.getDisplay().getSkin().setPath(value.getSkinPath());
+ conf.getDisplay().getSkin().setShape(value.getSkinShape().toString());
+ } else {
+ conf.getDisplay().getSkin().setShape(value.getSkinShape().toString());
+ }
+
+ // ram
+ conf.getRam().setSize(factory.createRamSize());
+ conf.getRam().getSize().setUnit(value.getRamSizeUnit());
+ conf.getRam().getSize().setValue(value.getRamSize());
+
+ // cpu count
+ conf.getCpu().setCount(value.getCpuCount());
+
+ // additionalDevices
+ if (value.getAdditionalDevices().size() > 0) {
+ conf.setAdditionalDevices(factory.createAdditionalDevices());
+ conf.getAdditionalDevices().getDevice().clear();
+ for (SubDevice device : value.getAdditionalDevices()) {
+ Device d = new Device();
+ d.setName(device.getName());
+ for (SubDeviceItem item : device.getItems()) {
+ DeviceItem i = new DeviceItem();
+ if (item.getValues() != null && item.getValues().size() > 0) {
+ // TODO
+ }
+
+ i.setId(item.getId());
+ i.setSupport(item.isSupport());
+ if (item.getName() != null && !item.getName().isEmpty()) {
+ i.setName(item.getName());
+ }
+ d.getDeviceItem().add(i);
+ }
+ conf.getAdditionalDevices().getDevice().add(d);
+ }
+ }
+
+ return conf;
+ }
+ }
+++ /dev/null
-/*
- * Emulator Manager
- *
- * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * JiHye Kim <jihye424.kim@samsung.com>
- * Minkee Lee <minkee.lee@samsung.com>
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- * Sangho Park <sangho.p@samsung.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-package org.tizen.emulator.manager.devices;
-
-import org.tizen.emulator.manager.device.xml.template.Device;
-import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration;
-import org.tizen.emulator.manager.device.xml.template.DeviceItem;
-import org.tizen.emulator.manager.device.xml.template.ObjectFactory;
-
-
-public class DeviceTemplateCreator {
- private DeviceTemplate template;
-
- public static DeviceTemplate create(DeviceTemplateValue value) {
- return new DeviceTemplateCreator().createInternal(value);
- }
-
- private DeviceTemplateCreator() {
- }
-
- private DeviceTemplate createInternal(DeviceTemplateValue value) {
- // lock.acquire
- this.template = DeviceTemplateList.createNewDeviceTemplate(value.getName());
- if (template.getTemplateFile().exists()) {
- // TODO
- }
-
- settingConfiguration(value);
-
- DeviceTemplateList.saveDeviceConfiguration(template);
-
- // lock.release
- return template;
- }
-
- private void settingConfiguration(DeviceTemplateValue value) {
- ObjectFactory factory = new ObjectFactory();
- DeviceConfiguration conf = template.getConf();
- conf.setBaseInformation(factory.createBaseInformation());
- conf.setDisplay(factory.createDisplay());
- conf.setRam(factory.createRam());
- conf.setCpu(factory.createCpu());
-
- // base information
- conf.getBaseInformation().setName(value.getName());
- conf.getBaseInformation().setType(value.getType());
- conf.getBaseInformation().setProfile(value.getProfile());
- if (value.getExtenstion() != null && !value.getExtenstion().isEmpty()) {
- conf.getBaseInformation().setExtension(value.getExtenstion());
- }
-
- conf.getBaseInformation().setVersion(value.getVersion());
- conf.getBaseInformation().setPriority(value.getPriority());
- if (value.getManufacturer() != null && !value.getManufacturer().isEmpty()) {
- conf.getBaseInformation().setManufacturer(value.getManufacturer());
- }
-
- // display
- conf.getDisplay().setResolution(factory.createDisplayResolution());
- conf.getDisplay().getResolution().setWidth(value.getDisplayWidth());
- conf.getDisplay().getResolution().setHeight(value.getDisplayHeight());
-
- conf.getDisplay().setScreenSize(factory.createDisplayScreenSize());
- conf.getDisplay().getScreenSize().setUnit(value.getDisplaySizeUnit());
- conf.getDisplay().getScreenSize().setValue(value.getDisplaySize());
-
- if (value.getSkin() != null) {
- conf.getDisplay().setSkin(factory.createDisplaySkin());
- conf.getDisplay().getSkin().setName(value.getSkinName());
- conf.getDisplay().getSkin().setPath(value.getSkinPath());
- }
-
- // ram
- conf.getRam().setSize(factory.createRamSize());
- conf.getRam().getSize().setUnit(value.getRamSizeUnit());
- conf.getRam().getSize().setValue(value.getRamSize());
-
- // cpu count
- conf.getCpu().setCount(value.getCpuCount());
-
- // additionalDevices
- if (value.getAdditionalDevices().size() > 0) {
- conf.setAdditionalDevices(factory.createAdditionalDevices());
- conf.getAdditionalDevices().getDevice().clear();
- for (SubDevice device : value.getAdditionalDevices()) {
- Device d = new Device();
- d.setName(device.getName());
- for (SubDeviceItem item : device.getItems()) {
- DeviceItem i = new DeviceItem();
- if (item.getValues() != null && item.getValues().size() > 0) {
- // TODO
- }
-
- i.setId(item.getId());
- i.setSupport(item.isSupport());
- if (item.getName() != null && !item.getName().isEmpty()) {
- i.setName(item.getName());
- }
- d.getDeviceItem().add(i);
- }
- conf.getAdditionalDevices().getDevice().add(d);
- }
- }
- }
-}
import javax.xml.transform.stream.StreamSource;
import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration;
-import org.tizen.emulator.manager.device.xml.template.ObjectFactory;
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.StringResources;
template.setConf(conf);
}
- public static DeviceTemplate createNewDeviceTemplate(String name) {
- String templateFilePath = FilePathResources.getTizenSdkDataDevicePath()
- + File.separator + name + ".xml";
- File templateFile = new File(templateFilePath);
- DeviceConfiguration conf = new ObjectFactory().createDeviceConfiguration();
-
- return new DeviceTemplate(templateFile, conf);
- }
-
- public static boolean saveDeviceConfiguration(DeviceTemplate template) {
- return saveDeviceConfiguration(template, null);
- }
-
- public static boolean saveDeviceConfiguration(DeviceTemplate template, File outputFile) {
- if (outputFile == null) {
- outputFile = template.getTemplateFile();
- }
- return storeXML(template.getConf(), outputFile);
+ public static boolean saveDeviceConfiguration(DeviceConfiguration conf, File outputFile) {
+ return storeXML(conf, outputFile);
}
private synchronized static List<DeviceTemplate> loadTemplates() {
import org.tizen.emulator.manager.platform.Skin;
import org.tizen.emulator.manager.resources.StringResources;
import org.tizen.emulator.manager.vms.RESOLUTION;
+import org.tizen.emulator.manager.vms.SKIN_SHAPE;
public class DeviceTemplateValue implements Cloneable {
private DeviceTemplate template;
private boolean isStandard = false;
private String name = "";
- private String type = "";
+ private String type = "custom";
private String profile = "";
private String extenstion = "";
// standard = 1, custom = 3 (1 > 3)
private int priority = 3;
- private String version = "1.0.0";
+ private double version = 1.0;
private String manufacturer = "";
private String skinName = "";
private String skinPath = "";
+ private SKIN_SHAPE skinShape = SKIN_SHAPE.SQUARE;
private Skin skin;
private String ramSizeUnit = "MB";
for (RESOLUTION r : RESOLUTION.values()) {
if (r.getResolution().getWidth() == displayWidth
- && r.getResolution().getHeight() == displayHeight
- && r.getDPI() == displayDPI) {
+ && r.getResolution().getHeight() == displayHeight) {
resolution = r;
break;
}
}
+
if (resolution == null) {
resolution = new RESOLUTION(displayWidth, displayHeight, "", displayDPI);
}
-
if (conf.getDisplay().getSkin() != null) {
skinName = conf.getDisplay().getSkin().getName();
skinPath = conf.getDisplay().getSkin().getPath();
+ String shape = conf.getDisplay().getSkin().getShape();
+ if (shape != null && !shape.isEmpty()) {
+ skinShape = SKIN_SHAPE.find(shape);
+ }
}
if (skinPath != null && !skinPath.isEmpty()) {
skin = null;
EMLogger.getLogger().warning("Failed to create skin." + e.getMessage()); //$NON-NLS-1$
}
+ // TODO
+ if (skin != null) {
+ skinShape = skin.getSkinShape();
+ }
}
}
public void setType(String type) {
this.type = type;
+ if (type.equals("standard")) {
+ isStandard = true;
+ } else {
+ isStandard = false;
+ }
}
public String getExtenstion() {
this.priority = priority;
}
- public String getVersion() {
+ public double getVersion() {
return version;
}
- public void setVersion(String version) {
+ public void setVersion(double version) {
this.version = version;
}
+ public void updateVersion() {
+ this.version += 0.1;
+ }
+
public String getManufacturer() {
return manufacturer;
}
this.skinPath = skinPath;
}
+ public SKIN_SHAPE getSkinShape() {
+ return skinShape;
+ }
+
+ public void setSkinShape(SKIN_SHAPE skinShape) {
+ this.skinShape = skinShape;
+ }
+
public Skin getSkin() {
return skin;
}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.devices;
+
+public class DeviceWorkerException extends Exception {
+ private static final long serialVersionUID = 6587341790567612630L;
+ // for redrawing view
+ private boolean needRefresh = false;
+
+ public DeviceWorkerException(String message) {
+ this(message, false);
+ }
+
+ public DeviceWorkerException(String message, boolean needRefresh) {
+ super(message);
+ this.needRefresh = needRefresh;
+ }
+
+ public boolean isNeedRefresh() {
+ return needRefresh;
+ }
+
+ public void setNeedRefresh(boolean needRefresh) {
+ this.needRefresh = needRefresh;
+ }
+}