SMP: Added SMP option and non-UG checking.
authorminkee.lee <minkee.lee@samsung.com>
Fri, 5 Dec 2014 07:51:34 +0000 (16:51 +0900)
committerjinhyung.jo <jinhyung.jo@samsung.com>
Wed, 28 Jan 2015 05:26:59 +0000 (14:26 +0900)
Change-Id: I53eb7a481be374edd5041b91214d9a3fb31360a7
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
common-project/src/org/tizen/emulator/manager/tool/CheckVirtualization.java
common-project/src/org/tizen/emulator/manager/ui/detail/item/CommonItemListFactory.java
common-project/src/org/tizen/emulator/manager/ui/detail/item/property/ProcessorViewItem.java [new file with mode: 0644]
common-project/src/org/tizen/emulator/manager/vms/VMWorkerCommon.java

index 8c42e70..26d7003 100644 (file)
@@ -58,6 +58,7 @@ public class CheckVirtualization {
 
        private static boolean isCheck = false;
        private static boolean isGallium = false; // for ubuntu OS
+       private static boolean isNonUG = false; // non-UG mode
 
 
        private CheckVirtualization() {
@@ -80,6 +81,10 @@ public class CheckVirtualization {
                return isGallium;
        }
 
+       public boolean isNonUG() {
+               return isNonUG;
+       }
+
        public String getVirtualizationEnableCommnad() {
                return virtualization_enable_command;
        }
@@ -169,10 +174,16 @@ public class CheckVirtualization {
 
                                if(exitValue == 0) {
                                        isVirtualizationSupport = true;
+
+                               } else if (exitValue == 1 ) {
+                                       isVirtualizationSupport = true;
+                                       isNonUG = true;
+
                                } else {
                                        isVirtualizationSupport = false;
                                }
                                virtualization_enable_command = "-enable-hax";
+
                        } else if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) {
                                if(new File("/dev/kvm").canRead()) {
                                        isVirtualizationSupport = true;
index 39d12db..406f192 100644 (file)
@@ -43,6 +43,7 @@ import org.tizen.emulator.manager.ui.detail.item.property.DisplayViewItem;
 import org.tizen.emulator.manager.ui.detail.item.property.FileShareViewItem;
 import org.tizen.emulator.manager.ui.detail.item.property.HWSupportViewItem;
 import org.tizen.emulator.manager.ui.detail.item.property.MaxTouchViewItem;
+import org.tizen.emulator.manager.ui.detail.item.property.ProcessorViewItem;
 import org.tizen.emulator.manager.ui.detail.item.property.RamSizeItem;
 import org.tizen.emulator.manager.ui.detail.item.property.VMNameViewItem;
 import org.tizen.emulator.manager.ui.detail.item.template.CheckLabelViewItem;
@@ -60,13 +61,14 @@ import org.tizen.emulator.manager.vms.xml.template.PropertyList;
 
 public abstract class CommonItemListFactory implements IItemListFactory{
 
-       protected static String ITEM_VM_NAME = "vmName";
-       protected static String ITEM_BASE_IMAGE = "baseImage";
-       protected static String ITEM_DISPLAY = "display";
-       protected static String ITEM_RAM_SIZE = "ramSize";
-       protected static String ITEM_MAX_TOUCH = "maxTouch";
-       protected static String ITEM_FILE_SHARE = "fileShare";
-       protected static String ITEM_HW_SUPPORT = "hwSupport";
+       public static String ITEM_VM_NAME = "vmName";
+       public static String ITEM_BASE_IMAGE = "baseImage";
+       public static String ITEM_DISPLAY = "display";
+       public static String ITEM_RAM_SIZE = "ramSize";
+       public static String ITEM_MAX_TOUCH = "maxTouch";
+       public static String ITEM_FILE_SHARE = "fileShare";
+       public static String ITEM_HW_SUPPORT = "hwSupport";
+       public static String ITEM_PROCESSORS = "processors";
 
        public static ObjectFactory factory = new ObjectFactory();
 
@@ -97,6 +99,9 @@ public abstract class CommonItemListFactory implements IItemListFactory{
                                } else if (itemName.equals(ITEM_DISPLAY)) {
                                        itemList.add(new DisplayViewItem(item, currentLineLabel));
 
+                               } else if (itemName.equals(ITEM_PROCESSORS)) {
+                                       itemList.add(new ProcessorViewItem(item, currentLineLabel));
+
                                } else if (itemName.equals(ITEM_RAM_SIZE)) {
                                        itemList.add(new RamSizeItem(item, currentLineLabel));
 
diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/ProcessorViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/ProcessorViewItem.java
new file mode 100644 (file)
index 0000000..12e89a3
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * Sangho Park <sangho1206.park@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.ui.detail.item.property;
+
+import java.util.List;
+
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.tizen.emulator.manager.tool.CheckVirtualization;
+import org.tizen.emulator.manager.ui.StatusBar;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.vms.CPU;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+import org.tizen.emulator.manager.vms.xml.template.Option;
+
+public class ProcessorViewItem extends ComboViewItem {
+
+       public ProcessorViewItem(Item template, LineLabelViewItem lineLabelViewItem) {
+               super(template, lineLabelViewItem);
+               COMBOBOX_WIDTH = 135;
+       }
+
+       @Override
+       protected void parseOption(List<Option> optionList) {
+               // make comboOptions
+               for (CPU r : CPU.values()) {
+                       comboOptions.add(r.toString());
+               }
+       }
+
+       @Override
+       public boolean settingDetailItem(VMPropertyValue value) {
+               valueLabel.setText(Integer.toString(value.cpu));
+               return false;
+       }
+
+       @Override
+       public void setValue(VMPropertyValue value) {
+               value.cpu = Integer.parseInt(newValue);
+       }
+
+       @Override
+       protected void addWidgetListener() {
+               combo.addSelectionListener(new SelectionListener() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               newValue = combo.getText();
+
+                               if (!isCreateMode()) {
+                                       getListener().ChangeValue(getThis());
+                                       getListener().changeConfirmButton(getThis());
+                               }
+
+                               if (checkUGWarning()) {
+                                       String msg = "\nPlease use processors 1 at non-UG platform." +
+                                                       "\nMulti-processors might cause VM slower.";
+                                       new MessageDialog().openWarningDialog("Emulator Manager Warning", msg);
+                               }
+                       }
+
+                       @Override
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                               // TODO Auto-generated method stub
+                       }
+               });
+       }
+
+       @Override
+       public boolean settingModifyItem(VMPropertyValue value) {
+
+               newValue = getItemValue(value);
+
+               // makeComboBox
+               if (comboOptions != null) {
+                       if (combo != null) {
+                               combo.removeAll();
+                       }
+                       for(String option : comboOptions) {
+                               combo.add(option);
+                       }
+               }
+
+               if (isCreateMode()) {
+                       if (CheckVirtualization.getInstance().isNonUG()) {
+                               value.cpu = 1;
+
+                       } else {
+                               // set MAX cpu value.
+                               String val = combo.getItem(combo.getItemCount()-1);
+                               int maxNum = Integer.parseInt(val);
+                               if (maxNum > 4) {
+                                       value.cpu = 4; // 4 : target max cpu.
+                               } else {
+                                       value.cpu = maxNum;
+                               }
+                       }
+               }
+               newValue = oldValue = String.valueOf(value.cpu);
+
+               // Select combo-box item.
+               int index=-1;
+               for (int i=0 ; i < comboOptions.size(); i++) {
+                       if (comboOptions.get(i).equals(newValue)) {
+                               index = i;
+                               break;
+                       }
+               }
+               if (comboOptions.size() > 0) {
+                       if (index == -1) {
+                               // if value not matches..
+                               combo.select(0);
+                               newValue = combo.getItem(0);
+                       } else {
+                               combo.select(index);
+                       }
+               }
+               return true;
+       }
+
+       @Override
+       public String getItemValue(VMPropertyValue value) {
+               return String.valueOf(value.cpu);
+       }
+
+       @Override
+       public boolean checkValue() {
+               return true;
+       }
+
+       private boolean checkUGWarning() {
+               if (CheckVirtualization.getInstance().isNonUG()) {
+                       if (Integer.parseInt(newValue) > 1) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+}
index 4f2110c..131a5cd 100644 (file)
@@ -51,6 +51,7 @@ import org.tizen.emulator.manager.vms.helper.QemuImgProc;
 import org.tizen.emulator.manager.vms.helper.VMLauncherException;
 import org.tizen.emulator.manager.vms.helper.VMWorkerException;
 import org.tizen.emulator.manager.vms.helper.WorkerLock;
+import org.tizen.emulator.manager.vms.xml.CpuType;
 
 
 public class VMWorkerCommon {
@@ -149,6 +150,22 @@ public class VMWorkerCommon {
                                                }
                                        }
 
+                                       // Check non-UG mode.
+                                       CpuType cpuOption = property.getConfiguration().getDevice().getCPU();
+                                       if (cpuOption != null) {
+                                               int cpu = cpuOption.getValue().getValue();
+                                               if (CheckVirtualization.getInstance().isNonUG() && cpu > 1) {
+                                                       MessageDialog dialog = new MessageDialog();
+                                                       int response = dialog.openWarningAndSelectionDialog(
+                                                                       "Using multi-processor option might cause VM slower" +
+                                                                       "\nin non-UG platform." +
+                                                                       "\n\n Do you want to continue launching anyway?");
+                                                       if (response != SWT.OK){
+                                                               throw new VMWorkerException("User stops launching emulator.");
+                                                       }
+                                               }
+                                       }
+
                                        isRunningNow();
 
                                        if (!launcher.launch(property, wait)) {