[Title] fix. communication IDE - DA
authorHyunjongPark <hyunjongpark@hyunjongpark-Samsung-Desktop-System.(none)>
Wed, 26 Jun 2013 10:12:49 +0000 (19:12 +0900)
committerHyunjongPark <hyunjongpark@hyunjongpark-Samsung-Desktop-System.(none)>
Wed, 26 Jun 2013 10:12:49 +0000 (19:12 +0900)
[Desc.] bug fix
[Isseu] -

org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/communication/DAServerManager.java
org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/launch/TizenNativeApplicationDADelegate.java
org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/nl/Labels.java
org.tizen.dynamicanalysis.ide.eplugin/src/org/tizen/dynamicanalysis/ide/eplugin/nl/Labels.properties
package/pkginfo.manifest

index b2b9378..6449793 100644 (file)
 package org.tizen.dynamicanalysis.ide.eplugin.communication;
 
 import java.io.BufferedWriter;
+import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -36,6 +38,7 @@ import java.io.RandomAccessFile;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
 
 import org.eclipse.ui.PlatformUI;
 import org.tizen.common.core.application.InstallPathConfig;
@@ -45,7 +48,7 @@ import org.tizen.dynamicanalysis.ide.eplugin.nl.Labels;
 public class DAServerManager extends Thread {
        private final int MAXBUFSIZE = 1024;
 
-       private int port = 0;
+       private int idePort = 0;
        private static DAServerManager instance;
 
        private ServerSocket serverSocket = null;
@@ -106,17 +109,17 @@ public class DAServerManager extends Thread {
                                        serverSocket = setServePort();
                                        if (serverSocket != null) {
 
-                                               // Save Server port
-                                               if (savePortFile() != true) {
-                                                       DALog.printLog("failed Save Server port"); //$NON-NLS-1$
-                                                       continue;
-                                               }
-
                                                // Set Active IDE to File
                                                if (setActiveDAPlugin() != true) {
                                                        DALog.printLog("failed Set Active IDE to File "); //$NON-NLS-1$
-                                                       continue;
+                                               } else {
+                                                       // Save Server port
+                                                       if (savePortFile(true) != true) {
+                                                               DALog.printLog("failed Save Server port"); //$NON-NLS-1$
+                                                               continue;
+                                                       }
                                                }
+
                                                // Communication IDE - DA
                                                while (true) {
                                                        closeClientSokcet();
@@ -133,6 +136,10 @@ public class DAServerManager extends Thread {
 
                                                        // Waiting Receive Message
                                                        waitingDataReceive();
+                                                       if (savePortFile(true) != true) {
+                                                               DALog.printLog("failed Save Server port"); //$NON-NLS-1$
+                                                               continue;
+                                                       }
                                                        DALog.printLog("Disconneced DA"); //$NON-NLS-1$
                                                }
                                        } else {
@@ -147,6 +154,26 @@ public class DAServerManager extends Thread {
                }
        }
 
+       public boolean isAnotherIDEConnected() {
+               int saveFilePort = readActiveIdePort();
+               if (saveFilePort == -1) {
+                       if (savePortFile(false) != true) {
+                               DALog.printLog("failed Save Server port"); //$NON-NLS-1$
+                       }
+                       return false;
+               } else if (saveFilePort != -1 && saveFilePort == idePort) {
+                       if (savePortFile(false) != true) {
+                               DALog.printLog("failed Save Server port"); //$NON-NLS-1$
+                       }
+                       return false;
+               } else if (saveFilePort != -1 && saveFilePort != idePort) {
+                       return true;
+               } else {
+                       DALog.printLog("isAnotherIDEConnected - unknown status");
+               }
+               return false;
+       }
+
        private boolean checkInstalledTizenSDK() {
                String installPath = InstallPathConfig.getUserDataPath();
                File logs = new File(installPath.toString());
@@ -190,8 +217,8 @@ public class DAServerManager extends Thread {
                ServerSocket serverSocket = null;
                serverSocket = getServerSocket(0);
                if (serverSocket != null) {
-                       port = serverSocket.getLocalPort();
-                       DALog.printLog("IDE port " + port); //$NON-NLS-1$
+                       idePort = serverSocket.getLocalPort();
+                       DALog.printLog("IDE port " + idePort); //$NON-NLS-1$
 
                        return serverSocket;
                }
@@ -210,29 +237,37 @@ public class DAServerManager extends Thread {
                return serverSocket;
        }
 
+       public String getPortFile() {
+               StringBuffer savePath = new StringBuffer();
+               savePath.append(InstallPathConfig.getUserDataPath())
+                               .append(File.separatorChar).append(DANAIC_ANALYZER)
+                               .append(File.separatorChar).append(SAVE);
+
+               File logs = new File(savePath.toString());
+               if (!logs.exists()) {
+                       logs.mkdirs();
+               }
+
+               savePath.append(File.separatorChar).append(CURRENT_ACTIVE_IDE_PORT);
+               return savePath.toString();
+       }
+
        // Save Current Port
-       private boolean savePortFile() {
+       public boolean savePortFile(boolean isInitPort) {
                boolean bSuccess = true;
                try {
-                       StringBuffer savePath = new StringBuffer();
-                       savePath.append(InstallPathConfig.getUserDataPath())
-                                       .append(File.separatorChar).append(DANAIC_ANALYZER)
-                                       .append(File.separatorChar).append(SAVE);
-
-                       File logs = new File(savePath.toString());
-                       if (!logs.exists()) {
-                               logs.mkdirs();
-                       }
-
-                       savePath.append(File.separatorChar).append(CURRENT_ACTIVE_IDE_PORT);
-
-                       File file = new File(savePath.toString());
+                       File file = new File(getPortFile());
                        FileOutputStream fos = null;
 
                        fos = new FileOutputStream(file);
 
                        DataOutputStream dos = new DataOutputStream(fos);
-                       dos.writeInt(port);
+                       if (isInitPort) {
+                               dos.writeInt(-1);
+                       } else {
+                               dos.writeInt(idePort);
+                       }
+
                        dos.flush();
                        bSuccess = true;
 
@@ -246,9 +281,53 @@ public class DAServerManager extends Thread {
                return bSuccess;
        }
 
+       // read Current Port
+       private int readActiveIdePort() {
+               int port = -1;
+               FileInputStream fis = null;
+               DataInputStream dis = null;
+               try {
+                       fis = new FileInputStream(getPortFile());
+                       dis = new DataInputStream(fis);
+                       try {
+                               port = dis.readInt();
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       } finally {
+                               try {
+                                       if (null != fis) {
+                                               fis.close();
+                                       }
+                                       if (null != dis) {
+                                               dis.close();
+                                       }
+                               } catch (IOException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
+               } catch (FileNotFoundException e) {
+                       DALog.printLog("DAServerManager - readActiveIdePort - FileNotFoundException");
+               } finally {
+                       try {
+                               if (null != fis) {
+                                       fis.close();
+                               }
+                               if (null != dis) {
+                                       dis.close();
+                               }
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+               }
+               return port;
+       }
+
        // Set Active DA_Plugin
        private boolean setActiveDAPlugin() {
                File file = null;
+               FileLock fileLock = null;
                FileChannel fchannel = null;
 
                StringBuffer savePortPath = new StringBuffer();
@@ -263,10 +342,13 @@ public class DAServerManager extends Thread {
                        DALog.printLog("DAServerManager - setActiveDAPlugin - FileNotFoundException");
                }
                try {
-                       fchannel.tryLock();
+                       fileLock = fchannel.tryLock();
                } catch (IOException e) {
                        DALog.printLog("DAServerManager - setActiveDAPlugin - IOException");
                }
+               if (fileLock == null) {
+                       return false;
+               }
 
                return true;
        }
@@ -406,7 +488,7 @@ public class DAServerManager extends Thread {
        public Boolean getRecvDAReadyStatus() {
                return recvDAReadyStatus;
        }
-       
+
        public void setRecvDAReadyStatus(boolean status) {
                recvDAReadyStatus = status;
        }
index 3fcd6a8..5021b69 100644 (file)
@@ -119,11 +119,15 @@ public class TizenNativeApplicationDADelegate extends
                                                TizenLaunchMessages.CANNOT_CONNECT_TO_DEVICE, null));
                        }
 
-                       if (isDAReady()) {
-                               if (packaging_upload_install(project, currentDevice)) {
-                                       runDynamicAnalyzer(project, currentDevice);
+                       if (serverManager.isAnotherIDEConnected()) {
+                               newCoreException(Labels.MESSAGE_ANOTHER_IDE_CONNECTED, null);
+                       }else{
+                               if (isDAReady()) {
+                                       if (packaging_upload_install(project, currentDevice)) {
+                                               runDynamicAnalyzer(project, currentDevice);
+                                       }
                                }
-                       }
+                       }               
                } catch (CoreException e) {
                        DALog.dlgErrorMessage(Labels.MESSAGE_ERROR, e.getMessage());
                } finally {
index 870dc83..df8eae1 100644 (file)
@@ -41,6 +41,8 @@ public class Labels extends NLS {
     public static String MESSAGE_NOT_SUPPORT_UNIT_TEST_PROJECT;
     public static String MESSAGE_NOT_SUPPORT_IME_PROJECT;
     
+    public static String MESSAGE_ANOTHER_IDE_CONNECTED;
+    
     static {
         // initialize resource bundle
         NLS.initializeMessages(BUNDLE_NAME, Labels.class);
index 54fa7bc..feec3f8 100644 (file)
@@ -9,4 +9,5 @@ MESSAGE_BUILDING_PACKAGE=Building package...
 MESSAGE_DYNAMIC_ANALYZER_IS_NOT_INSTALLED=Dynamic Analyzer is not installed.
 
 MESSAGE_NOT_SUPPORT_UNIT_TEST_PROJECT=DA does not support tizen unit test project.
-MESSAGE_NOT_SUPPORT_IME_PROJECT=Certain application categories, such as "ime", cannot be launched by "Profile As".
\ No newline at end of file
+MESSAGE_NOT_SUPPORT_IME_PROJECT=Certain application categories, such as "ime", cannot be launched by "Profile As".
+MESSAGE_ANOTHER_IDE_CONNECTED= Dynamic Analyzer has been connected to another IDE\n You need to close the prior Dynamic Analyzer first.
\ No newline at end of file
index a4b4fb1..12109da 100644 (file)
@@ -1,4 +1,4 @@
-Version:2.1.23
+Version:2.1.24
 Source:dynamic-analysis-ide-eplugin
 Maintainer:Juyoung Kim <j0.kim@samsung.com>, Sanghyun Lee <sanghyunnim.lee@samsung.com>