From 5738e4e28d43a2a8a4fda933ef278ca73ba0fb57 Mon Sep 17 00:00:00 2001 From: "jihye424.kim" Date: Wed, 15 Jul 2015 13:30:19 +0900 Subject: [PATCH] OCI Device: add oci device view item - add EnumerationOCI.c -> use making oci device list Change-Id: I812bf73e04be9639b22214dc1b78c455a8a93302 Signed-off-by: jihye424.kim --- native-src/EnumerationOCI.c | 127 +++++++++++++ .../emulator/manager/tool/EnumerationOCI.java | 91 +++++++++ .../ui/detail/item/CommonItemListFactory.java | 6 +- .../item/property/OCIDevicesSubViewItem.java | 203 +++++++++++++++++++++ .../ui/detail/item/property/OCIViewItem.java | 79 ++++++++ 5 files changed, 505 insertions(+), 1 deletion(-) create mode 100644 native-src/EnumerationOCI.c create mode 100644 src/org/tizen/emulator/manager/tool/EnumerationOCI.java create mode 100644 src/org/tizen/emulator/manager/ui/detail/item/property/OCIDevicesSubViewItem.java create mode 100644 src/org/tizen/emulator/manager/ui/detail/item/property/OCIViewItem.java diff --git a/native-src/EnumerationOCI.c b/native-src/EnumerationOCI.c new file mode 100644 index 0000000..fde5d52 --- /dev/null +++ b/native-src/EnumerationOCI.c @@ -0,0 +1,127 @@ +#include "org_tizen_emulator_manager_tool_EnumerationOCI.h" +#include + +/* copy from "libvboxusb.h (qemu/tizen/distrib/libvboxusb/inc/libvboxusb.h)" + struct libvbox_usb should be consistent with "libvboxusb.h". + */ + +#define MAX_ENUM_DEVICES 128 +#define MAX_PORTLEN 16 +#define MAX_PROD_NAME 32 + +typedef struct libvbox_usb{ + int bus_num; + int addr; + char port[MAX_PORTLEN]; + int class_id; + int vendor_id; + int product_id; + char product_name[32]; + int speed; +}libvbox_usb; + + +#ifdef __cplusplus +extern "C" { +#endif + int VBOXUSB_enum_devices(libvbox_usb ** opaque); + void VBOXUSB_free(libvbox_usb* opaque); +#ifdef __cplusplus +} +#endif + + +/*JNI*/ + +#define CLASS_ID_HUB 9 + +JNIEXPORT jobject JNICALL Java_org_tizen_emulator_manager_tool_EnumerationOCI_getEnumerationOCIDevice (JNIEnv *env, jclass class) +{ + libvbox_usb *iter, *intern = NULL; + int rc, i; + + jclass class_arraylist = (*env)->FindClass(env, "java/util/ArrayList"); + if (class_arraylist == NULL) { + printf("FindClass(java/util/ArrayList) error \n"); + goto error; + } + jmethodID ctor = (*env)->GetMethodID(env, class_arraylist, "", "()V"); + if (ctor == NULL){ + printf("GetMethodID() error \n"); + goto error; + } + jmethodID add = (*env)->GetMethodID(env, class_arraylist, "add", "(Ljava/lang/Object;)Z"); + if (add == NULL){ + printf("GetMethodID(add) error \n"); + goto error; + } + jobject device_arraylist = (*env)->NewObject(env, class_arraylist, ctor, ""); + if (device_arraylist == NULL) { + printf("NewObject(device_arraylist) error \n"); + goto error; + } + jclass class_enumeration = (*env)->FindClass(env, "org/tizen/emulator/manager/tool/EnumerationOCI"); + if (class_enumeration ==NULL){ + printf("FindClass(Enumeration) error \n"); + goto error; + } + jmethodID enum_ctor = (*env)->GetMethodID(env, class_enumeration, "", "()V"); + if (enum_ctor == NULL) { + printf("GetMethodID(enumeration init) error \n"); + goto error; + } + rc = VBOXUSB_enum_devices(&intern); + if(!rc) { + printf("VBOXUSB_enum_devices error \n"); + goto error; + } + iter = intern; + for(i = 0; i < rc; i++) { + if (iter->class_id != CLASS_ID_HUB) { + jobject device = (*env)->NewObject(env, class_enumeration, enum_ctor, ""); + if (device == NULL) { + printf("NewObject(device) error \n"); + goto error; + } + jfieldID field_pid = (*env)->GetFieldID(env, class_enumeration, "addr", "I"); + jfieldID field_vid = (*env)->GetFieldID(env, class_enumeration, "bus", "I"); + jfieldID field_name = (*env)->GetFieldID(env, class_enumeration, "deviceName", "Ljava/lang/String;"); + if (field_pid == NULL || field_vid == NULL || field_name == NULL) { + printf("GetFieldID(addr, bus, deviceName) error \n"); + goto error; + } + jstring str = (*env)->NewStringUTF(env, iter->product_name); + if (str == NULL) { + printf("NewStringUTF(product_name) error \n"); + goto error; + } + (*env)->SetIntField(env, device, field_pid, iter->product_id); + (*env)->SetIntField(env, device, field_vid, iter->vendor_id); + //(*env)->SetIntField(env, device, field_pid, iter->product_id); + //(*env)->SetIntField(env, device, field_vid, iter->vendor_id); + (*env)->SetObjectField(env, device, field_name, str); + if (!(*env)->CallBooleanMethod(env, device_arraylist, add, device)) { + printf("CallbooleanMethod error \n"); + goto error; + } + + //(*env)->CallObjectMethod(env, device_arraylist, add, device); + } + iter ++; + } + + (*env)->DeleteLocalRef(env, class_enumeration); + (*env)->DeleteLocalRef(env, class_arraylist); + + if(intern != NULL) + VBOXUSB_free(intern); + return device_arraylist ; +error: + (*env)->DeleteLocalRef(env, class_enumeration); + (*env)->DeleteLocalRef(env, class_arraylist); + + if(intern != NULL) + VBOXUSB_free(intern); + return NULL; + +} diff --git a/src/org/tizen/emulator/manager/tool/EnumerationOCI.java b/src/org/tizen/emulator/manager/tool/EnumerationOCI.java new file mode 100644 index 0000000..9bebe2e --- /dev/null +++ b/src/org/tizen/emulator/manager/tool/EnumerationOCI.java @@ -0,0 +1,91 @@ +/* + * Emulator Manager + * + * Copyright (C) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * MunKyu Im + * JiHye Kim + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * 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.tool; + +import java.util.ArrayList; +import org.tizen.emulator.manager.EmulatorManager; +import org.tizen.emulator.manager.logging.EMLogger; +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.isMac()) { + try { + System.loadLibrary("EnumerationOCI"); + isSuccess = true; + } catch (UnsatisfiedLinkError e) { + //System.err.println("Native code library(EnumerationOCI) failed to load"); + EMLogger.getLogger().warning("Native code library(EnumerationOCI) failed to load.." + + StringResources.NEW_LINE + "Error: " + e.getMessage()); + } + } + } + + 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 getEnumerationOCIDevice(); +} diff --git a/src/org/tizen/emulator/manager/ui/detail/item/CommonItemListFactory.java b/src/org/tizen/emulator/manager/ui/detail/item/CommonItemListFactory.java index 7aa0587..4976cb5 100644 --- a/src/org/tizen/emulator/manager/ui/detail/item/CommonItemListFactory.java +++ b/src/org/tizen/emulator/manager/ui/detail/item/CommonItemListFactory.java @@ -53,6 +53,7 @@ import org.tizen.emulator.manager.ui.detail.item.property.NetMacViewItem; import org.tizen.emulator.manager.ui.detail.item.property.NetProxyViewItem; import org.tizen.emulator.manager.ui.detail.item.property.NetTapDeviceViewItem; import org.tizen.emulator.manager.ui.detail.item.property.NetTapDeviceViewItemWin; +import org.tizen.emulator.manager.ui.detail.item.property.OCIViewItem; 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.SuspendSupportViewItem; @@ -204,7 +205,10 @@ public abstract class CommonItemListFactory implements IItemListFactory{ } else if (name.equals(ITEM_TUNER)) { itemList.add(new TunerViewItem(item, currentLineLabel)); - }else if (type.equals(ItemType.TOGGLE.getName())) { + } else if (name.equals(ITEM_OCI_DEVICE)) { + itemList.add(new OCIViewItem(item, currentLineLabel)); + + } else if (type.equals(ItemType.TOGGLE.getName())) { itemList.add(new OnOffViewItem(item, currentLineLabel)); } else if (type.equals(ItemType.LABEL.getName())) { diff --git a/src/org/tizen/emulator/manager/ui/detail/item/property/OCIDevicesSubViewItem.java b/src/org/tizen/emulator/manager/ui/detail/item/property/OCIDevicesSubViewItem.java new file mode 100644 index 0000000..0cbb7fd --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/detail/item/property/OCIDevicesSubViewItem.java @@ -0,0 +1,203 @@ +/* + * Emulator Manager + * + * Copyright (C) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JiHye Kim + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * 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.io.IOException; +import java.util.ArrayList; +import java.util.StringTokenizer; + +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; +import org.tizen.emulator.manager.EmulatorManager; +import org.tizen.emulator.manager.logging.EMLogger; +import org.tizen.emulator.manager.resources.StringResources; +import org.tizen.emulator.manager.tool.EnumerationOCI; +import org.tizen.emulator.manager.ui.detail.item.template.ComboSubViewItem; +import org.tizen.emulator.manager.ui.detail.item.template.LabelViewItem; +import org.tizen.emulator.manager.vms.OCI; +import org.tizen.emulator.manager.vms.OCIList; +import org.tizen.emulator.manager.vms.VMPropertyValue; +import org.tizen.emulator.manager.vms.xml.template.Item; + +public class OCIDevicesSubViewItem extends ComboSubViewItem{ + private OCI newOCIDevice; + ArrayList enumerationOCIDeviceList = OCIList.getInstance().getOCIList(); + ArrayList selectedOciDevicesList = OCIList.getInstance().getOCISelectList(); + + public static String VALUE_NONE = "(None)"; + + public OCIDevicesSubViewItem(LabelViewItem parentItem, Composite comp, + Item template) { + super(parentItem, comp, template); + } + + @Override + public void addComboBoxListener() { + combo.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + if (combo.getSelectionIndex() != 0) { + selectedOciDevicesList.removeAll(selectedOciDevicesList); + selectedOciDevicesList.add(enumerationOCIDeviceList.get(combo.getSelectionIndex() - 1)); + + newValue = selectedOciDevicesList.get(0).getName(); + } else { + newValue = VALUE_NONE; + } + + if (!parentItem.isCreateMode()) { + parentItem.getListener().ChangeValue(parentItem.getThis()); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + }); + } + + @Override + public void setValue(VMPropertyValue value) { + value.ociDevice = newOCIDevice; + value.ociOptions = newValue; + } + + @Override + public boolean settingDetailItem(VMPropertyValue value) { + if (!EmulatorManager.isMac()) { + try { + scanOCIDevice(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + EMLogger.getLogger().warning("filed scan OCI Device...." + + StringResources.NEW_LINE + "Error: " + e.getMessage()); + } catch (UnsatisfiedLinkError e) { + e.printStackTrace(); + EMLogger.getLogger().warning("filed scan OCI Device...." + + StringResources.NEW_LINE + "Error: " + e.getMessage()); + } + } + String device = null; + + if (!value.ociOptions.toString().equals(VALUE_NONE) && !value.ociOptions.toString().equals(" ")) { + device = setOLDDevice(value.ociOptions); + } + + if (OCIList.getInstance().findOCIDeviceName(device) != null) { + valueLabel.setText(value.ociOptions); + } else { +// valueLabel.setText(""); + valueLabel.setText(VALUE_NONE); + } + return false; + } + + @Override + public boolean settingModifyItem(VMPropertyValue value) { + if (!EmulatorManager.isMac()) { + try { + scanOCIDevice(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + EMLogger.getLogger().warning("filed scan OCI Device...." + + StringResources.NEW_LINE + "Error: " + e.getMessage()); + } catch (UnsatisfiedLinkError e) { + e.printStackTrace(); + EMLogger.getLogger().warning("filed scan OCI Device...." + + StringResources.NEW_LINE + "Error: " + e.getMessage()); + } + } + newOCIDevice = value.ociDevice; + if (value.ociOptions.toString().equals(VALUE_NONE) || value.ociOptions.toString().equals(" ")) { + oldValue = newValue = value.ociOptions; + } else { + selectedOciDevicesList.removeAll(selectedOciDevicesList); + String device = setOLDDevice(value.ociOptions); + oldValue = newValue = device; + } + + combo.removeAll(); + combo.add(VALUE_NONE); + + for (int i = 0; i < OCIList.getInstance().getOCICount(); i++) { + combo.add(enumerationOCIDeviceList.get(i).getName()); + } + + for (int i = 0; i < combo.getItemCount(); i++) { + if (combo.getItem(i).equals(oldValue)) { + combo.select(i); + break; + } else { + combo.select(0); + } + } + + return true; + } + + public void scanOCIDevice() throws IOException { + enumerationOCIDeviceList.removeAll(enumerationOCIDeviceList); + selectedOciDevicesList.removeAll(selectedOciDevicesList); + + ArrayList 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, ","); + while (s.hasMoreTokens()) { + device = s.nextToken(); + + if (OCIList.getInstance().findOCIDeviceName(device) != null) { + selectedOciDevicesList.add(OCIList.getInstance().findOCIDeviceName(device)); + } + } + return device; + } + +} diff --git a/src/org/tizen/emulator/manager/ui/detail/item/property/OCIViewItem.java b/src/org/tizen/emulator/manager/ui/detail/item/property/OCIViewItem.java new file mode 100644 index 0000000..8ed53f4 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/detail/item/property/OCIViewItem.java @@ -0,0 +1,79 @@ +/* + * Emulator Manager + * + * Copyright (C) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * MunKyu Im + * JiHye Kim + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * 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.ArrayList; +import java.util.List; + +import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem; +import org.tizen.emulator.manager.ui.detail.item.template.DetailSubViewItem; +import org.tizen.emulator.manager.ui.detail.item.template.LabelViewItem; +import org.tizen.emulator.manager.vms.xml.template.Item; + +public class OCIViewItem extends LabelViewItem{ + + public static String ITEM_DEVICES = "devices"; + + public OCIViewItem(Item template, LineLabelViewItem lineLabelViewItem) { + super(template, lineLabelViewItem); + } + + protected List getSubItemList() { + if (subItemList == null) { + subItemList = new ArrayList(); + + List itemList = template.getItem(); + int i=0; + for (Item item : itemList) { + String itemName = item.getName(); + if (itemName.equals(ITEM_DEVICES)) { + subItemList.add(new OCIDevicesSubViewItem(this, compList.get(i++), item)); + } + } + } + return subItemList; + } + + // TODO + protected int getSubItemCount(Item template) { + List itemList = template.getItem(); + int count = 0; + for (Item item : itemList) { + String itemName = item.getName(); + if (itemName.equals(ITEM_DEVICES)) { + count++; + } + } + return count; + } + +} -- 2.7.4