From bbab56d38a9e0626a0ef5690ac20f148b107b602 Mon Sep 17 00:00:00 2001 From: jihye kim Date: Thu, 22 Aug 2013 12:17:43 +0900 Subject: [PATCH] add CPU device type Signed-off-by: jihye kim --- .../tizen/emulator/manager/vms/xml/CpuType.java | 165 +++++++++++++++++++++ .../tizen/emulator/manager/vms/xml/DeviceType.java | 29 ++++ .../emulator/manager/vms/xml/ObjectFactory.java | 15 ++ .../src/org/tizen/emulator/manager/vms/CPU.java | 90 +++++++++++ .../org/tizen/emulator/manager/vms/Creator.java | 12 +- .../org/tizen/emulator/manager/vms/Modifier.java | 4 + .../emulator/manager/vms/VMPropertyValue.java | 15 ++ common-project/xsd/em.xsd | 21 +++ 8 files changed, 349 insertions(+), 2 deletions(-) create mode 100644 common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/CpuType.java create mode 100644 common-project/src/org/tizen/emulator/manager/vms/CPU.java diff --git a/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/CpuType.java b/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/CpuType.java new file mode 100644 index 0000000..1e0ce84 --- /dev/null +++ b/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/CpuType.java @@ -0,0 +1,165 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2013.07.22 at 03:22:38 PM KST +// + + +package org.tizen.emulator.manager.vms.xml; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + + +/** + *

