DeviceTemplate: make device template worker
authorjihye424.kim <jihye424.kim@samsung.com>
Tue, 13 Oct 2015 05:55:36 +0000 (14:55 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Tue, 13 Oct 2015 05:55:36 +0000 (14:55 +0900)
- device template worker (in DeviceTemplate class)
create(clone), modify, delete device template
- make 'DeviceWorkerException' class
- add skin shape property to 'DeviceTemplateValue'

Change-Id: Idc1e92c4e6f7d93564a37431a006c352e18c4d6c
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/devices/DeviceTemplate.java
src/org/tizen/emulator/manager/devices/DeviceTemplateCreator.java [deleted file]
src/org/tizen/emulator/manager/devices/DeviceTemplateList.java
src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java
src/org/tizen/emulator/manager/devices/DeviceWorkerException.java [new file with mode: 0644]

index da7165b..fc284dc 100644 (file)
@@ -32,29 +32,33 @@ package org.tizen.emulator.manager.devices;
 
 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();
@@ -89,10 +93,15 @@ public class DeviceTemplate {
                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
@@ -100,7 +109,7 @@ public class DeviceTemplate {
                }
 
                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
@@ -110,7 +119,134 @@ public class DeviceTemplate {
                // 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;
+       }
+ }
diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateCreator.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateCreator.java
deleted file mode 100644 (file)
index f76bdd3..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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);
-                       }
-               }
-       }
-}
index 43ac5cd..7d3bca8 100644 (file)
@@ -46,7 +46,6 @@ import javax.xml.bind.Unmarshaller;
 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;
@@ -87,24 +86,8 @@ public class DeviceTemplateList {
                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() {
index f03c4f2..3eaee07 100644 (file)
@@ -43,17 +43,18 @@ import org.tizen.emulator.manager.logging.EMLogger;
 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 = "";
 
 
@@ -66,6 +67,7 @@ public class DeviceTemplateValue implements Cloneable {
 
        private String skinName = "";
        private String skinPath = "";
+       private SKIN_SHAPE skinShape = SKIN_SHAPE.SQUARE;
        private Skin skin;
 
        private String ramSizeUnit = "MB";
@@ -142,20 +144,23 @@ public class DeviceTemplateValue implements Cloneable {
 
                        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()) {
@@ -165,6 +170,10 @@ public class DeviceTemplateValue implements Cloneable {
                                        skin = null;
                                        EMLogger.getLogger().warning("Failed to create skin." + e.getMessage()); //$NON-NLS-1$
                                }
+                               // TODO
+                               if (skin != null) {
+                                       skinShape = skin.getSkinShape();
+                               }
                        }
                }
 
@@ -233,6 +242,11 @@ public class DeviceTemplateValue implements Cloneable {
 
        public void setType(String type) {
                this.type = type;
+               if (type.equals("standard")) {
+                       isStandard = true;
+               } else {
+                       isStandard = false;
+               }
        }
 
        public String getExtenstion() {
@@ -259,14 +273,18 @@ public class DeviceTemplateValue implements Cloneable {
                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;
        }
@@ -339,6 +357,14 @@ public class DeviceTemplateValue implements Cloneable {
                this.skinPath = skinPath;
        }
 
+       public SKIN_SHAPE getSkinShape() {
+               return skinShape;
+       }
+
+       public void setSkinShape(SKIN_SHAPE skinShape) {
+               this.skinShape = skinShape;
+       }
+
        public Skin getSkin() {
                return skin;
        }
diff --git a/src/org/tizen/emulator/manager/devices/DeviceWorkerException.java b/src/org/tizen/emulator/manager/devices/DeviceWorkerException.java
new file mode 100644 (file)
index 0000000..03f2129
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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;
+       }
+}