net: Support bridged network on macosx
authorMunkyu Im <munkyu.im@samsung.com>
Wed, 4 Mar 2015 09:49:05 +0000 (18:49 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Sat, 2 May 2015 07:23:00 +0000 (16:23 +0900)
Emulator Manager supports use bridged network now.
supported only wired network(en0) currently.

Change-Id: I0dfa0f6fea9884380e1ebe7d4ceb8ffe31c3e7a8
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
common-project/src/org/tizen/emulator/manager/tool/TapUtil.java
common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetTapDeviceViewItem.java
common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForLinux.java
common-project/src/org/tizen/emulator/manager/ui/dialog/TapDeviceDialogForWin.java
plugin-project/mobile-plugin/src/org/tizen/emulator/manager/mobile/ui/detail/ItemListFactory.java [new file with mode: 0644]
plugin-project/mobile-plugin/src/org/tizen/emulator/manager/mobile/vms/Launcher.java

index 33e1c33..2923222 100644 (file)
@@ -62,8 +62,7 @@ import com.sun.jna.platform.win32.WinReg.HKEYByReference;
 
 public class TapUtil {
 
-       public static String getBridgeFromDevice(String device)
-                       throws VMWorkerException {
+       public static String getBridgeFromDevice(String device) throws VMWorkerException {
 
                String result = null;
                if (EmulatorManager.isLinux()) {
@@ -98,8 +97,7 @@ public class TapUtil {
                return result;
        }
 
-       public static List<String> getDefaultGateway(String ifName)
-                       throws VMWorkerException {
+       public static List<String> getDefaultGateway(String ifName) throws VMWorkerException {
                List<String> result = new ArrayList<String>();
 
                if (EmulatorManager.isLinux()) {
@@ -118,8 +116,7 @@ public class TapUtil {
 
                                        } else {
                                                if (arr.length >= 5) {
-                                                       if (arr[0].equals("default")
-                                                                       && arr[4].equals(ifName)) {
+                                                       if (arr[0].equals("default") && arr[4].equals(ifName)) {
                                                                result.add(arr[2]);
                                                        }
                                                }
@@ -176,11 +173,17 @@ public class TapUtil {
                        list = getTapListForWin2();
 
                } else if (EmulatorManager.isMac()) {
-                       // TODO
+                       list = getTapListForMac();
                }
                return list;
        }
 
+       private static List<String> getTapListForMac() {
+               List<String> result = new ArrayList<String>();
+               result.add("auto");
+               return result;
+       }
+
        // Use "ip tuntap" command.
        // Result is like below.
        // "tap1: tap one_queue vnet_hdr"
@@ -190,10 +193,7 @@ public class TapUtil {
                List<String> cmd = Arrays.asList("ip", "tuntap");
                ProcessResult res = HelperClass.runProcess(cmd);
                if (res.isSuccess() == false) {
-                       EMLogger.getLogger().warning(
-                                       "Get tap list fail. Command returns fail:" + "cmd : "
-                                                       + cmd.toString() + ", return : "
-                                                       + res.getExitValue());
+                       EMLogger.getLogger().warning("Get tap list fail. Command returns fail:" + "cmd : " + cmd.toString() + ", return : " + res.getExitValue());
                } else {
                        for (String line : res.getStdOutMsg()) {
                                String arr[] = line.split(":");
@@ -213,20 +213,16 @@ public class TapUtil {
        private static List<String> getTapListForWin() {
                List<String> result = new ArrayList<String>();
                List<String> cmd = new ArrayList<String>();
-               ProcessBuilder pb = new ProcessBuilder(new String[] { "openvpn",
-                               "--show-adapters" });
+               ProcessBuilder pb = new ProcessBuilder(new String[] { "openvpn", "--show-adapters" });
                int exitValue = 0;
                Process process;
                try {
                        process = pb.start();
-                       List<String> stdOut = ProcessOutputReader.readStdOut(process,
-                                       cmd.toString());
+                       List<String> stdOut = ProcessOutputReader.readStdOut(process, cmd.toString());
                        exitValue = process.waitFor();
 
                        if (exitValue != 0) {
-                               EMLogger.getLogger().warning(
-                                               "Get tap list fail. Command returns fail:" + "cmd : "
-                                                               + cmd.toString() + ", return : " + exitValue);
+                               EMLogger.getLogger().warning("Get tap list fail. Command returns fail:" + "cmd : " + cmd.toString() + ", return : " + exitValue);
                        } else {
                                for (String line : stdOut) {
                                        if (line.contains("'")) {
@@ -239,13 +235,11 @@ public class TapUtil {
                        }
 
                } catch (IOException e) {
-                       EMLogger.getLogger()
-                                       .warning("Get tap list fail. " + e.getMessage());
+                       EMLogger.getLogger().warning("Get tap list fail. " + e.getMessage());
                        e.printStackTrace();
 
                } catch (InterruptedException e) {
-                       EMLogger.getLogger()
-                                       .warning("Get tap list fail. " + e.getMessage());
+                       EMLogger.getLogger().warning("Get tap list fail. " + e.getMessage());
                        e.printStackTrace();
                }
 
@@ -269,7 +263,7 @@ public class TapUtil {
                                                String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey);
                                                for (String subKey2 : subKeys2) {
                                                        if (subKey2.equals(key)) {
-                                                               String tapName = Advapi32Util.registryGetStringValue(root,  topKey + "\\" + subKey + "\\" + key, value);
+                                                               String tapName = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value);
                                                                if (tapName != null) {
                                                                        EMLogger.getLogger().warning("tapname added: " + tapName);
                                                                        tapNameList.add(tapName);
@@ -295,7 +289,7 @@ public class TapUtil {
 
                List<String> tapIdList = new ArrayList<String>();
                HKEY root = WinReg.HKEY_LOCAL_MACHINE;
-               String topKey= "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
+               String topKey = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
 
                String value1 = "ComponentId";
                String value2 = "NetCfgInstanceId";
@@ -304,8 +298,8 @@ public class TapUtil {
                        regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
                        String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
                        for (String subKey : subKeys) {
-                               String compId = Advapi32Util.registryGetStringValue(root,  topKey + "\\" + subKey, value1);
-                               String tapId = Advapi32Util.registryGetStringValue(root,  topKey + "\\" + subKey, value2);
+                               String compId = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey, value1);
+                               String tapId = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey, value2);
                                if (compId != null && tapId != null) {
                                        if (compId.startsWith("tap")) {
                                                tapIdList.add(tapId);
@@ -343,7 +337,7 @@ public class TapUtil {
                                                        String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey);
                                                        for (String subKey2 : subKeys2) {
                                                                if (subKey2.equals(key)) {
-                                                                       String name = Advapi32Util.registryGetStringValue(root,  topKey + "\\" + subKey + "\\" + key, value);
+                                                                       String name = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value);
                                                                        if (name != null) {
                                                                                if (name.equals(tapName)) {
                                                                                        foundTapId = tapId;
@@ -361,7 +355,7 @@ public class TapUtil {
                                        topKey = "SYSTEM\\CurrentControlSet\\services\\Bridge\\Linkage";
                                }
                                value = "Route";
-                               String valueArr[] = Advapi32Util.registryGetStringArray(root,  topKey, value);
+                               String valueArr[] = Advapi32Util.registryGetStringArray(root, topKey, value);
                                for (String str : valueArr) {
                                        if (str.replace("\"", "").equals(foundTapId)) {
                                                result = true;
@@ -429,10 +423,53 @@ public class TapUtil {
                                        }
                                }
                        }
+               } else if (EmulatorManager.isMac()) {
+                       List<String> cmd = Arrays.asList("/bin/sh", "-c", "ifconfig en0 | grep \"inet \" | awk '{print $4}'");
+                       ProcessResult res = HelperClass.runProcess(cmd);
+                       boolean isCommandSuccess = false;
+                       if (res.isSuccess()) {
+                               for (String str : res.getStdOutMsg()) {
+                                       isCommandSuccess = true;
+                                       long ipAddress = Long.parseLong(str.substring(2), 16);
+                                       netMask = longToIpAddress(ipAddress);
+                                       EMLogger.getLogger().info("netmask en0: " + netMask);
+                               }
+                               if (netMask.length() == 0) {
+                                       isCommandSuccess = false;
+                                       cmd = Arrays.asList("/bin/sh", "-c", "ifconfig bridge1 | grep \"inet \" | awk '{print $4}'");
+                                       res = HelperClass.runProcess(cmd);
+                                       if (res.isSuccess()) {
+                                               for (String str : res.getStdOutMsg()) {
+                                                       isCommandSuccess = true;
+                                                       long ipAddress = Long.parseLong(str.substring(2), 16);
+                                                       netMask = longToIpAddress(ipAddress);
+                                                       EMLogger.getLogger().info("netmask bridge1: " + netMask);
+                                               }
+                                       }
+                               }
+                       }
+                       if (!res.isSuccess() || !isCommandSuccess) {
+                               EMLogger.getLogger().warning(res.getResultMessage());
+                       }
                }
                return netMask;
        }
 
+       private static String longToIpAddress(long ip) {
+               StringBuilder sb = new StringBuilder(15);
+
+               for (int i = 0; i < 4; i++) {
+                       sb.insert(0, Long.toString(ip & 0xff));
+
+                       if (i < 3) {
+                               sb.insert(0, '.');
+                       }
+
+                       ip >>= 8;
+               }
+               return sb.toString();
+       }
+
        private static HKEY getBridgeTcpipKey() {
                HKEY resultKey = null;
                String bridgeId = getBridgeId();
@@ -441,15 +478,14 @@ public class TapUtil {
                }
 
                HKEY root = WinReg.HKEY_LOCAL_MACHINE;
-               String topKey = "SYSTEM\\CurrentControlSet\\services";
+               String topKey = "SYSTEM\\CurrentControlSet\\services";
                HKEYByReference regKey = null;
                try {
                        regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
                        String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
                        for (String subKey : subKeys) {
                                if (subKey.equals(bridgeId)) {
-                                       resultKey = Advapi32Util.registryGetKey(root,
-                                                       topKey + "\\" + subKey + "\\Parameters\\Tcpip", WinNT.KEY_READ).getValue();
+                                       resultKey = Advapi32Util.registryGetKey(root, topKey + "\\" + subKey + "\\Parameters\\Tcpip", WinNT.KEY_READ).getValue();
                                        break;
                                }
                        }
@@ -470,8 +506,7 @@ public class TapUtil {
                HKEY resultKey = null;
 
                HKEY root = WinReg.HKEY_LOCAL_MACHINE;
-               String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces"
-                               + "\\" + ifId;
+               String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces" + "\\" + ifId;
 
                try {
                        resultKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ).getValue();
@@ -486,7 +521,7 @@ public class TapUtil {
                String bridgeId = null;
                if (EmulatorManager.isWin()) {
                        HKEY root = WinReg.HKEY_LOCAL_MACHINE;
-                       String topKey = "SYSTEM\\CurrentControlSet\\services\\BridgeMP";
+                       String topKey = "SYSTEM\\CurrentControlSet\\services\\BridgeMP";
                        String value = "Device";
                        try {
                                String data = Advapi32Util.registryGetStringValue(root, topKey, value);
@@ -542,21 +577,53 @@ public class TapUtil {
                                        }
                                }
                        }
+               } else if (EmulatorManager.isMac()) {
+                       List<String> cmd = Arrays.asList("/bin/sh", "-c", "netstat -rn | grep ^default | awk '{print $2}'");
+                       ProcessResult res = HelperClass.runProcess(cmd);
+                       boolean isCommandSuccess = false;
+                       if (res.isSuccess()) {
+                               for (String str : res.getStdOutMsg()) {
+                                       isCommandSuccess = true;
+                                       gateway = str.trim();
+                                       EMLogger.getLogger().info("gateway: " + gateway);
+                               }
+                       } else if (!res.isSuccess() || !isCommandSuccess) {
+                               EMLogger.getLogger().warning(res.getResultMessage());
+                       }
                }
                return gateway;
        }
 
        public static String getDnsFromTap(String tapName) {
-               String dns="";
+               String dns = "";
                if (EmulatorManager.isLinux()) {
                        dns = getDnsForLinux(tapName);
 
                } else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
                        dns = getDnsForWin(tapName);
+               } else if (EmulatorManager.isMac()) {
+                       dns = getDnsForMac(tapName);
                }
                return dns;
        }
 
+       private static String getDnsForMac(String tapName) {
+               String dnsServer = "";
+               List<String> cmd = Arrays.asList("/bin/sh", "-c", "/usr/sbin/scutil --dns | grep nameserver\\[[0]*\\] | awk '{print $3}' | head -n 1");
+               ProcessResult res = HelperClass.runProcess(cmd);
+               boolean isCommandSuccess = false;
+               if (res.isSuccess()) {
+                       for (String str : res.getStdOutMsg()) {
+                               isCommandSuccess = true;
+                               dnsServer = str.trim();
+                               EMLogger.getLogger().info("dns server: " + dnsServer);
+                       }
+               } else if (!res.isSuccess() || !isCommandSuccess) {
+                       EMLogger.getLogger().warning(res.getResultMessage());
+               }
+               return dnsServer;
+       }
+
        private static String getDnsForLinux(String tapName) {
                String brName = null;
                try {
@@ -611,7 +678,6 @@ public class TapUtil {
                return dns;
        }
 
-
        // return ip, broadcast, mask-length
        public static InterfaceAddress getInterfaceIpInfo(String ifName) {
                Enumeration<NetworkInterface> interfaces;
@@ -621,8 +687,7 @@ public class TapUtil {
                                while (interfaces.hasMoreElements()) {
                                        NetworkInterface current = interfaces.nextElement();
                                        if (current.getName().equals(ifName)) {
-                                               for (InterfaceAddress addr : current
-                                                               .getInterfaceAddresses()) {
+                                               for (InterfaceAddress addr : current.getInterfaceAddresses()) {
                                                        if (addr.getAddress() instanceof Inet4Address) {
                                                                return addr;
                                                        }
@@ -716,14 +781,11 @@ public class TapUtil {
                return isNotExist;
        }
 
-       public static void createTapDevice(String tapName,
-                       ComboViewItem comboViewItem) {
+       public static void createTapDevice(String tapName, ComboViewItem comboViewItem) {
                if (EmulatorManager.isWin()) {
                        MessageDialog msgDialog = new MessageDialog();
-                       msgDialog
-                                       .openNoButtonInfoDialog("Creating tap device.\nThis will take few seconds..");
-                       TapCreateWorker worker = new TapCreateWorker(tapName, msgDialog,
-                                       comboViewItem);
+                       msgDialog.openNoButtonInfoDialog("Creating tap device.\nThis will take few seconds..");
+                       TapCreateWorker worker = new TapCreateWorker(tapName, msgDialog, comboViewItem);
                        worker.start();
                }
 
@@ -737,15 +799,11 @@ public class TapUtil {
                                if (ifAddr != null)
                                        ipAddr = ifAddr.getAddress().getHostAddress();
                        } catch (VMWorkerException e) {
-                               EMLogger.getLogger().warning(
-                                               (new StringBuilder())
-                                                               .append("Failed to get bridge ip address. ")
-                                                               .append(e.getMessage()).toString());
+                               EMLogger.getLogger().warning((new StringBuilder()).append("Failed to get bridge ip address. ").append(e.getMessage()).toString());
                        }
                else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
                        String proxyCommand = "check-net.exe";
-                       List<String> cmd = Arrays.asList(FilePathResources.getBinPath()
-                                       + File.separator + proxyCommand, "--bridge");
+                       List<String> cmd = Arrays.asList(FilePathResources.getBinPath() + File.separator + proxyCommand, "--bridge");
                        ProcessResult res = HelperClass.runProcess(cmd);
                        boolean isCommandSuccess = false;
                        if (res.isSuccess()) {
@@ -753,8 +811,7 @@ public class TapUtil {
                                        if (str.startsWith("IP Address:")) {
                                                isCommandSuccess = true;
                                                ipAddr = str.split("IP Address: ")[1].trim();
-                                               EMLogger.getLogger().info(
-                                                               "bridge IP address: " + ipAddr);
+                                               EMLogger.getLogger().info("bridge IP address: " + ipAddr);
                                                if (ipAddr.equals("0.0.0.0")) {
                                                        return null;
                                                }
@@ -767,8 +824,34 @@ public class TapUtil {
 
                        if (ipAddr == null) {
                                EMLogger.getLogger().warning("Can't find host bridge IP");
-                               EMLogger.getLogger().warning(
-                                               "check-net result : " + res.getResultMessage());
+                               EMLogger.getLogger().warning("check-net result : " + res.getResultMessage());
+                       }
+               } else if (EmulatorManager.isMac()) {
+                       List<String> cmd = Arrays.asList("/bin/sh", "-c", "ifconfig en0 | grep \"inet \" | awk '{print $2}'");
+                       ProcessResult res = HelperClass.runProcess(cmd);
+                       boolean isCommandSuccess = false;
+                       if (res.isSuccess()) {
+                               for (String str : res.getStdOutMsg()) {
+                                       isCommandSuccess = true;
+                                       ipAddr = str.trim();
+                                       EMLogger.getLogger().info("host IP en0: " + ipAddr);
+                               }
+                               if (ipAddr.length() == 0) {
+                                       isCommandSuccess = false;
+                                       cmd = Arrays.asList("/bin/sh", "-c", "ifconfig bridge1 | grep \"inet \" | awk '{print $2}'");
+                                       res = HelperClass.runProcess(cmd);
+                                       if (res.isSuccess()) {
+                                               for (String str : res.getStdOutMsg()) {
+                                                       isCommandSuccess = true;
+                                                       ipAddr = str.trim();
+                                                       EMLogger.getLogger().info("host IP bridge1: " + ipAddr);
+                                               }
+                                       }
+                               }
+                       }
+
+                       if (!res.isSuccess() || !isCommandSuccess) {
+                               EMLogger.getLogger().warning(res.getResultMessage());
                        }
                }
                return ipAddr;
@@ -820,8 +903,7 @@ class TapCreateWorker extends Thread {
        final String tapName;
        final ComboViewItem comboViewItem; // for refresh combo-list
 
-       public TapCreateWorker(String tapName, MessageDialog dialog,
-                       ComboViewItem comboViewItem) {
+       public TapCreateWorker(String tapName, MessageDialog dialog, ComboViewItem comboViewItem) {
                this.dialog = dialog;
                this.tapName = tapName;
                this.comboViewItem = comboViewItem;
@@ -863,13 +945,11 @@ class TapCreateWorker extends Thread {
                        }
 
                        if (newOne == null) {
-                               throw new VMWorkerException(
-                                               "Tap create fail. Cannot find new tap device.");
+                               throw new VMWorkerException("Tap create fail. Cannot find new tap device.");
                        }
 
                        // 4. Rename
-                       cmd = Arrays.asList("netsh", "interface", "set", "interface",
-                                       "name=" + newOne, "newname=" + tapName);
+                       cmd = Arrays.asList("netsh", "interface", "set", "interface", "name=" + newOne, "newname=" + tapName);
                        res = HelperClass.runProcess(cmd);
                        if (!res.isSuccess()) {
                                throw new VMWorkerException(res.getResultMessage());
@@ -887,10 +967,7 @@ class TapCreateWorker extends Thread {
                        if (isTapExist) {
                                Display.getDefault().asyncExec(new Runnable() {
                                        public void run() {
-                                               int res = resultDialog
-                                                               .openSelectionDialog("Tap device created : "
-                                                                               + tapName
-                                                                               + "\nDo you want to see the guide for bridge network ?");
+                                               int res = resultDialog.openSelectionDialog("Tap device created : " + tapName + "\nDo you want to see the guide for bridge network ?");
                                                if (res == SWT.OK) {
                                                        // Show bridge guide dialog
                                                        TapGuideDialogForWin.open();
@@ -908,9 +985,7 @@ class TapCreateWorker extends Thread {
                        final String msg = e.getMessage();
                        Display.getDefault().asyncExec(new Runnable() {
                                public void run() {
-                                       new MessageDialog()
-                                                       .openWarningDialog("\nFailed to create tap device.\n\n"
-                                                                       + msg);
+                                       new MessageDialog().openWarningDialog("\nFailed to create tap device.\n\n" + msg);
                                }
                        });
 
index ea8b4e1..1333c2d 100644 (file)
@@ -50,6 +50,7 @@ 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.ui.dialog.TapDeviceDialogForLinux;
+import org.tizen.emulator.manager.ui.dialog.TapDeviceDialogForMac;
 import org.tizen.emulator.manager.ui.dialog.TapDeviceDialogForWin;
 import org.tizen.emulator.manager.ui.widgets.ImageCombo;
 import org.tizen.emulator.manager.ui.widgets.WSTATE;
@@ -103,8 +104,9 @@ public class NetTapDeviceViewItem extends ComboViewItem {
                combo.setLayout(new FormLayout());
 
                createButton = new Button(compList.get(0), SWT.NORMAL);
-               createButton.setText("create");
+               createButton.setText("...");
                createButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+               createButton.setToolTipText("setting");
 
                FormData data = new FormData();
                data.left = new FormAttachment(0, INPUTBOX_OFFSET);
@@ -153,9 +155,10 @@ public class NetTapDeviceViewItem extends ComboViewItem {
                        public void widgetSelected(SelectionEvent arg0) {
                                if (EmulatorManager.isLinux()) {
                                        TapDeviceDialogForLinux.open();
-
                                } else if (EmulatorManager.isWin()) {
                                        TapDeviceDialogForWin.open(thisItem);
+                               } else if (EmulatorManager.isMac()) {
+                                       TapDeviceDialogForMac.open();
                                }
                                resetCombo(NetConnectTypeViewItem.VALUE_BRIDGE);
                        }
@@ -249,6 +252,10 @@ public class NetTapDeviceViewItem extends ComboViewItem {
                        combo.setEnabled(false);
                        createButton.setEnabled(false);
                }
+
+               if (EmulatorManager.isMac()) {
+                       combo.setEnabled(false);
+               }
        }
 
        @Override
@@ -274,10 +281,10 @@ public class NetTapDeviceViewItem extends ComboViewItem {
                        netIPInfoItem.setGateway(TapUtil.getGatewayFromTap(newValue));
                }
 
-                item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_DNS);
-                if (item != null && item instanceof NetDnsViewItem) {
-                        ((NetDnsViewItem)item).setDns(TapUtil.getDnsFromTap(newValue));
-                }
+               item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_DNS);
+               if (item != null && item instanceof NetDnsViewItem) {
+                       ((NetDnsViewItem) item).setDns(TapUtil.getDnsFromTap(newValue));
+               }
 
                item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_MAC);
                if (item != null && item instanceof NetMacViewItem) {
index 6d63ab4..cba295a 100644 (file)
@@ -109,7 +109,7 @@ public class TapDeviceDialogForLinux {
        private static void makeDialog() {
                dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
                                | SWT.APPLICATION_MODAL);
-               dialog.setText("Creating tap device.");
+               dialog.setText("Setting tap device.");
                dialog.setSize(width, height);
                dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
                RowLayout rowLayout = new RowLayout();
index fdbcb74..ee4725d 100644 (file)
@@ -30,8 +30,6 @@
 package org.tizen.emulator.manager.ui.dialog;
 
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.PaintEvent;
 import org.eclipse.swt.events.PaintListener;
 import org.eclipse.swt.events.SelectionEvent;
@@ -56,7 +54,6 @@ import org.tizen.emulator.manager.tool.TapUtil;
 import org.tizen.emulator.manager.ui.MainDialog;
 import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
 import org.tizen.emulator.manager.ui.widgets.ImageLabel;
-import org.tizen.emulator.manager.vms.helper.HelperClass;
 
 public class TapDeviceDialogForWin {
        private static Shell dialog = null;
@@ -96,7 +93,7 @@ public class TapDeviceDialogForWin {
        private static void makeDialog() {
                dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
                                | SWT.APPLICATION_MODAL);
-               dialog.setText("Creating tap device.");
+               dialog.setText("Setting tap device.");
                dialog.setSize(width, height);
                dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
                RowLayout rowLayout = new RowLayout();
diff --git a/plugin-project/mobile-plugin/src/org/tizen/emulator/manager/mobile/ui/detail/ItemListFactory.java b/plugin-project/mobile-plugin/src/org/tizen/emulator/manager/mobile/ui/detail/ItemListFactory.java
new file mode 100644 (file)
index 0000000..ba2cd6b
--- /dev/null
@@ -0,0 +1,186 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@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.mobile.ui.detail;
+
+import java.util.List;
+
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.EmulatorManager.ManagerModeType;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.IViewItem;
+import org.tizen.emulator.manager.ui.detail.item.ItemType;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.property.NetConnectTypeViewItem;
+import org.tizen.emulator.manager.ui.detail.item.property.NetDnsViewItem;
+import org.tizen.emulator.manager.ui.detail.item.property.NetIPInfoViewItem;
+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.template.CheckLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.FileViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.LabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.OnOffViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.TextViewItem;
+import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator;
+import org.tizen.emulator.manager.vms.xml.template.DeviceList;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+import org.tizen.emulator.manager.vms.xml.template.ItemList;
+
+public class ItemListFactory extends CommonItemListFactory {
+
+       public static String ITEM_EXPERIMENTAL = "experimental";
+
+       private static void makeItemListOld(List<? extends IViewItem> list) {
+               List<IViewItem> itemList = (List<IViewItem>)list;
+
+               itemList.add(new TNameTextItem());
+               itemList.add(new TDisplayItem());
+               itemList.add(new TRAMItem());
+               itemList.add(new TTouchPointItem());
+               if (EmulatorManager.getManagerMode() == ManagerModeType.INHOUSE_MODE) {
+                       itemList.add(new TSupportSuspendItem());
+               }
+
+               itemList.add(new TFileShareItem());
+               itemList.add(new THWSupportItem());
+
+       }
+
+       @Override
+       public void makeItemList(List<? extends IViewItem> itemList,
+                       ItemList template) {
+               if (template == null) {
+                       makeItemListOld(itemList);  // TODO old
+               } else {
+                       makePropertyItemList(itemList, template.getPropertyList(), template.getProfile(), true);
+                       makeDeviceItemList(itemList, template.getDeviceList());
+
+               }
+       }
+
+       @Override
+       public void makeDeviceItemList(List<? extends IViewItem> list, DeviceList deviceList) {
+
+               if (deviceList != null) {
+                       List<IViewItem> itemList = (List<IViewItem>)list;
+                       List<Item> deviceItemList = deviceList.getItem();
+                       LineLabelViewItem currentLineLabel = null;   // Top categorizing item
+                       boolean isExperimentalLabel = false;
+
+                       for (Item item : deviceItemList) {
+                               String type = item.getType();
+                               String name = item.getName();
+
+                               if (isExperimentalLabel && EmulatorManager.getManagerMode() != ManagerModeType.INHOUSE_MODE) {
+                                       continue;
+                               }
+
+                               if (name.equals(CheckingRunningEmulator.OPTION_VIEWER)) {
+                                       if (EmulatorManager.isLinux()) {
+                                               itemList.add(new LabelViewItem(item, currentLineLabel));
+                                       }
+                                       continue;
+
+                               } else if (name.equals(ITEM_NET_CONNECT_TYPE)) {
+                                               itemList.add(new NetConnectTypeViewItem(item,
+                                                               currentLineLabel));
+                                       continue;
+
+                               } else if (name.equals(ITEM_NET_TAP_DEVICE)) {
+                                               itemList.add(new NetTapDeviceViewItem(item,
+                                                               currentLineLabel));
+                                       continue;
+
+                               } else if (name.equals(ITEM_NET_PROXY)) {
+                                               itemList.add(new NetProxyViewItem(item, currentLineLabel));
+                                       continue;
+
+                               } else if (name.equals(ITEM_NET_IP_INFO)) {
+                                               itemList.add(new NetIPInfoViewItem(item, currentLineLabel));
+                                       continue;
+
+                               } else if (name.equals(ITEM_NET_DNS)) {
+                                               itemList.add(new NetDnsViewItem(item, currentLineLabel));
+                                       continue;
+
+                               } else if (name.equals(ITEM_NET_MAC)) {
+                                       itemList.add(new NetMacViewItem(item, currentLineLabel));
+                                       continue;
+
+                               }
+
+                               if (type.equals(ItemType.LINE_LABEL.getName())) { // Top categorizing item
+                                       if (name.equals(ITEM_EXPERIMENTAL)) {
+                                               isExperimentalLabel = true;
+                                               if (EmulatorManager.getManagerMode() == ManagerModeType.INHOUSE_MODE) {
+                                                       currentLineLabel = new LineLabelViewItem(item);
+                                                       itemList.add(currentLineLabel);
+                                               }
+                                       } else {
+                                               currentLineLabel = new LineLabelViewItem(item);
+                                               itemList.add(currentLineLabel);
+                                               isExperimentalLabel = false;
+                                       }
+
+                               } else if (type.equals(ItemType.TOGGLE.getName())) {
+                                       itemList.add(new OnOffViewItem(item, currentLineLabel));
+
+                               } else if (type.equals(ItemType.LABEL.getName())) {
+                                       itemList.add(new LabelViewItem(item, currentLineLabel));
+
+                               } else if (type.equals(ItemType.COMBO.getName())) {
+                                       itemList.add(new ComboViewItem(item, currentLineLabel));
+
+                               } else if (type.equals(ItemType.FILE.getName())) {
+                                       itemList.add(new FileViewItem(item, currentLineLabel));
+
+                               } else if (type.equals(ItemType.CHECK_LABEL.getName())) {
+                                       itemList.add(new CheckLabelViewItem(item, currentLineLabel));
+
+                               } else if (type.equals(ItemType.TEXT.getName())) {
+                                       itemList.add(new TextViewItem(item, currentLineLabel));
+                               }
+                       }
+               }
+       }
+
+
+       @Override
+       public void makeCustomItemList(List<? extends IViewItem> itemList,
+                       List<ItemList> templateList) {
+               if (templateList == null || templateList.size() == 0) {
+                       makeItemListOld(itemList);  // TODO old
+               } else {
+
+                       makeCustomDeviceItemList(itemList, templateList);
+               }
+       }
+}
index 23d3539..1f4e3bc 100644 (file)
@@ -75,7 +75,7 @@ public class Launcher implements ILauncher {
        private String binPath = null;
        private static Launcher launcher;
 
-
+       public static final String IFUP_SCRIPT = "emulator-ifup.sh";
        // Option names in vm_config.xml
        // Add if need.
        public static final String OPT_DEVICE = "device";
@@ -138,23 +138,9 @@ public class Launcher implements ILauncher {
                int portNo;
                boolean useBridgeNet = property.getPropertyValue()
                                .getAdvancedOptionValue(OPT_NET_CONNECT_TYPE).equals("Bridge") &&
-                               (EmulatorManager.isLinux() || EmulatorManager.isWin());
+                               (EmulatorManager.isLinux() || EmulatorManager.isWin() || EmulatorManager.isMac());
 
                if (useBridgeNet) {
-                       String tapName = property.getPropertyValue()
-                                       .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
-                       if (TapUtil.nameNotExist(tapName))
-                               throw new VMLauncherException((new StringBuilder())
-                                               .append("Tap device is not exist : ").append(tapName)
-                                               .append("\nCheck VM's tap configuration.").toString());
-                       if (isTapUsing(tapName))
-                               throw new VMLauncherException(
-                                               (new StringBuilder())
-                                                               .append("Tap device(")
-                                                               .append(tapName)
-                                                               .append(") is being used by other VM.")
-                                                               .append("\nPlease select another tap device for current VM.")
-                                                               .toString());
                        String ipAddr = property.getPropertyValue()
                                        .getAdvancedOptionSubValue(OPT_NET_IP_INFO, "ipAddr");
                        if (isIpAddrUsing(ipAddr))
@@ -163,21 +149,38 @@ public class Launcher implements ILauncher {
                                                .append(") is being used by other VM.")
                                                .append("\nPlease modify current VM's ip address.")
                                                .toString());
-                       try {
-                               if (!TapUtil.isTapInBridge(tapName)) {
-                                       MessageDialog dialog = new MessageDialog();
-                                       int res = dialog
-                                                       .openWarningAndSelectionDialog("\nTap device is not connected with Bridge." +
-                                                                       "\nGuest network would work as NAT." +
-                                                                       "\nKeep launching ?");
-                                       if (res != SWT.OK) {
-                                               throw new VMLauncherException("User canceled.");
+
+                       if (!EmulatorManager.isMac()) {
+                               String tapName = property.getPropertyValue()
+                                               .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+                               if (TapUtil.nameNotExist(tapName))
+                                       throw new VMLauncherException((new StringBuilder())
+                                                       .append("Tap device is not exist : ").append(tapName)
+                                                       .append("\nCheck VM's tap configuration.").toString());
+                               if (isTapUsing(tapName))
+                                       throw new VMLauncherException(
+                                                       (new StringBuilder())
+                                                                       .append("Tap device(")
+                                                                       .append(tapName)
+                                                                       .append(") is being used by other VM.")
+                                                                       .append("\nPlease select another tap device for current VM.")
+                                                                       .toString());
+                               try {
+                                       if (!TapUtil.isTapInBridge(tapName)) {
+                                               MessageDialog dialog = new MessageDialog();
+                                               int res = dialog
+                                                               .openWarningAndSelectionDialog("\nTap device is not connected with Bridge." +
+                                                                               "\nGuest network would work as NAT." +
+                                                                               "\nKeep launching ?");
+                                               if (res != SWT.OK) {
+                                                       throw new VMLauncherException("User canceled.");
+                                               }
+                                               useBridgeNet = false;
                                        }
-                                       useBridgeNet = false;
-                               }
 
-                       } catch (VMWorkerException e) {
-                               throw new VMLauncherException(e.getMessage());
+                               } catch (VMWorkerException e) {
+                                       throw new VMLauncherException(e.getMessage());
+                               }
                        }
                }
 
@@ -243,8 +246,8 @@ public class Launcher implements ILauncher {
                
                /* get MAC address of host set as guest MAC address */
                String macAddr = useBridgeNet ? property.getPropertyValue()
-                               .getAdvancedOptionValue(OPT_NET_MAC) : SettingInfoFile
-                               .getMACaddr();
+                                       .getAdvancedOptionValue(OPT_NET_MAC) : SettingInfoFile
+                                       .getMACaddr();
 
                if(macAddr.isEmpty()) {
                        macAddr = "52:54:00:12:34:56";
@@ -386,13 +389,17 @@ public class Launcher implements ILauncher {
                        cmd.add(FilePathResources.getKernelPath() + File.separator+ "bzImage." + property.getArch().toString());
                        cmd.add("-net");
                        if (useBridgeNet) {
-                               String tapName = property.getPropertyValue()
-                                               .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
-                               if (TapUtil.nameNotExist(tapName)) {
-                                       throw new VMLauncherException("Tap device is not exist : "
-                                                       + tapName + "\nCheck VM's tap configuration.");
+                               if (!EmulatorManager.isMac()) {
+                                       String tapName = property.getPropertyValue()
+                                                       .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+                                       if (TapUtil.nameNotExist(tapName)) {
+                                               throw new VMLauncherException("Tap device is not exist : "
+                                                               + tapName + "\nCheck VM's tap configuration.");
+                                       }
+                                       cmd.add("tap,ifname=" + tapName + ",script=no,downscript=no");
+                               } else {
+                                       cmd.add("tap,script=" + FilePathResources.getBinPath() + File.separator + IFUP_SCRIPT +",downscript=no");
                                }
-                               cmd.add("tap,ifname=" + tapName + ",script=no,downscript=no");
                        } else {
                                cmd.add("user,dhcpstart=10.0.2.16");
                        }