Java class for cpuType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="cpuType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="size">
+ *           <complexType>
+ *             <simpleContent>
+ *               <extension base="<http://www.w3.org/2001/XMLSchema>int">
+ *                 <attribute name="unit" use="required">
+ *                   <simpleType>
+ *                     <restriction base="{http://www.w3.org/2001/XMLSchema}NMTOKEN">
+ *                       <enumeration value="MiB"/>
+ *                     </restriction>
+ *                   </simpleType>
+ *                 </attribute>
+ *               </extension>
+ *             </simpleContent>
+ *           </complexType>
+ *         </element>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "cpuType", propOrder = { + "value" +}) +public class CpuType { + + @XmlElement(required = true) + protected CpuType.Value value; + + /** + * Gets the value of the size property. + * + * @return + * possible object is + * {@link CpuType.Size } + * + */ + public CpuType.Value getUsed() { + return value; + } + + /** + * Sets the value of the size property. + * + * @param value + * allowed object is + * {@link CpuType.Size } + * + */ + public void setUsed(CpuType.Value value) { + this.value = value; + } + + + /** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+     * <complexType>
+     *   <simpleContent>
+     *     <extension base="<http://www.w3.org/2001/XMLSchema>int">
+     *       <attribute name="unit" use="required">
+     *         <simpleType>
+     *           <restriction base="{http://www.w3.org/2001/XMLSchema}NMTOKEN">
+     *             <enumeration value="MiB"/>
+     *           </restriction>
+     *         </simpleType>
+     *       </attribute>
+     *     </extension>
+     *   </simpleContent>
+     * </complexType>
+     * 
+ * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "value" + }) + public static class Value { + + @XmlValue + protected int value; + @XmlAttribute(required = true) + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + protected String unit; + + /** + * Gets the value of the value property. + * + */ + public int getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + */ + public void setValue(int value) { + this.value = value; + } + + /** + * Gets the value of the unit property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getUnit() { + return unit; + } + + /** + * Sets the value of the unit property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setUnit(String value) { + this.unit = value; + } + + } + +} diff --git a/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/DeviceType.java b/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/DeviceType.java index 051e650..5e7999b 100644 --- a/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/DeviceType.java +++ b/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/DeviceType.java @@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlType; * <sequence> * <element name="display" type="{http://www.tizen.org/em}displayType"/> * <element name="storage" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="CPU" type="{http://www.tizen.org/em}cpuType"/> * <element name="RAM" type="{http://www.tizen.org/em}ramType"/> * <element name="touch" type="{http://www.tizen.org/em}touchType" minOccurs="0"/> * </sequence> @@ -40,6 +41,7 @@ import javax.xml.bind.annotation.XmlType; @XmlType(name = "deviceType", propOrder = { "display", "storage", + "cpu", "ram", "touch" }) @@ -49,9 +51,12 @@ public class DeviceType { protected DisplayType display; @XmlElement(required = true) protected String storage; + @XmlElement(name = "CPU", required = true) + protected CpuType cpu; @XmlElement(name = "RAM", required = true) protected RamType ram; protected TouchType touch; + /** * Gets the value of the display property. @@ -100,6 +105,30 @@ public class DeviceType { public void setStorage(String value) { this.storage = value; } + + /** + * Gets the value of the CPU property. + * + * @return + * possible object is + * {@link CpuType } + * + */ + public CpuType getCPU() { + return cpu; + } + + /** + * Sets the value of the CPU property. + * + * @param value + * allowed object is + * {@link CpuType } + * + */ + public void setCpu(CpuType value) { + this.cpu = value; + } /** * Gets the value of the ram property. diff --git a/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/ObjectFactory.java b/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/ObjectFactory.java index 5f867cd..7d185f0 100644 --- a/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/ObjectFactory.java +++ b/common-project/jaxb_src/org/tizen/emulator/manager/vms/xml/ObjectFactory.java @@ -45,6 +45,14 @@ public class ObjectFactory { } /** + * Create an instance of {@link CpuType } + * + */ + public CpuType createCpuType() { + return new CpuType(); + } + + /** * Create an instance of {@link RamType } * */ @@ -157,6 +165,13 @@ public class ObjectFactory { } /** + * Create an instance of {@link CpuType.Value } + * + */ + public CpuType.Value createCpuTypeValue() { + return new CpuType.Value(); + } + /** * Create an instance of {@link RamType.Size } * */ diff --git a/common-project/src/org/tizen/emulator/manager/vms/CPU.java b/common-project/src/org/tizen/emulator/manager/vms/CPU.java new file mode 100644 index 0000000..e9090ed --- /dev/null +++ b/common-project/src/org/tizen/emulator/manager/vms/CPU.java @@ -0,0 +1,90 @@ +/* + * Emulator Manager + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * SeokYeon Hwang + * JiHye Kim + * YeongKyoon Lee + * + * 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.vms; + +import java.util.ArrayList; +import java.lang.Exception; +import java.lang.Runtime; + +import org.tizen.emulator.manager.logging.EMLogger; + + +public class CPU { + private static int cpuNum; + + private static final ArrayList list; + static{ + list = new ArrayList(); + try { + cpuNum = findTotalCpu(); + } catch (Exception e) { + // TODO Auto-generated catch block + System.out.println("err!!!!!findTotalCpu"); + e.printStackTrace(); + + EMLogger.getLogger().warning("Throw exception: " + e.getMessage()); + EMLogger.printStakTrace(e); + } + + for (int i = 1; i <= cpuNum; i++) { + if(cpuNum % i == 0) { + list.add(new CPU(Integer.toString(i), i)); + } + } + } + + public static ArrayList values() { + + return list; + } + + private String id; + private int value; + + private CPU(String id, int value) { + this.id = id; + this.value = value; + } + + private static int findTotalCpu() throws Exception { + Runtime rt = Runtime.getRuntime(); + int pn = rt.availableProcessors(); + + return pn; + } + + public int getValue() { + return value; + } + + public String toString() { + return id; + } +} diff --git a/common-project/src/org/tizen/emulator/manager/vms/Creator.java b/common-project/src/org/tizen/emulator/manager/vms/Creator.java index 45f21ab..eb717e9 100644 --- a/common-project/src/org/tizen/emulator/manager/vms/Creator.java +++ b/common-project/src/org/tizen/emulator/manager/vms/Creator.java @@ -295,6 +295,13 @@ public class Creator { ec.getDevice().getDisplay().getSkinPath().setPath(newVM.skinPath); } + ////// CPU ////// + ec.getDevice().setCpu(factory.createCpuType()); + + ec.getDevice().getCPU().setUsed(factory.createCpuTypeValue()); + ec.getDevice().getCPU().getUsed().setUnit("cpu"); + ec.getDevice().getCPU().getUsed().setValue(newVM.cpu); + ec.getDevice().setRAM(factory.createRamType()); ec.getDevice().getRAM().setSize(factory.createRamTypeSize()); ec.getDevice().getRAM().getSize().setUnit("MiB"); @@ -311,10 +318,11 @@ public class Creator { /////////OCI DEVICE//////////// if (ec.getOci() != null) { - if(newVM.ociOptions != null) + if(newVM.ociOptions != null) { ec.getOci().setOCIOptions(newVM.ociOptions); - else + } else { ec.getOci().setOCIOptions(""); + } } } diff --git a/common-project/src/org/tizen/emulator/manager/vms/Modifier.java b/common-project/src/org/tizen/emulator/manager/vms/Modifier.java index 6d7251d..0248590 100644 --- a/common-project/src/org/tizen/emulator/manager/vms/Modifier.java +++ b/common-project/src/org/tizen/emulator/manager/vms/Modifier.java @@ -85,6 +85,10 @@ public class Modifier { } } + if (newVM.cpu != oldVM.cpu) { + property.getConfiguration().getDevice().getCPU().getUsed().setValue(newVM.cpu); + } + if (newVM.ramSize != oldVM.ramSize) { property.getConfiguration().getDevice().getRAM().getSize().setValue(newVM.ramSize); } diff --git a/common-project/src/org/tizen/emulator/manager/vms/VMPropertyValue.java b/common-project/src/org/tizen/emulator/manager/vms/VMPropertyValue.java index 5ee3276..5352603 100644 --- a/common-project/src/org/tizen/emulator/manager/vms/VMPropertyValue.java +++ b/common-project/src/org/tizen/emulator/manager/vms/VMPropertyValue.java @@ -73,6 +73,7 @@ public class VMPropertyValue implements Cloneable { public String skinPath; public int ramSize; + public int cpu; public boolean isFileShareSupport; public String fileSharePath; @@ -162,6 +163,7 @@ public class VMPropertyValue implements Cloneable { dest.keyType = this.keyType; dest.ramSize = this.ramSize; + dest.cpu = this.cpu; dest.isFileShareSupport = this.isFileShareSupport; dest.fileSharePath = this.fileSharePath; @@ -208,6 +210,10 @@ public class VMPropertyValue implements Cloneable { return false; } + if(this.cpu != dest.cpu) { + return false; + } + if(this.isFileShareSupport != dest.isFileShareSupport) { return false; } else { @@ -297,6 +303,13 @@ public class VMPropertyValue implements Cloneable { } ramSize = property.getConfiguration().getDevice().getRAM().getSize().getValue(); + + /////// CPU TEST ////// + + if (property.getConfiguration().getDevice().getCPU() != null) { + cpu = property.getConfiguration().getDevice().getCPU().getUsed().getValue(); + } + isHWVirtualization = property.getConfiguration().getUsability().isHwVirtualization() && CheckVirtualization.getInstance().isSupportVirtualization(); isGLAcceleration = property.getConfiguration().getUsability().isHwGLAcceleration() @@ -342,6 +355,8 @@ public class VMPropertyValue implements Cloneable { ramSize = RAM_SIZE.RAM512.getSize(); + cpu = 1; + isFileShareSupport = false; fileSharePath = ""; fileSharePathName = StringResources.None; diff --git a/common-project/xsd/em.xsd b/common-project/xsd/em.xsd index e807bc7..e5a5406 100644 --- a/common-project/xsd/em.xsd +++ b/common-project/xsd/em.xsd @@ -124,6 +124,8 @@ maxOccurs="1" /> + + + + + + + + + + + + + + + + + + + + -- 2.7.4