--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+
+}