COMM: enable to connect device by network 92/28792/3
authorgreatim <jaewon81.lim@samsung.com>
Thu, 16 Oct 2014 08:14:47 +0000 (17:14 +0900)
committergreatim <jaewon81.lim@samsung.com>
Fri, 17 Oct 2014 08:21:16 +0000 (17:21 +0900)
enable to connect device by network (Remote Device Connection)

Change-Id: I21593e01d2d263c8f445f1e8984a555a839b5701
Signed-off-by: greatim <jaewon81.lim@samsung.com>
15 files changed:
org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/widgets/da/base/DAText.java
org.tizen.dynamicanalyzer.common/src/org/tizen/dynamicanalyzer/constant/CommonConstants.java
org.tizen.dynamicanalyzer.common/src/org/tizen/dynamicanalyzer/util/CommonUtil.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AutoStartManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/CommunicatorUtils.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/ProcessExplorerDialog.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/RemoteDeviceDialog.java [new file with mode: 0644]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/RemoteDeviceManager.java [new file with mode: 0644]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/ToolbarArea.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/utils/RpmUtil.java

index 2738e85..516662b 100644 (file)
@@ -109,6 +109,10 @@ public class DAText {
                        }
                });
        }
+       
+       public void setEnabled(boolean enabled) {
+               this.text.setEnabled(enabled);
+       }
 
        public void setText(String text) {
                this.text.setText(text);
index ec3ac4a..00a2ecd 100644 (file)
@@ -73,6 +73,11 @@ public class CommonConstants {
 
        public static final String LOCAL_HOST = "127.0.0.1"; //$NON-NLS-1$
 
+       public static final int IPv4_OCTET_NUMBER = 4;
+       public static final int MAX_OCTET_NUMBER = 255;
+       public static final int MIN_PORT_NUMBER = 1;
+       public static final int MAX_PORT_NUMBER = 65535;
+
        /* extensions */
        public static final String EXTENSION_LOG_CENTER = ".logc"; //$NON-NLS-1$
        public static final String EXTENSION_LEAK_CHECK = ".leak"; //$NON-NLS-1$
index 868932f..74ecf4d 100644 (file)
 
 package org.tizen.dynamicanalyzer.util;
 
+import java.io.BufferedReader;
 import java.io.Closeable;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.util.List;
 
 public class CommonUtil {
        private static final String OS = getOS();
@@ -44,17 +47,34 @@ public class CommonUtil {
 
        private static String pid = null;
 
-       public static int executeCommand(String[] cmds) {
-               int retValue = 0;
+       public static boolean executeCommand(String cmd, List<String> stdoutput, List<String> stderror) {
+               boolean bret = false;
                Process process = null;
-               if (null == cmds || cmds.length == 0) {
-                       retValue = -1;
-               } else {
+               BufferedReader reader = null;
+               BufferedReader error = null;
+
+               if (cmd != null && !cmd.isEmpty()) {
                        try {
-                               process = Runtime.getRuntime().exec(cmds);
+                               process = Runtime.getRuntime().exec(cmd);
                                if (process != null) {
                                        process.waitFor();
-                                       retValue = process.exitValue();
+                                       reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+                                       error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+
+                                       String line = null;
+                                       if (stdoutput != null) {
+                                               while (null != (line = reader.readLine())) {
+                                                       stdoutput.add(line);
+                                               }
+                                       }
+
+                                       if (stderror != null) {
+                                               while (null != (line = error.readLine())) {
+                                                       stderror.add(line);
+                                               }
+                                       }
+
+                                       bret = true;
                                }
                        } catch (IOException e) {
                                e.printStackTrace();
@@ -64,10 +84,32 @@ public class CommonUtil {
                                if (process != null) {
                                        process.destroy();
                                }
+                               tryClose(reader, error);
+                       }
+               }
+
+               return bret;
+       }
+
+       public static boolean executeCommand(String[] cmds) {
+               return executeCommand(cmds, null, null);
+       }
+
+       public static boolean executeCommand(String[] cmds, List<String> stdoutput,
+                       List<String> stderror) {
+               if (cmds != null && cmds.length != 0) {
+                       StringBuffer command = new StringBuffer();
+                       for (int i = 0; i < cmds.length; i++) {
+                               command.append(cmds[i]);
+                               if (i != cmds.length - 1) {
+                                       command.append(" ");
+                               }
                        }
+
+                       return executeCommand(command.toString(), stdoutput, stderror);
                }
 
-               return retValue;
+               return false;
        }
 
        public static void tryClose(final Object... closeables) {
@@ -129,4 +171,19 @@ public class CommonUtil {
 
                return pid;
        }
+
+       public static String getNormalizedFilename(String original) {
+               // replace prohibited character to underbar
+               String result = original.replace('/', '_');
+               result = result.replace('\\', '_');
+               result = result.replace('?', '_');
+               result = result.replace('*', '_');
+               result = result.replace(':', '_');
+               result = result.replace('|', '_');
+               result = result.replace('\"', '_');
+               result = result.replace('<', '_');
+               result = result.replace('>', '_');
+
+               return result;
+       }
 }
index cd9e6bd..036b6c3 100644 (file)
@@ -372,6 +372,10 @@ public class AnalyzerConstants {
        public final static String COMMON_EXECUTABLE = "_Common executable_";//$NON-NLS-1$
        public final static String COMMON_EXECUTABLE_LABEL = "[Common executable]";//$NON-NLS-1$
        
+       public final static String REMOTE_DEVICE = "[Remote Device]";//$NON-NLS-1$
+       
+       public final static int DEFAULT_DEVICE_PORT = 26101;
+       
        // file constants
        public final static int F_SETLKW = 7;
        
index c84e865..f1aaf60 100644 (file)
@@ -111,6 +111,7 @@ public class AutoStartManager implements Runnable {
                Logger.debug("auto start : " + appid);
                DeviceInfo device = DACommunicator.getDeviceByName(deviceName);
                Global.setCurrentDeviceInfo(device);
+               DACommunicator.updateAppListFromTarget();
 
                PackageInfo pkgInfo = DACommunicator.getPkgInfoByMainAppID(appid);
                if (null == pkgInfo) {
index efeae88..68ef308 100755 (executable)
@@ -71,15 +71,14 @@ public class CommunicatorUtils {
        public static long getReadelfSize() {
                long ret = -1;
                getUploadDataResult().clear();
-               execShellCommand(AnalyzerShellCommands.CMD_UPLOAD_FILE_LIST,
-                               new MultiLineReceiver() {
-                                       @Override
-                                       public void processNewLines(String[] lines) {
-                                               for (int i = 0; i < lines.length; i++) {
-                                                       getUploadDataResult().add(lines[i]);
-                                               }
-                                       }
-                               });
+               execShellCommand(AnalyzerShellCommands.CMD_UPLOAD_FILE_LIST, new MultiLineReceiver() {
+                       @Override
+                       public void processNewLines(String[] lines) {
+                               for (int i = 0; i < lines.length; i++) {
+                                       getUploadDataResult().add(lines[i]);
+                               }
+                       }
+               });
                if (getUploadDataResult().isEmpty()) {
                        return ret;
                }
@@ -103,8 +102,7 @@ public class CommunicatorUtils {
                } else {
                        readelf += CommonConstants.X86_ARCH;
                }
-               String source = readelf + File.separator
-                               + AnalyzerConstants.READELF_BIN;
+               String source = readelf + File.separator + AnalyzerConstants.READELF_BIN;
                File file = new File(source);
                if (file.exists()) {
                        readelfSize = file.length();
@@ -113,9 +111,8 @@ public class CommunicatorUtils {
                        return HostResult.ERR_FILE_IS_NOT_EXISTS;
                }
 
-               result = uploadFile(Global.getCurrentDeviceInfo()
-                               .getIDevice(), source, PathConstants.DA_REMOTE_PATH
-                               + AnalyzerConstants.READELF_BIN);
+               result = uploadFile(Global.getCurrentDeviceInfo().getIDevice(), source,
+                               PathConstants.DA_REMOTE_PATH + AnalyzerConstants.READELF_BIN);
                if (!result.isSuccess()) {
                        return result;
                }
@@ -133,17 +130,16 @@ public class CommunicatorUtils {
        }
 
        public static boolean isCurrentDeviceArmArch() {
-               execHostCommand(AnalyzerShellCommands.CMD_IS_ARM_ARCH,
-                               new MultiLineReceiver() {
-                                       @Override
-                                       public void processNewLines(String[] lines) {
-                                               if (lines[0].contains(CommonConstants.ARM_ARCH)) {
-                                                       isArch = true;
-                                               } else {
-                                                       isArch = false;
-                                               }
-                                       }
-                               });
+               execHostCommand(AnalyzerShellCommands.CMD_IS_ARM_ARCH, new MultiLineReceiver() {
+                       @Override
+                       public void processNewLines(String[] lines) {
+                               if (lines[0].contains(CommonConstants.ARM_ARCH)) {
+                                       isArch = true;
+                               } else {
+                                       isArch = false;
+                               }
+                       }
+               });
 
                return isArch;
        }
@@ -159,13 +155,11 @@ public class CommunicatorUtils {
                execShellCommand(command, NullOutputReceiver.getInstance());
        }
 
-       public static void execShellCommand(String command,
-                       IShellOutputReceiver receiver) {
+       public static void execShellCommand(String command, IShellOutputReceiver receiver) {
                DeviceInfo currentDevice = Global.getCurrentDeviceInfo();
                if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
                        try {
-                               currentDevice.getIDevice().executeShellCommand(command,
-                                               receiver);
+                               currentDevice.getIDevice().executeShellCommand(command, receiver);
                        } catch (TimeoutException e) {
                                e.printStackTrace();
                        } catch (SdbCommandRejectedException e) {
@@ -179,16 +173,14 @@ public class CommunicatorUtils {
        }
 
        public static void execShellCommand(IDevice device, String command,
-                       IShellOutputReceiver receiver) throws TimeoutException,
-                       SdbCommandRejectedException, ShellCommandUnresponsiveException,
-                       IOException {
+                       IShellOutputReceiver receiver) throws TimeoutException, SdbCommandRejectedException,
+                       ShellCommandUnresponsiveException, IOException {
                if (null != device && isOnline(device)) {
                        device.executeShellCommand(command, receiver);
                }
        }
 
-       private static HostResult uploadFile(IDevice device, String source,
-                       String targetPath) {
+       private static HostResult uploadFile(IDevice device, String source, String targetPath) {
                HostResult ret = HostResult.SUCCESS;
                SyncResult result = push(device, source, targetPath);
                if (null == result || !result.isOk()) {
@@ -207,12 +199,11 @@ public class CommunicatorUtils {
        }
 
        public static SyncResult push(IDevice device, String local, String remote) {
-               return push(device, local, remote,
-                               NullSyncProgressMonitor.getInstance());
+               return push(device, local, remote, NullSyncProgressMonitor.getInstance());
        }
 
-       public static SyncResult push(IDevice currentDevice, String local,
-                       String remote, ISyncProgressMonitor monitor) {
+       public static SyncResult push(IDevice currentDevice, String local, String remote,
+                       ISyncProgressMonitor monitor) {
                SyncResult result = null;
                if (null != currentDevice && isOnline(currentDevice)) {
                        try {
@@ -237,19 +228,17 @@ public class CommunicatorUtils {
                return pull(remote, local, NullSyncProgressMonitor.getInstance());
        }
 
-       public static SyncResult pull(String remote, String local,
-                       ISyncProgressMonitor monitor) {
+       public static SyncResult pull(String remote, String local, ISyncProgressMonitor monitor) {
                SyncResult result = null;
                DeviceInfo currentDevice = Global.getCurrentDeviceInfo();
                if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
                        FileOutputStream fileOut = null;
                        try {
                                fileOut = new FileOutputStream(local);
-                               SyncService service = currentDevice.getIDevice()
-                                               .getSyncService();
+                               SyncService service = currentDevice.getIDevice().getSyncService();
                                if (null != service) {
-                                       result = service.doPull(currentDevice.getIDevice()
-                                                       .getFileEntry(remote), fileOut, monitor, -1);
+                                       result = service.doPull(currentDevice.getIDevice().getFileEntry(remote),
+                                                       fileOut, monitor, -1);
                                }
                        } catch (TimeoutException e) {
                                e.printStackTrace();
@@ -265,8 +254,7 @@ public class CommunicatorUtils {
        }
 
        public static SyncResult pull(IDevice device, String local, String remote) {
-               return pull(device, local, remote,
-                               NullSyncProgressMonitor.getInstance());
+               return pull(device, local, remote, NullSyncProgressMonitor.getInstance());
        }
 
        public static SyncResult pull(IDevice device, String remote, String local,
@@ -278,8 +266,7 @@ public class CommunicatorUtils {
                                fileOut = new FileOutputStream(local);
                                SyncService service = device.getSyncService();
                                if (null != service) {
-                                       result = service.doPull(device.getFileEntry(remote),
-                                                       fileOut, monitor, -1);
+                                       result = service.doPull(device.getFileEntry(remote), fileOut, monitor, -1);
                                }
                        } catch (TimeoutException e) {
                                e.printStackTrace();
@@ -302,8 +289,7 @@ public class CommunicatorUtils {
                long start = System.currentTimeMillis();
                while ((System.currentTimeMillis() - start) < PORT_WAIT_TIME) {
                        try {
-                               execShellCommand(device,
-                                               AnalyzerShellCommands.CMD_CAT_PORT_FILE,
+                               execShellCommand(device, AnalyzerShellCommands.CMD_CAT_PORT_FILE,
                                                new MultiLineReceiver() {
                                                        @Override
                                                        public void processNewLines(String[] lines) {
@@ -322,7 +308,7 @@ public class CommunicatorUtils {
                                                System.out.print("=");
                                        }
                                }
-                               
+
                                Thread.sleep(50);
                        } catch (InterruptedException e) {
                                System.out.print("\n");
@@ -346,14 +332,14 @@ public class CommunicatorUtils {
                                break;
                        }
                }
-               
+
                System.out.print("\n");
-               if(remotePort < 0) {
+               if (remotePort < 0) {
                        Logger.debug("!!port get failed!!");
                } else {
                        Logger.debug("!!port get success!! : " + remotePort);
                }
-               
+
                return remotePort;
        }
 
@@ -429,8 +415,7 @@ public class CommunicatorUtils {
                if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
                        try {
                                currentDevice.getIDevice().executeShellCommand(
-                                               AnalyzerShellCommands.CMD_REMOVE
-                                                               + CommonConstants.SPACE + path,
+                                               AnalyzerShellCommands.CMD_REMOVE + CommonConstants.SPACE + path,
                                                NullOutputReceiver.getInstance());
                        } catch (TimeoutException e) {
                                e.printStackTrace();
@@ -444,21 +429,18 @@ public class CommunicatorUtils {
                }
        }
 
-       public static void execHostCommand(String command,
-                       IShellOutputReceiver receiver) {
+       public static void execHostCommand(String command, IShellOutputReceiver receiver) {
                DeviceInfo currentDevice = Global.getCurrentDeviceInfo();
                if (null != currentDevice && isOnline(currentDevice.getIDevice())) {
                        try {
-                               currentDevice.getIDevice()
-                                               .executeHostCommand(command, receiver);
+                               currentDevice.getIDevice().executeHostCommand(command, receiver);
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
                }
        }
 
-       public static void execHostCommand(IDevice device, String command,
-                       IShellOutputReceiver receiver) {
+       public static void execHostCommand(IDevice device, String command, IShellOutputReceiver receiver) {
                if (null != device && isOnline(device)) {
                        try {
                                device.executeHostCommand(command, receiver);
@@ -490,9 +472,6 @@ public class CommunicatorUtils {
        }
 
        public static List<String> getApiMap(IDevice device) {
-               String apiFilePath = PathManager.DA_TEMP_FOLDER_PATH + File.separator
-                               + device.getSerialNumber() + CommonConstants.UNDERBAR
-                               + AnalyzerConstants.API_NAME_FILE_NAME;
                try {
                        device.becomeSuperUser(true);
                } catch (TimeoutException e) {
@@ -503,8 +482,11 @@ public class CommunicatorUtils {
                        e.printStackTrace();
                }
 
-               SyncResult res = CommunicatorUtils.pull(device,
-                               PathConstants.DA_API_MAP_PATH, apiFilePath);
+               String nDeviceName = CommonUtil.getNormalizedFilename(device.getSerialNumber());
+               String apiFilePath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + nDeviceName
+                               + CommonConstants.UNDERBAR + AnalyzerConstants.API_NAME_FILE_NAME;
+
+               SyncResult res = CommunicatorUtils.pull(device, PathConstants.DA_API_MAP_PATH, apiFilePath);
                if (null != res && res.isOk()) {
                        Logger.debug("api map copying success!!");//$NON-NLS-1$ 
                } else {
@@ -520,7 +502,7 @@ public class CommunicatorUtils {
                        Logger.debug("file open failed...");
                        return null;
                }
-               
+
                FileInputStream fis = null;
                InputStreamReader isr = null;
                BufferedReader reader = null;
@@ -531,8 +513,7 @@ public class CommunicatorUtils {
 
                        String input = null;
                        while (null != (input = reader.readLine())) {
-                               String[] splitLine = input.trim().split(CommonConstants.SPACE,
-                                               2);
+                               String[] splitLine = input.trim().split(CommonConstants.SPACE, 2);
                                apiMap.add(new String(splitLine[1]));
                        }
 
index 642473a..f432b18 100644 (file)
@@ -417,9 +417,7 @@ public class DACommunicator {
        public static boolean isTargetEmulator() {
                DeviceInfo device = Global.getCurrentDeviceInfo();
                if (device != null) {
-                       if (device.getIDevice().getSerialNumber().contains(CommonConstants.EMULATOR)) {
-                               return true;
-                       }
+                       return device.isEmulator();
                }
                return false;
        }
@@ -496,8 +494,7 @@ public class DACommunicator {
                                        updateToolbarDevice();
                                }
                        }
-                       if (null != Global.getCurrentDeviceInfo()
-                                       && null != Global.getCurrentApplication()) {
+                       if (null != Global.getCurrentDeviceInfo() && null != Global.getCurrentApplication()) {
                                Display.getDefault().syncExec(new Runnable() {
                                        @Override
                                        public void run() {
@@ -535,8 +532,7 @@ public class DACommunicator {
                                                updateToolbarDevice();
                                        }
                                }
-                               if (null != Global.getCurrentDeviceInfo()
-                                               && null != Global.getCurrentApplication()) {
+                               if (null != Global.getCurrentDeviceInfo() && null != Global.getCurrentApplication()) {
                                        Display.getDefault().syncExec(new Runnable() {
                                                @Override
                                                public void run() {
index 1204ab4..06bf931 100755 (executable)
@@ -53,6 +53,14 @@ public class AnalyzerLabels extends NLS {
 
        public static String RANGE_PAGE;
        public static String SNAPSHOT_ENABLE;
+       
+       // string for dialog by toolbar combobox
+       public static String SELECT_PROCESS;
+       public static String REMOTE_DEVICE;
+       public static String IP;
+       public static String PORT;
+       public static String CONNECT;
+       public static String CONNECTING;
 
        // tooltip text
        public static String ABOUT;
index bdb8f74..3b96482 100755 (executable)
@@ -18,6 +18,14 @@ REPLAY_EDIT_MAC=Replay Edit [Command + E]
 RANGE_PAGE=Range page
 SNAPSHOT_ENABLE=Take snapshot
 
+#String for dialog by toolbar combobox
+SELECT_PROCESS=Select Process
+REMOTE_DEVICE=Connect Remote Device
+IP=IP address
+PORT=Port number
+CONNECT=Connect
+CONNECTING=Connecting
+
 #Setting menu
 ABOUT=About Tizen Dynamic Analyzer [F1]
 SETTING=Settings [F2]
index dd8db94..b3812e4 100755 (executable)
@@ -412,11 +412,14 @@ public class Project {
 
                setAppName(Global.getCurrentApplication().getMainApp().getLabel());
                setPackageID(Global.getCurrentApplication().getPackageId());
-               DeviceInfo deviceName = Global.getCurrentDeviceInfo();
+               DeviceInfo device = Global.getCurrentDeviceInfo();
+               String deviceSerial = null;
+               if (device != null) {
+                       deviceSerial = device.getIDevice().getSerialNumber();
+               }
 
-               if (null != deviceName && null != deviceName.getIDevice().getSerialNumber()
-                               && !deviceName.getIDevice().getSerialNumber().isEmpty()) {
-                       setDevice(Global.getCurrentDeviceInfo().getIDevice().getSerialNumber());
+               if (null != deviceSerial && !deviceSerial.isEmpty()) {
+                       setDevice(deviceSerial);
                } else {
                        setDevice(CommonConstants.SPACE);
                }
index 69a02cc..50e2299 100644 (file)
@@ -39,6 +39,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.dynamicanalyzer.appearance.DesignConstants;
 import org.tizen.dynamicanalyzer.common.Global;
+import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
 import org.tizen.dynamicanalyzer.nl.WidgetLabels;
 import org.tizen.dynamicanalyzer.resources.ColorResources;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
@@ -56,7 +57,7 @@ public class ProcessExplorerDialog extends DAMessageBox {
                shell.setLayout(new FormLayout());
                shell.setSize(446, 600);
                shell.setBackground(ColorResources.DIALOG_BG_UPPER);
-               shell.setText("Select process");
+               shell.setText(AnalyzerLabels.SELECT_PROCESS);
 
                explorer = new ProcessExplorer(shell);
                FormData data = new FormData();
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/RemoteDeviceDialog.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/RemoteDeviceDialog.java
new file mode 100644 (file)
index 0000000..9a20270
--- /dev/null
@@ -0,0 +1,325 @@
+package org.tizen.dynamicanalyzer.ui.toolbar;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.dynamicanalyzer.appearance.DesignConstants;
+import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
+import org.tizen.dynamicanalyzer.constant.CommonConstants;
+import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
+import org.tizen.dynamicanalyzer.nl.WidgetLabels;
+import org.tizen.dynamicanalyzer.resources.ColorResources;
+import org.tizen.dynamicanalyzer.widgets.animation.DAAnimationIcon;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
+import org.tizen.dynamicanalyzer.widgets.da.base.DAButton;
+import org.tizen.dynamicanalyzer.widgets.da.base.DAMessageBox;
+import org.tizen.dynamicanalyzer.widgets.da.base.DAText;
+import org.tizen.dynamicanalyzer.widgets.helper.ImageResources;
+
+public class RemoteDeviceDialog extends DAMessageBox {
+       private static final long THREAD_JOIN_WAITTIME = 1000;
+
+       private RemoteDeviceDialog self = null;
+
+       private DAText ipTextbox = null;
+       private DAText portTextbox = null;
+
+       private List<Image> progressImage = new ArrayList<Image>();
+       private DAAnimationIcon progressIcon = null;
+       private Label progressLabel = null;
+
+       private DACustomButton connectButton = null;
+       private DACustomButton cancelButton = null;
+
+       private String address = null;
+       private Thread managerThread = null;
+
+       public RemoteDeviceDialog(Shell parentShell) {
+               super(parentShell);
+
+               self = this;
+
+               shell.setLayout(new FormLayout());
+               shell.setSize(400, 192);
+               shell.setBackground(ColorResources.DIALOG_BG_UPPER);
+               shell.setText(AnalyzerLabels.REMOTE_DEVICE);
+
+               // IP label and textbox
+               Label ipText = new Label(shell, SWT.TRANSPARENT);
+               FormData data = new FormData();
+               data.top = new FormAttachment(0, 12);
+               data.left = new FormAttachment(0, 15);
+               data.height = 20;
+               data.width = 100;
+               ipText.setLayoutData(data);
+               ipText.setBackground(ColorResources.DIALOG_BG_UPPER);
+               ipText.setAlignment(SWT.LEFT);
+               ipText.setForeground(ColorResources.BLACK);
+               ipText.setText(AnalyzerLabels.IP);
+
+               ipTextbox = new DAText(shell, SWT.SINGLE);
+               data = new FormData();
+               data.top = new FormAttachment(0, 12);
+               data.left = new FormAttachment(ipText, 12);
+               data.height = 20;
+               data.width = 250;
+               ipTextbox.setLayoutData(data);
+               ipTextbox.setBackground(ColorResources.VIEW_BG_COLOR);
+               ipTextbox.getControl().addKeyListener(ipTextboxListener);
+
+               // Port label and textbox
+               Label portText = new Label(shell, SWT.TRANSPARENT);
+               data = new FormData();
+               data.top = new FormAttachment(ipText, 12);
+               data.left = new FormAttachment(0, 15);
+               data.height = 20;
+               data.width = 100;
+               portText.setLayoutData(data);
+               portText.setBackground(ColorResources.DIALOG_BG_UPPER);
+               portText.setAlignment(SWT.LEFT);
+               portText.setForeground(ColorResources.BLACK);
+               portText.setText(AnalyzerLabels.PORT);
+
+               portTextbox = new DAText(shell, SWT.SINGLE);
+               data = new FormData();
+               data.top = new FormAttachment(ipText, 12);
+               data.left = new FormAttachment(portText, 12);
+               data.height = 20;
+               data.width = 250;
+               portTextbox.setLayoutData(data);
+               portTextbox.setBackground(ColorResources.VIEW_BG_COLOR);
+               portTextbox.getControl().addKeyListener(portTextboxListener);
+
+               // progress Icon and text
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_01);
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_02);
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_03);
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_04);
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_05);
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_06);
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_07);
+               progressImage.add(ImageResources.STOP_PROGRESS_LOADING_08);
+
+               progressIcon = new DAAnimationIcon(shell, SWT.NONE, progressImage);
+               data = new FormData();
+               data.top = new FormAttachment(portText, 16);
+               data.left = new FormAttachment(30, 10);
+               data.height = 24;
+               data.width = 24;
+               progressIcon.setLayoutData(data);
+               progressIcon.setVisible(false);
+
+               progressLabel = new Label(shell, SWT.TRANSPARENT);
+               data = new FormData();
+               data.top = new FormAttachment(portText, 20);
+               data.left = new FormAttachment(progressIcon, 12);
+               data.height = 20;
+               data.width = 150;
+               progressLabel.setLayoutData(data);
+               progressLabel.setBackground(ColorResources.DIALOG_BG_UPPER);
+               progressLabel.setAlignment(SWT.LEFT);
+               progressLabel.setForeground(ColorResources.BLACK);
+               progressLabel.setText(AnalyzerLabels.CONNECTING);
+               progressLabel.setVisible(false);
+
+               // connect and cancel button
+               Composite buttonComp = new Composite(shell, SWT.NONE);
+               buttonComp.setLayout(new FormLayout());
+               buttonComp.setBackground(ColorResources.DIALOG_BG_LOWER);
+
+               buttonComp.addPaintListener(new PaintListener() {
+
+                       @Override
+                       public void paintControl(PaintEvent e) {
+                               Composite comp = (Composite) e.widget;
+                               Rectangle rect = comp.getClientArea();
+                               e.gc.setForeground(ColorResources.DIALOG_SUNKEN_1);
+                               e.gc.drawLine(rect.x, rect.y, rect.x + rect.width, rect.y);
+                               e.gc.setForeground(ColorResources.DIALOG_SUNKEN_2);
+                               e.gc.drawLine(rect.x, rect.y + 1, rect.x + rect.width, rect.y + 1);
+                       }
+               });
+
+               FormData compData = new FormData();
+               compData.top = new FormAttachment(100, -50);
+               compData.left = new FormAttachment(0, 0);
+               compData.right = new FormAttachment(100, 0);
+               compData.bottom = new FormAttachment(100, 0);
+               buttonComp.setLayoutData(compData);
+
+               connectButton = new DAButton(buttonComp, SWT.NONE);
+               data = new FormData();
+               data.top = new FormAttachment(0, 11);
+               data.left = new FormAttachment(50, -DesignConstants.DA_BUTTON_WIDTH - 4);
+               data.height = DesignConstants.DA_BUTTON_HEIGHT;
+               data.width = DesignConstants.DA_BUTTON_WIDTH;
+               connectButton.setLayoutData(data);
+               connectButton.setText(AnalyzerLabels.CONNECT);
+               connectButton.addClickListener(connectButtonListener);
+               connectButton.setButtonEnabled(false);
+
+               cancelButton = new DAButton(buttonComp, SWT.NONE);
+               data = new FormData();
+               data.top = new FormAttachment(0, 11);
+               data.left = new FormAttachment(50, 4);
+               data.height = DesignConstants.DA_BUTTON_HEIGHT;
+               data.width = DesignConstants.DA_BUTTON_WIDTH;
+               cancelButton.setLayoutData(data);
+               cancelButton.setText(WidgetLabels.CANCEL);
+               cancelButton.addClickListener(cancelButtonListener);
+       }
+
+       private DACustomButtonClickEventListener connectButtonListener = new DACustomButtonClickEventListener() {
+
+               @Override
+               public void handleClickEvent(DACustomButton button) {
+                       String ip = ipTextbox.getText();
+                       String port = portTextbox.getText();
+
+                       if (ip.isEmpty()) {
+                               return;
+                       }
+
+                       if (port.isEmpty()) {
+                               port = String.valueOf(AnalyzerConstants.DEFAULT_DEVICE_PORT);
+                       }
+
+                       address = ip + ":" + port;
+
+                       // show progress and try to connect
+                       connectButton.setButtonEnabled(false);
+                       ipTextbox.setEnabled(false);
+                       portTextbox.setEnabled(false);
+
+                       progressIcon.setVisible(true);
+                       progressLabel.setVisible(true);
+                       progressIcon.start();
+
+                       // start RemoteDeviceManager
+                       Thread managerThread = new Thread(new RemoteDeviceManager(self));
+                       managerThread.start();
+               }
+       };
+
+       private DACustomButtonClickEventListener cancelButtonListener = new DACustomButtonClickEventListener() {
+
+               @Override
+               public void handleClickEvent(DACustomButton button) {
+                       address = null;
+
+                       if (managerThread != null && managerThread.isAlive()) {
+                               managerThread.interrupt();
+                               try {
+                                       managerThread.join(THREAD_JOIN_WAITTIME);
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                               }
+                               managerThread = null;
+
+                               setConnectionResult(false);
+                       } else {
+                               shell.close();
+                       }
+               }
+       };
+
+       private KeyListener ipTextboxListener = new KeyListener() {
+
+               @Override
+               public void keyReleased(KeyEvent e) {
+                       if (!checkValidIP(ipTextbox.getText())) {
+                               connectButton.setButtonEnabled(false);
+                       } else {
+                               connectButton.setButtonEnabled(true);
+                       }
+               }
+
+               @Override
+               public void keyPressed(KeyEvent e) {
+
+               }
+       };
+
+       private KeyListener portTextboxListener = new KeyListener() {
+
+               @Override
+               public void keyReleased(KeyEvent e) {
+                       if (!checkValidPort(portTextbox.getText())) {
+                               connectButton.setButtonEnabled(false);
+                       } else {
+                               connectButton.setButtonEnabled(true);
+                       }
+               }
+
+               @Override
+               public void keyPressed(KeyEvent e) {
+
+               }
+       };
+
+       private boolean checkValidIP(String ipaddr) {
+               String[] splitstr = ipaddr.split("\\.");
+               if (splitstr == null || splitstr.length != CommonConstants.IPv4_OCTET_NUMBER) {
+                       return false;
+               }
+
+               for (int i = 0; i < CommonConstants.IPv4_OCTET_NUMBER; i++) {
+                       int classnum = Integer.parseInt(splitstr[i]);
+                       if (classnum < 0 || classnum > CommonConstants.MAX_OCTET_NUMBER) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+
+       private boolean checkValidPort(String port) {
+               if (port.isEmpty()) {
+                       return true;
+               }
+
+               int portnum = Integer.parseInt(port);
+
+               if (portnum < CommonConstants.MIN_PORT_NUMBER || portnum > CommonConstants.MAX_PORT_NUMBER) {
+                       return false;
+               } else {
+                       return true;
+               }
+       }
+
+       public String getAddress() {
+               return address;
+       }
+
+       public void setConnectionResult(boolean bresult) {
+               if (bresult) {
+                       // if succeeded to connect remote device
+                       result = AnalyzerConstants.SUCCESS;
+                       shell.close();
+               } else {
+                       // if failed to connect remote device
+                       address = null;
+
+                       progressIcon.setVisible(false);
+                       progressLabel.setVisible(false);
+
+                       connectButton.setButtonEnabled(true);
+                       ipTextbox.setEnabled(true);
+                       portTextbox.setEnabled(true);
+               }
+       }
+}
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/RemoteDeviceManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/RemoteDeviceManager.java
new file mode 100644 (file)
index 0000000..3d0affc
--- /dev/null
@@ -0,0 +1,81 @@
+package org.tizen.dynamicanalyzer.ui.toolbar;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Display;
+import org.tizen.dynamicanalyzer.common.path.PathManager;
+import org.tizen.dynamicanalyzer.util.CommonUtil;
+
+public class RemoteDeviceManager implements Runnable {
+       private static final String CMD_SDB_CONNECT = PathManager.SDB_PATH + " connect ";
+       private static final String CMD_SDB_DEVICE = PathManager.SDB_PATH + " devices";
+       private static final String CONNECTED_STR1 = "connected";
+       private static final String CONNECTED_STR2 = "already";
+
+       private static final long SLEEPTIME = 50;
+       private static final long MAX_WAITTIME = 5000;
+
+       private RemoteDeviceDialog parentDialog = null;
+
+       public RemoteDeviceManager(RemoteDeviceDialog dialog) {
+               parentDialog = dialog;
+       }
+
+       @Override
+       public void run() {
+               boolean bret = false;
+
+               // execute sdb connect command
+               String address = parentDialog.getAddress();
+               if (address != null) {
+                       String cmd = CMD_SDB_CONNECT + address;
+
+                       List<String> outputlines = new ArrayList<String>();
+                       if (CommonUtil.executeCommand(cmd, outputlines, null) && !outputlines.isEmpty()) {
+                               for (String line : outputlines) {
+                                       if (line.startsWith(CONNECTED_STR1) || line.contains(CONNECTED_STR2)) {
+                                               bret = true;
+                                               break;
+                                       }
+                               }
+                       }
+
+                       // wait for device is online
+                       if (bret) {
+                               bret = false;
+                               cmd = CMD_SDB_DEVICE;
+                               long starttime = System.currentTimeMillis();
+                               do {
+                                       outputlines.clear();
+                                       if (CommonUtil.executeCommand(cmd, outputlines, null) && !outputlines.isEmpty()) {
+                                               for (String line : outputlines) {
+                                                       if (line.startsWith(address)) {
+                                                               if (line.contains("device")) {
+                                                                       bret = true;
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                                       
+                                       try {
+                                               Thread.sleep(SLEEPTIME);
+                                       } catch (InterruptedException e) {
+                                               e.printStackTrace();
+                                               break;
+                                       }
+                               } while (System.currentTimeMillis() < starttime + MAX_WAITTIME);
+                       }
+               }
+
+               final boolean fret = bret;
+               // set result to dialog
+               Display.getDefault().syncExec(new Runnable() {
+                       @Override
+                       public void run() {
+                               parentDialog.setConnectionResult(fret);
+                       }
+               });
+       }
+}
index 01caad4..141b34e 100755 (executable)
@@ -204,14 +204,51 @@ public class ToolbarArea {
                                DeviceInfo oldDevInfo = Global.getCurrentDeviceInfo();
                                if (oldDevInfo != null)
                                        oldDeviceName = oldDevInfo.getIDevice().getSerialNumber();
-                               String serial = combo.getText();
+                               final String serial = combo.getText();
 
-                               if (serial != null && !serial.equals(oldDeviceName)) {
-                                       Global.setCurrentDeviceInfo(DACommunicator.setSelectedDeviceBySerial(serial));
-                                       if (null != serial && !serial.isEmpty()) {
+                               if (serial == null || serial.isEmpty()) {
+                                       Global.setCurrentDeviceInfo(null);
+                               } else {
+                                       if (serial.equals(AnalyzerConstants.REMOTE_DEVICE)) {
+                                               final String oldDevName = oldDeviceName;
+
+                                               Display.getDefault().asyncExec(new Runnable() {
+
+                                                       @Override
+                                                       public void run() {
+                                                               String newDevice = null;
+                                                               Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell();
+                                                               RemoteDeviceDialog pdialog = new RemoteDeviceDialog(shell);
+                                                               pdialog.open();
+                                                               String address = pdialog.getAddress();
+                                                               if (address != null && !address.isEmpty()) {
+                                                                       newDevice = address;
+                                                               } else {
+                                                                       newDevice = null;
+                                                               }
+
+                                                               if (newDevice == null) {
+                                                                       if (oldDevName == null)
+                                                                               deviceCombo.setText(CommonConstants.EMPTY);
+                                                                       else
+                                                                               deviceCombo.setText(oldDevName);
+                                                               } else {
+                                                                       deviceCombo.setText(newDevice);
+                                                               }
+
+                                                               if (newDevice != null && !newDevice.isEmpty()) {
+                                                                       DACommunicator.setSelectedDeviceBySerial(serial);
+                                                                       initAppCombo();
+                                                                       setRepalyButtonEnable(true);
+                                                               }
+                                                       }
+                                               });
+
+                                       } else if (!serial.equals(oldDeviceName)) {
+                                               DACommunicator.setSelectedDeviceBySerial(serial);
                                                initAppCombo();
+                                               setRepalyButtonEnable(true);
                                        }
-                                       setRepalyButtonEnable(true);
                                }
                        }
                });
@@ -470,9 +507,10 @@ public class ToolbarArea {
 
                        setToolbarStartStopState(true);
 
-                       if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty()) {
-                               deviceCombo.setEnabled(false);
-                       }
+                       // commented because REMOVE_DEVICE is added
+                       // if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty()) {
+                       // deviceCombo.setEnabled(false);
+                       // }
 
                        if (!deviceCombo.isEnabled() || null == Global.getCurrentDeviceInfo()) {
                                appCombo.setEnabled(false);
@@ -524,9 +562,11 @@ public class ToolbarArea {
 
                                setToolbarStartStopState(true);
 
-                               if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty()) {
-                                       deviceCombo.setEnabled(false);
-                               }
+                               // commented because REMOVE_DEVICE is added
+                               // if (null == DACommunicator.getDevices() || DACommunicator.getDevices().isEmpty())
+                               // {
+                               // deviceCombo.setEnabled(false);
+                               // }
 
                                if (!deviceCombo.isEnabled() || null == Global.getCurrentDeviceInfo()) {
                                        appCombo.setEnabled(false);
@@ -868,6 +908,7 @@ public class ToolbarArea {
                deviceCombo.initCombo();
                if (null == items || items.isEmpty()) {
                        deviceCombo.add(CommonConstants.EMPTY);
+                       deviceCombo.add(AnalyzerConstants.REMOTE_DEVICE);
                        deviceCombo.select(0);
                        appCombo.initCombo();
                        appCombo.setEnabled(false);
@@ -884,6 +925,7 @@ public class ToolbarArea {
                                        selIndex = i;
                                }
                        }
+                       deviceCombo.add(AnalyzerConstants.REMOTE_DEVICE);
 
                        deviceCombo.select(selIndex);
                        Global.setCurrentDeviceInfo(DACommunicator.getDeviceByName(items.get(selIndex)));
@@ -922,7 +964,7 @@ public class ToolbarArea {
                }
 
                List<PackageInfo> pkgList = new ArrayList<PackageInfo>();
-               
+
                // TODO : reconstruct real app list for app combo
                // relation between package and app?
                for (Map.Entry<String, PackageInfo> entry : pkgInfos.entrySet()) {
@@ -1005,7 +1047,7 @@ public class ToolbarArea {
                });
 
                addToAppCombo(pkgList);
-               
+
                return true;
        }
 
@@ -1214,6 +1256,8 @@ public class ToolbarArea {
                for (int i = 0; i < size; i++) {
                        deviceCombo.add(devices.get(i).getIDevice().getSerialNumber());
                }
+               deviceCombo.add(AnalyzerConstants.REMOTE_DEVICE);
+
                int index = deviceCombo.getItems().indexOf(selectedDevice);
                if (index >= 0) {
                        deviceCombo.setText(selectedDevice);
index 0e29e5d..54d59cd 100644 (file)
@@ -26,9 +26,6 @@
 
 package org.tizen.dynamicanalyzer.utils;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -51,39 +48,18 @@ public class RpmUtil {
                        String[] command = new String[] { toolPath, RpmUtil.getDebugInfoOption(), "-d",
                                        targetpath, rpmpath };
 
-                       BufferedReader reader = null;
-                       BufferedReader error = null;
-
-                       try {
-                               Runtime rt = Runtime.getRuntime();
-                               Process process = rt.exec(command);
-                               process.waitFor();
-                               reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
-
-                               String line = null;
-                               int lineCount = 0;
-                               while (null != (line = reader.readLine())) {
-                                       lineCount++;
-                                       if (lineCount == 1) {
-                                               Logger.debug("CHANGE DIR : " + line);
-                                       } else {
-                                               Logger.debug("EXTRACE RPM : " + line);
+                       List<String> outputlines = new ArrayList<String>();
+                       List<String> errorlines = new ArrayList<String>();
+                       if (CommonUtil.executeCommand(command, outputlines, errorlines)) {
+                               int linecount = outputlines.size();
+                               if (linecount < 2) {
+                                       Logger.debug("debug info file extract failed...");
+                                       if (errorlines.size() != 0) {
+                                               Logger.debug(errorlines.get(0));
                                        }
-                               }
-
-                               if (lineCount < 2) {
-                                       error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
-                                       String errorStr = error.readLine();
-                                       Logger.debug("debug info file extract failed... : " + errorStr);
                                } else {
                                        bret = true;
                                }
-                       } catch (IOException e) {
-                               e.printStackTrace();
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                       } finally {
-                               CommonUtil.tryClose(reader, error);
                        }
                }
 
@@ -96,27 +72,17 @@ public class RpmUtil {
                if (null != rpmpath) {
                        String toolPath = PathManager.getDebugInfoScript();
                        String[] command = new String[] { toolPath, RpmUtil.getDebugInfoOption(), "-l", rpmpath };
-                       BufferedReader reader = null;
-                       try {
-                               Runtime rt = Runtime.getRuntime();
-                               Process process = rt.exec(command);
-                               process.waitFor();
-                               reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
 
+                       List<String> outputlines = new ArrayList<String>();
+
+                       if (CommonUtil.executeCommand(command, outputlines, null)) {
                                ret = new ArrayList<String>();
-                               String line = null;
-                               while (null != (line = reader.readLine())) {
+                               for (String line : outputlines) {
                                        if (line.startsWith("./")) {
                                                line = line.substring(1);
                                                ret.add(line);
                                        }
                                }
-                       } catch (IOException e) {
-                               e.printStackTrace();
-                       } catch (InterruptedException e) {
-                               e.printStackTrace();
-                       } finally {
-                               CommonUtil.tryClose(reader);
                        }
                }