[Title] emulator-manager : add checking launching emulator status.
authorjihye kim <jihye1128.kim@samsung.com>
Mon, 10 Dec 2012 11:31:59 +0000 (20:31 +0900)
committerjihye kim <jihye1128.kim@samsung.com>
Mon, 10 Dec 2012 11:31:59 +0000 (20:31 +0900)
[Desc.] add checking launching emulator status.
[Issue] N_SE-16404

package/changelog
package/pkginfo.manifest
src/org/tizen/emulator/manager/vms/CheckingRunningEmulator.java [new file with mode: 0644]
src/org/tizen/emulator/manager/vms/Launcher.java
src/org/tizen/emulator/manager/vms/VMsWorker.java

index 96ef2cb..0805d13 100644 (file)
@@ -1,3 +1,7 @@
+* 1.3.67
+- add double checking launching emulator.
+== jihye kim <jihye1128.kim@samsung.com> 2012-12-10
+
 * 1.3.66
 - modify default skin phone shape skin -> general skina
 == jihye kim <jihye1128.kim@samsung.com> 2012-12-10
index c3cd0f8..ac239b5 100644 (file)
@@ -1,5 +1,5 @@
 Source: emulator-manager
-Version: 1.3.66
+Version: 1.3.67
 Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
 
 Package: emulator-manager
diff --git a/src/org/tizen/emulator/manager/vms/CheckingRunningEmulator.java b/src/org/tizen/emulator/manager/vms/CheckingRunningEmulator.java
new file mode 100644 (file)
index 0000000..d22442b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * JiHye Kim <jihye1128.kim@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.vms;
+
+import java.util.ArrayList;
+
+public class CheckingRunningEmulator {
+       private static ArrayList<String> emList = new ArrayList<String> ();
+
+       public static synchronized void addEmulator(String name) {
+               if (!emList.contains(name)) {
+                       emList.add(name);
+               }
+       }
+
+       public static synchronized void removeEmulator(String name) {
+               emList.remove(name);
+       }
+
+       public static synchronized boolean isContains(String name) {
+               return emList.contains(name);
+       }
+}
index 9eba07b..1e22f1e 100644 (file)
@@ -372,7 +372,16 @@ public class Launcher {
                        return false;
                }
 
-               return launch(cmd);
+               CheckingRunningEmulator.addEmulator(property.getName());
+               MonitoringEmulator monitor = new MonitoringEmulator(property);
+               if (launch(cmd)) {
+                       monitor.start();
+                       return true;
+               } else {
+                       CheckingRunningEmulator.removeEmulator(property.getName());
+                       monitor.interrupt();
+                       return false;
+               }
        }
 
        public boolean launch(List<String> cmd) {
@@ -425,3 +434,29 @@ public class Launcher {
                return true;
        }
 }
+
+class MonitoringEmulator extends Thread {
+       private VMsProperty property;
+       public MonitoringEmulator(VMsProperty property) {
+               this.property = property;
+               this.setDaemon(true);
+       }
+
+       public void run() {
+               while (true) {
+                       if (VMsWorker.checking(property)) {
+                               CheckingRunningEmulator.removeEmulator(property.getName());
+                               break;
+                       }
+
+                       synchronized(this) {
+                               try {
+                                       this.wait(500);
+                               } catch (InterruptedException e) {
+                                       EMLogger.getLogger().warning(e.getMessage());
+                                       break;
+                               }
+                       }
+               }
+       }
+}
\ No newline at end of file
index 23937cc..6a3cd3f 100644 (file)
@@ -254,6 +254,15 @@ public class VMsWorker {
                                return true;
                        }
                }
+
+               if (CheckingRunningEmulator.isContains(property.getName())) {
+                       return true;
+               }
+
+               return checking(property);
+       }
+
+       public static boolean checking(VMsProperty prop) {
                Logger logger = EMLogger.getLogger();
                boolean result = false;
 
@@ -291,7 +300,7 @@ public class VMsWorker {
                        stdOut = new BufferedReader(inputReader);
                        if(isLinux > -1) {
                                while ((line = stdOut.readLine()) != null) {
-                                       String imagePath = property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
+                                       String imagePath = prop.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
                                        if(line.contains(imagePath)) {
                                                //logger.log(Level.INFO, line + " contains " + imagePath);
                                                logger.log(Level.INFO, "emulator instance with the same name is running now (" + imagePath + ")");
@@ -303,7 +312,7 @@ public class VMsWorker {
                                while ((line = stdOut.readLine()) != null) {
                                        String[] titleName = line.split(",");
                                        // "split[split.length - 1]" is window title.
-                                       if(titleName[titleName.length - 1].startsWith("\"" + property.getName()+ ":261")) {
+                                       if(titleName[titleName.length - 1].startsWith("\"" + prop.getName()+ ":261")) {
                                                //logger.log(Level.INFO, "contains " + titleName[titleName.length - 1]);
                                                logger.log(Level.INFO, "emulator instance with the same name is running now (" + titleName[titleName.length - 1] + ")");
                                                result = true; 
@@ -312,7 +321,7 @@ public class VMsWorker {
                        }
                        else if(isMac > -1) {
                 while ((line = stdOut.readLine()) != null) {
-                        String imagePath = property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
+                        String imagePath = prop.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
                         if(line.contains(imagePath)) {
                                 //logger.log(Level.INFO, line + " contains " + imagePath);
                                 logger.log(Level.INFO, "emulator instance with the same name is running now (" + imagePath + ")");