OCI-option: add OCI option
authorminkee.lee <minkee.lee@samsung.com>
Wed, 2 Dec 2015 08:28:20 +0000 (17:28 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 3 Dec 2015 06:52:31 +0000 (15:52 +0900)
This option should be moved to tv plug-in.
(EnumerationOCI.java, OCIDeviceItem.java should be removed)

Change-Id: I8640dd7f41f6677575d19a77ebb23d9b408fd254
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
resource/renewal/res/icon_title_oci_device.png [new file with mode: 0644]
src/org/tizen/emulator/manager/renewal/resources/ColorResources.java
src/org/tizen/emulator/manager/renewal/resources/ImageResources.java
src/org/tizen/emulator/manager/ui/renewal/item/CommonItemListFactory.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/EnumerationOCI.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/OCIDeviceItem.java [new file with mode: 0644]
xsd/x86-standard-template-v2.xml

diff --git a/resource/renewal/res/icon_title_oci_device.png b/resource/renewal/res/icon_title_oci_device.png
new file mode 100644 (file)
index 0000000..765bcb6
Binary files /dev/null and b/resource/renewal/res/icon_title_oci_device.png differ
index dc5af00..5838aae 100644 (file)
@@ -44,7 +44,7 @@ public enum ColorResources {
        GRAY_BTN_NORMAL(149, 159, 164),
        GRAY_BTN_HOVER(149, 159, 164),
        GRAY_BTN_PUSH(100, 110, 144),
-       GRAY_BTN_DISABLE(208, 208, 208),
+       GRAY_BTN_DISABLE(184, 184, 184),
 
        BLUE_BTN(147, 188, 208),
 
index ad1a81c..ca03805 100644 (file)
@@ -282,7 +282,8 @@ public enum ImageResources {
        ICON_TITLE_IMAGE_FILE("icon_title_imagefile"),
        ICON_TITLE_JACK("icon_title_jack"),
        ICON_TITLE_NETWORK("icon_title_network"),
-       ICON_TITLE_OCI_DEVICE("icon_title_ocidevice"),
+       ICON_TITLE_OCI_DEVICE1("icon_title_ocidevice"),
+       ICON_TITLE_OCI_DEVICE2("icon_title_oci_device"),
        ICON_TITLE_SENSOR("icon_title_sensor"),
        ICON_TITLE_TUNER("icon_title_tuner"),
        ICON_TITLE_VERSION("icon_title_version"),
index b7645e1..863d420 100644 (file)
@@ -65,6 +65,7 @@ import org.tizen.emulator.manager.ui.renewal.item.modify.vm.NetProxyItem;
 import org.tizen.emulator.manager.ui.renewal.item.modify.vm.NetTapDeviceItem;
 import org.tizen.emulator.manager.ui.renewal.item.modify.vm.NetTapDeviceItemForWin;
 import org.tizen.emulator.manager.ui.renewal.item.modify.vm.NetworkItem;
+import org.tizen.emulator.manager.ui.renewal.item.modify.vm.OCIDeviceItem;
 
 public class CommonItemListFactory implements IItemListFactory{
 
@@ -226,7 +227,12 @@ public class CommonItemListFactory implements IItemListFactory{
                } else if (name.equals(ItemName.GL_VERSION)) {
                        itemList.add(new GLVersionItem(name, title,
                                        VMTemplateUtil.getOptionMap(item.getOptions())));
+
+               } else if (name.equals(ItemName.OCI_DEVICE)) {
+                       // TODO this may be moved to tv plugin.
+                       itemList.add(new OCIDeviceItem(title));
                }
+
        }
 
 
index e123b86..d29ce48 100644 (file)
@@ -45,6 +45,7 @@ import org.tizen.emulator.manager.platform.Platform;
 import org.tizen.emulator.manager.platform.Skin;
 import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageValue;
 import org.tizen.emulator.manager.ui.renewal.item.ItemName;
+import org.tizen.emulator.manager.vms.OCI;
 import org.tizen.emulator.manager.vms.RESOLUTION;
 import org.tizen.emulator.manager.vms.SKIN_SHAPE;
 import org.tizen.emulator.manager.vms.VMOption;
@@ -603,6 +604,32 @@ public class PropertyValue {
                }
        }
 
+       public void setOCIOption(String ociOption) {
+               if (isVMValue()) {
+                       vmValue.ociOptions = ociOption;
+               }
+       }
+
+       public String getOCIOption() {
+               if (isVMValue()) {
+                       return vmValue.ociOptions;
+               }
+               return "";
+       }
+
+       public void setOCIDevice(OCI ociDevice) {
+               if (isVMValue()) {
+                       vmValue.ociDevice = ociDevice;
+               }
+       }
+
+       public OCI getOCIDevice() {
+               if (isVMValue()) {
+                       return vmValue.ociDevice;
+               }
+               return null;
+       }
+
 
 //     public
 /*
diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/EnumerationOCI.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/EnumerationOCI.java
new file mode 100644 (file)
index 0000000..db205a3
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye424.kim@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.ui.renewal.item.modify.vm;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.resources.FilePathResources;
+import org.tizen.emulator.manager.resources.StringResources;
+
+public class EnumerationOCI {
+       public int bus;  // vender id
+       public int addr; // product id
+       public String deviceName;
+       private static boolean isSuccess = false;
+       static {
+               if (EmulatorManager.isLinux()) {
+                       try {
+                               // TODO
+                               String libPath = FilePathResources.getToolEmulatorBinPath();
+                               System.load(libPath + File.separator + "libEnumerationOCI.so");
+                               isSuccess = true;
+                       } catch (UnsatisfiedLinkError e) {
+                               System.err.println("Native code library(EnumerationOCI) failed to load.." //$NON-NLS-1$
+                                               + StringResources.NEW_LINE + "Error: " + e.getMessage());
+                               EMLogger.getLogger().warning("Native code library(EnumerationOCI) failed to load.." //$NON-NLS-1$
+                                               + StringResources.NEW_LINE + "Error: " + e.getMessage()); //$NON-NLS-1$
+                       }
+               }
+       }
+
+       public static boolean isSuccessToLoadLib() {
+               return EnumerationOCI.isSuccess;
+       }
+
+       @ Override
+       public String toString() {
+               return deviceName;
+       }
+
+       public String getName() {
+               return deviceName;
+       }
+
+       public void setName(String deviceName) {
+               this.deviceName = deviceName;
+       }
+
+       public void setBus(int bus) {
+               this.bus = bus;
+       }
+
+       public int getBus() {
+               return bus;
+       }
+
+       public void setAddr(int addr) {
+               this.addr = addr;
+       }
+
+       public int getAddr() {
+               return addr;
+       }
+
+       public static native ArrayList<EnumerationOCI> getEnumerationOCIDevice();
+}
diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/OCIDeviceItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/vm/OCIDeviceItem.java
new file mode 100644 (file)
index 0000000..126b862
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye424.kim@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.ui.renewal.item.modify.vm;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.eclipse.swt.widgets.Composite;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.ui.renewal.item.ItemName;
+import org.tizen.emulator.manager.ui.renewal.item.modify.common.ComboItem;
+import org.tizen.emulator.manager.ui.renewal.item.modify.common.ModifyDialogItem;
+import org.tizen.emulator.manager.ui.renewal.item.modify.comp.ModifyItem;
+import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue;
+import org.tizen.emulator.manager.ui.renewal.widgets.ComboBox;
+import org.tizen.emulator.manager.vms.OCI;
+import org.tizen.emulator.manager.vms.OCIList;
+
+public class OCIDeviceItem extends ComboItem {
+
+       private String ociOption = "";
+       private final int COMBO_WIDTH = 232;
+
+       private OCI newOCIDevice;
+       ArrayList<OCI> enumerationOCIDeviceList = OCIList.getInstance().getOCIList();
+       ArrayList<OCI> selectedOciDevicesList = OCIList.getInstance().getOCISelectList();
+       public static String VALUE_NONE = "(None)"; //$NON-NLS-1$
+
+       public OCIDeviceItem(String title) {
+               super(ItemName.OCI_DEVICE, title);
+       }
+
+
+       @Override
+       public void create(Composite parent) {
+               item = new ModifyItem(this);
+               item.init(parent);
+               item.setItemTitle(createIconTitle(item, ImageResources.ICON_TITLE_OCI_DEVICE1));
+               item.create();
+
+               makeBody();
+
+       }
+
+       private void createDetailItem() {
+               createDetailItem(ociOption);
+       }
+
+       protected void makeBody() {
+               if (getItemListComp().isDetailMode()) {
+                       createDetailItem();
+                       return;
+               }
+
+               // create combo
+               createCombo(item, COMBO_WIDTH);
+               initComboList();
+       }
+
+       private void initComboList() {
+               if (!EmulatorManager.isMac()) {
+                       try {
+                               scanOCIDevice();
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                               EMLogger.getLogger().warning("failed scan OCI Device...." //$NON-NLS-1$
+                                               + StringResources.NEW_LINE + "Error: " + e.getMessage()); //$NON-NLS-1$
+                       } catch (UnsatisfiedLinkError e) {
+                               e.printStackTrace();
+                               EMLogger.getLogger().warning("failed scan OCI Device...." //$NON-NLS-1$
+                                               + StringResources.NEW_LINE + "Error: " + e.getMessage()); //$NON-NLS-1$
+                       }
+               }
+
+               if (ociOption.equals(VALUE_NONE) || ociOption.equals(" ")) { //$NON-NLS-1$
+
+               } else {
+                       selectedOciDevicesList.removeAll(selectedOciDevicesList);
+                       String device = setOLDDevice(ociOption);
+                       ociOption = device;
+               }
+
+               addComboItem(VALUE_NONE);
+               for (int i = 0; i < OCIList.getInstance().getOCICount(); i++) {
+                       addComboItem(enumerationOCIDeviceList.get(i).getName());
+               }
+
+               selectItem();
+       }
+
+
+       private void selectItem() {
+               int index = 0;
+               for (int i = 0; i < comboBox.getItemCount(); i++) {
+                       if (getComboItemList().get(i).equals(ociOption)) {
+                               index = i;
+                               break;
+                       }
+               }
+               selectComboItem(index, false);
+               comboSelected();
+       }
+
+       @Override
+       public void setInitialValue(PropertyValue value) {
+               if (!EmulatorManager.isMac()) {
+                       try {
+                               scanOCIDevice();
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                               EMLogger.getLogger().warning("failed scan OCI Device...." //$NON-NLS-1$
+                                               + StringResources.NEW_LINE + "Error: " + e.getMessage()); //$NON-NLS-1$
+                       } catch (UnsatisfiedLinkError e) {
+                               e.printStackTrace();
+                               EMLogger.getLogger().warning("failed scan OCI Device...." //$NON-NLS-1$
+                                               + StringResources.NEW_LINE + "Error: " + e.getMessage()); //$NON-NLS-1$
+                       }
+               }
+               newOCIDevice = value.getOCIDevice();
+
+               String ociValue = value.getOCIOption();
+
+               String device = null;
+               if (ociValue != null && !ociValue.equals(VALUE_NONE) && !ociValue.equals(" ")) { //$NON-NLS-1$
+                       device = setOLDDevice(ociValue);
+               }
+
+               if (OCIList.getInstance().findOCIDeviceName(device) != null) {
+                       ociOption = ociValue;
+
+               } else {
+                       ociOption = VALUE_NONE;
+               }
+
+
+       }
+
+       @Override
+       public void setValue(PropertyValue value) {
+               value.setOCIDevice(newOCIDevice);
+               value.setOCIOption(ociOption);
+       }
+
+       @Override
+       public ModifyDialogItem cloneItem() {
+               return new OCIDeviceItem(getTitle());
+       }
+
+       @Override
+       public void itemSelected(ComboBox comboBox) {
+               // This is called when combo item is selected
+               if (comboBox.getSelectionIndex() != 0) {
+                       selectedOciDevicesList.removeAll(selectedOciDevicesList);
+                       selectedOciDevicesList.add(enumerationOCIDeviceList.get(comboBox.getSelectionIndex() - 1));
+
+                       ociOption = selectedOciDevicesList.get(0).getName();
+               } else {
+                       ociOption = VALUE_NONE;
+               }
+
+               comboSelected();
+       }
+
+
+       private void comboSelected() {
+               getItemListComp().checkValid();
+       }
+
+
+       public void scanOCIDevice() throws IOException {
+               enumerationOCIDeviceList.removeAll(enumerationOCIDeviceList);
+               selectedOciDevicesList.removeAll(selectedOciDevicesList);
+
+               ArrayList<EnumerationOCI> deviceList = null;
+
+               if (EnumerationOCI.isSuccessToLoadLib()) {
+                       deviceList = EnumerationOCI.getEnumerationOCIDevice();
+               }
+
+               if (deviceList != null) {
+                       for (int i = 0; i < deviceList.size(); i++) {
+                               //System.out.println("name : " + deviceList.get(i).getName() + ", addr : "+deviceList.get(i).getAddr() + ", bus : " + deviceList.get(i).getBus());
+                               OCIList.getInstance().makeOCIList(deviceList.get(i).getName(), deviceList.get(i).getAddr(), deviceList.get(i).getBus());
+                       }
+               }
+       }
+
+
+       public String setOLDDevice(String ociOptions) {
+               String device = null;
+
+               StringTokenizer s = new StringTokenizer(ociOptions, ","); //$NON-NLS-1$
+               while (s.hasMoreTokens()) {
+                       device = s.nextToken();
+
+                       if (OCIList.getInstance().findOCIDeviceName(device) != null) {
+                                       selectedOciDevicesList.add(OCIList.getInstance().findOCIDeviceName(device));
+                       }
+               }
+               return device;
+       }
+
+
+}
index 420b50a..2e8244e 100644 (file)
                        <option name="experimental">true</option>
                        <option name="defaultOnCreate">Native</option>
                </item>
+<!--           <item name="ociDevice" title="OCI Device" type="combo" /> -->
        </itemGroup>
 
 </ItemList>