import java.io.BufferedInputStream;
import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.vms.EmulatorVMs;
+import org.tizen.emulator.manager.vms.VMProcess;
import org.tizen.emulator.manager.vms.VMsProperty;
public class Launcher {
String kvm = "";
boolean exists = false;
int portNo;
- String StrPortNo = "";
- int c;
-
- //check if there is another Emulator instance with the same name
- String PortPath = new FileIO().getTizenVmsArchPath() + File.separator + property.getName() + File.separator + ".port";
- File file = new File(PortPath);
- exists = file.exists();
- if(exists) {
- try {
- FileReader in = new FileReader(PortPath);
- while((c=in.read()) != -1) {
- StrPortNo = StrPortNo + (char)c;
- }
- in.close();
- } catch(Exception e1) {
- e1.printStackTrace();
- }
-
- //FIXME
- /*
- Socket so = null;
- try {
- Socket so = new Socket("localhost", Integer.parseInt(StrPortNo) +1 );
- so.close();
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- } catch (IOException e) {
- // means portNo not in use
- MessageBox alert = new MessageBox(shell, SWT.OK);
- alert.setMessage("Can not launch this target: " + property.getName()
- + "\n※ Predictable Causes are below."
- +"\n1. Virtual target with the same name is running now."
- + "\n2. Emulator might be terminated abnormally before."
- + "\nIf case 1, exit existing virtual target and re-launch."
- + "\nIf case 2, delete the port info file: " + PortPath);
- alert.open();
- return;
- }
- */
+
+ VMProcess vmprocess = new VMProcess();
+ if(!vmprocess.checkIfRunning(property))
+ {
+ MessageBox alert = new MessageBox(shell, SWT.OK);
+ alert.setMessage("Can not execute emulator.\n Emulator instance with the same name is running now.");
+ alert.open();
+ return;
}
//check available port number.
+ height
+ "-32@60"
+ " dpi=" + property.getConfiguration().getDevice().getDisplay().getDensity().getValue()
- + " root=/dev/vda rw"
+ " ip=10.0.2.16::10.0.2.2:255.255.255.0::eth0:none 5 virtio-9p");
}
else {
+ height
+ "-32@60"
+ " dpi=" + property.getConfiguration().getDevice().getDisplay().getDensity().getValue()
- + " root=/dev/vda rw"
+ " ip=10.0.2.16::10.0.2.2:255.255.255.0::eth0:none 5");
}
cmd.add("-rtc");
cmd.add("base=utc");
cmd.add(kvm);
- /*
- if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1 && property.getConfiguration().getUsability().isHwVirtualization()) {
- File fi = new File("/dev/kvm");
- exists = fi.exists();
- if(exists) {
- cmd.add("-enable-kvm");
- }
- }
- */
+
// cmd.add("-redir");
// cmd.add("tcp:1202:10.0.2.16:22");
//System.out.println(cmd);
package org.tizen.emulator.manager.vms;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
errorMessage = "Throw unknown error";
}
+// check if the emulator instance with the same name is running now.
+ public boolean checkIfRunning(VMsProperty property)
+ {
+ int isLinux = System.getProperty("os.name").toLowerCase().indexOf("linux");
+ int isWindows = System.getProperty("os.name").toLowerCase().indexOf("linux");
+
+ try {
+ String line;
+ List<String> cmd = new ArrayList<String>();
+ if(isLinux > -1) {
+ cmd.add("/bin/ps");
+ cmd.add("-ef");
+ }
+ else if(isWindows > -1) {
+ cmd.add("tasklist");
+ cmd.add("/V");
+ cmd.add("/FI");
+ cmd.add("\"IMAGENAME eq emulator-x86\"");
+ }
+
+ ProcessBuilder pb = new ProcessBuilder(cmd);
+ Process p = pb.start();
+ BufferedReader stdOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
+
+ if(isLinux > -1) {
+ while ((line = stdOut.readLine()) != null) {
+ if(line.contains(FileIO.getInstance().getVirtualTargetPath(property.getName()))) {
+ // System.out.println("exist in"+ line);
+ stdOut.close();
+ return false;
+ }
+ }
+ }
+ else if(isWindows > -1) {
+ while ((line = stdOut.readLine()) != null) {
+ if(line.contains(property.getName()+ ":261")) {
+ //System.out.println("exist in"+ line);
+ stdOut.close();
+ return false;
+ }
+ }
+ }
+ stdOut.close();
+ System.out.println("not exist anywhere");
+ return true;
+ } catch (Exception err) {
+ err.printStackTrace();
+ return false;
+ }
+ }
+
+
public VMsProperty modify(VMsProperty property, VMPropertyValue oldVM, VMPropertyValue newVM) {
if (!newVM.resolution.equals(oldVM.resolution)) {
isModify = true;