import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.tool.FileIO;
-import org.tizen.emulator.manager.tool.Launcher;
import org.tizen.emulator.manager.ui.MainDialog;
import org.tizen.emulator.manager.vms.EmulatorVMs;
-import org.tizen.emulator.manager.vms.VMsProperty;
public class EmulatorManager {
private static final String ICON_FILE_NAME = "res/em.ico";
Image icon;
private MainDialog mainDialog;
- private Launcher launcher;
public EmulatorManager() {
this.display = new Display();
return instance;
}
- public Display getDisplay() {
- return display;
- }
-
public Shell getShell() {
return shell;
}
return mainDialog;
}
- public Launcher getLauncher() {
- return launcher;
- }
-
private void preare() {
mainDialog = new MainDialog();
display.dispose();
}
- public void launchVM(VMsProperty property) {
- Launcher.launch(property);
- }
-
private void dispose() {
mainDialog.dispose();
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.EmulatorManager;
-import org.tizen.emulator.manager.tool.Launcher;
import org.tizen.emulator.manager.ui.ResourceRegistry.ImageName;
import org.tizen.emulator.manager.ui.detail.DetailTableView;
import org.tizen.emulator.manager.ui.vmstree.VMsTree;
import org.tizen.emulator.manager.vms.EmulatorVMs;
import org.tizen.emulator.manager.vms.VMsProperty;
+import org.tizen.emulator.manager.vms.VMsWorkerException;
public class MainDialog {
private static String Launch = "Launch";
leftButton.setText(Launch);
leftButton.addSelectionListener(new SelectionListener() {
@Override
- public void widgetSelected(SelectionEvent e) {
+ public void widgetSelected(SelectionEvent event) {
String type = leftButton.getText();
if (type.equals(Launch)) {
- Launcher.launch(detailView.getCurrentPoperty());
+ try {
+ detailView.getCurrentPoperty().getWorker().launchVM();
+ } catch (VMsWorkerException e) {
+ MessageBox alert = new MessageBox(EmulatorManager.getInstance().getShell(), SWT.OK);
+ alert.setMessage(e.getMessage());
+ alert.open();
+ }
} else if (type.equals(Confirm)) {
VMsProperty pro = detailView.confirm();
if (pro != null) { // successs
}
}
@Override
- public void widgetDefaultSelected(SelectionEvent e) {
+ public void widgetDefaultSelected(SelectionEvent event) {
}
});
import org.tizen.emulator.manager.ui.ResourceRegistry.ImageName;
import org.tizen.emulator.manager.ui.detail.VMPropertyView;
import org.tizen.emulator.manager.ui.vmstree.VMsTree;
+import org.tizen.emulator.manager.vms.Creator;
import org.tizen.emulator.manager.vms.EmulatorVMs;
import org.tizen.emulator.manager.vms.VMCreateHelper;
-import org.tizen.emulator.manager.vms.VMProcess;
import org.tizen.emulator.manager.vms.VMPropertyValue;
import org.tizen.emulator.manager.vms.VMsProperty;
+import org.tizen.emulator.manager.vms.VMsWorkerException;
public class MenuHandling {
private Shell shell;
}
public void resetVirtualMachine() {
- if (listTable.getSelectionContentCount() == 1) {
- if (!checkRunnigVM(listTable.getSelectionItem())) {
- return;
- }
- }
-
MessageBox msg = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
msg.setText("Warning");
msg.setMessage("This emulator will be formatting.\nAre you sure to conitnue?");
int response = msg.open();
- boolean success = false;
- if (response == SWT.OK) {
- if (listTable.getSelectionContentCount() == 1) {
- if (!resetProcess(listTable.getSelectionItem())) {
- return;
- }
- } else {
- ArrayList<VMsProperty> list = listTable.getSelectionItems();
- for (VMsProperty property : list) {
- if (!checkRunnigVM(property)) {
- continue;
- }
- if (!resetProcess(property)) {
- continue;
- }
- success = true;
- }
+
+ msg = new MessageBox(shell, SWT.ICON_INFORMATION);
+ msg.setText("INFO");
+ if (response != SWT.OK)
+ return;
+
+ VMsProperty[] properties = listTable.getSelectionItems();
+ for (VMsProperty property : properties) {
+ if(property.getWorker().isRunningNow()) {
+ msg.setMessage("[" + property.getName() + "] is running now...\n" +
+ "Reset is canceled !");
+ msg.open();
+
+ return;
}
}
- msg = new MessageBox(shell, SWT.ICON_INFORMATION);
- msg.setText("INFO");
- if (!success) {
- msg.setMessage("Reset failed!");
- } else {
- msg.setMessage("Reset completed!");
+ for (VMsProperty property : properties) {
+ try {
+ property.getWorker().resetVM();
+ } catch (VMsWorkerException e) {
+ msg.setMessage(" Reset for [" + property.getName() + "] failed...\n"
+ + e.getMessage());
+ msg.open();
+
+ break;
+ }
}
- msg.open();
}
private boolean checkRunnigVM(VMsProperty property) {
- VMProcess process = new VMProcess();
MessageBox msg = null;
- if (!process.checkIfRunning(property)) {
+
+ if(property.getWorker().isRunningNow()) {
msg = new MessageBox(shell, SWT.ICON_INFORMATION);
msg.setText("INFO");
msg.setMessage("Emulator is running now\nEmulator Name : " + property.getName());
msg.open();
- return false;
+
+ return false;
}
- return true;
- }
-
- private boolean resetProcess(VMsProperty property) {
- VMProcess process = new VMProcess();
- MessageBox msg = null;
- String basePath = property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue();
- String targetPath = property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
- if (basePath == null || basePath.isEmpty() || targetPath == null || targetPath.isEmpty()) {
- msg = new MessageBox(shell, SWT.ICON_INFORMATION);
- msg.setText("INFO");
- msg.setMessage("Fail reset Emulator\nEmulator Name : " + property.getName());
- msg.open();
- return false;
- }
-
- if(!process.createBaseImage(basePath, targetPath)) {
- msg = new MessageBox(shell, SWT.ICON_INFORMATION);
- msg.setText("INFO");
- msg.setMessage("Fail reset Emulator\nEmulator Name : " + property.getName()
- +"\n" + process.getErrorMessage());
- msg.open();
- return false;
- }
return true;
}
return false;
}
} else {
- ArrayList<VMsProperty> list = listTable.getSelectionItems();
+ ArrayList<VMsProperty> list = listTable.getSelectionItemsList();
for (VMsProperty property : list) {
if (!checkRunnigVM(property)) {
continue;
msg.setText("INFO");
msg.setMessage("Delete completed!");
msg.open();
+
+ return true;
}
- return true;
+ return false;
}
private VMsProperty property = null;
}
@Override
public void widgetSelected(SelectionEvent arg0) {
- VMPropertyValue vmValue = new VMPropertyValue();
- vmValue.settingValue(property);
+ VMPropertyValue vmValue = property.getPropertyValue();
vmValue.imageName = vmName;
- VMProcess process = new VMProcess();
- VMsProperty p = process.create(vmValue);
MessageBox msg = new MessageBox(shell, SWT.ICON_INFORMATION);
msg.setText("INFO");
- if (p != null) {
+ try {
+ Creator.create(vmValue);
msg.setMessage("Success cloning Emulator!");
- } else {
- msg.setMessage(process.getErrorMessage());
+ } catch (VMsWorkerException e) {
+ msg.setMessage(e.getMessage());
}
+
msg.open();
dialog.close();
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
-import org.tizen.emulator.manager.EmulatorManager;
+import org.eclipse.swt.widgets.Display;
public class ResourceRegistry {
public enum ImageName {
for(ImageName imageName : ImageName.values()) {
is = loader.getResourceAsStream("res/" + imageName.toString() + ".png");
if(is != null)
- instance.imagesMap.put(imageName, new Image(EmulatorManager.getInstance().getDisplay(), is));
+ instance.imagesMap.put(imageName, new Image(Display.getCurrent(), is));
}
}
}
public class DetailTableView {
static final int[] DEFAULT_WEIGHT = new int[] { 60, 40 };
+ static final int[] STATUS_CLOSE_WEIGHT = new int[] { 100, 0 };
private static String Modify = "Modify";
private static String Create = "Create";
if(isDetailOpened) {
weight = mainDialog.getSashFormWeight();
- mainDialog.setDetailViewWeights(new int[] { 100, 0 });
+ mainDialog.setDetailViewWeights(STATUS_CLOSE_WEIGHT);
isDetailOpened = false;
}
}
import org.eclipse.swt.widgets.Text;
import org.tizen.emulator.manager.ui.ResourceRegistry;
import org.tizen.emulator.manager.ui.ResourceRegistry.ImageName;
+import org.tizen.emulator.manager.vms.Creator;
import org.tizen.emulator.manager.vms.VMCreateHelper;
-import org.tizen.emulator.manager.vms.VMProcess;
import org.tizen.emulator.manager.vms.VMPropertyValue;
import org.tizen.emulator.manager.vms.VMsProperty;
+import org.tizen.emulator.manager.vms.VMsWorkerException;
enum CItem{
ImageName("Name"), ImageNameInfo(""), BaseImage("BaseImage"),
private static String SEFARATOR = File.separator;
private VMCreateHelper helper;
private VMViewWidget widget;
- private VMProcess process;
private VMsProperty property;
private Table table;
private Image image = null;
public VMPropertyView(Table table) {
this.helper = new VMCreateHelper();
- this.process = new VMProcess();
this.widget = new VMViewWidget();
this.table = table;
this.image = ResourceRegistry.getImage(ImageName.FOLDER);
}
this.property = property;
- oldValue = new VMPropertyValue();
- oldValue.settingValue(property);
+ oldValue = property.getPropertyValue();
widget.itemList.get(DItem.ImageName.ordinal()).setText(1, oldValue.imageName);
this.isCreateMode = true;
settingCreateColumn();
- oldValue = new VMPropertyValue();
- oldValue.defaultSetting(isDefaultImage);
- oldValue.isDefaultImage = isDefaultImage;
+ oldValue = VMPropertyValue.getDefault(isDefaultImage);
widget.itemList.get(CItem.ImageName.ordinal()).setText(1, oldValue.imageName);
}
public void modifyView(Button confirm) {
- newValue = new VMPropertyValue(oldValue);
+ newValue = oldValue.clone();
widget.confirmButton = confirm;
createNameArea(table);
}
public void createView(Button confirm) {
- newValue = new VMPropertyValue(oldValue);
+ newValue = oldValue.clone();
widget.confirmButton = confirm;
createNameArea(table);
if (widget.baseImageFD == null) {
// TODO : x86 is hard cording (create)
widget.baseImageFD = new FileDialog(table.getShell(), SWT.OPEN);
- widget.baseImageFD.setText(String.format("Select existing Base Image(%s)", oldValue.arcType));
- String[] filter = {String.format("*.%s", oldValue.arcType)};
- String[] filterName = {String.format("Disk Image Files(*.%s)", oldValue.arcType)};
+ widget.baseImageFD.setText(String.format("Select existing Base Image(%s)", oldValue.archType));
+ String[] filter = {String.format("*.%s", oldValue.archType)};
+ String[] filterName = {String.format("Disk Image Files(*.%s)", oldValue.archType)};
widget.baseImageFD.setFilterExtensions(filter);
widget.baseImageFD.setFilterNames(filterName);
}
public VMsProperty confirm() {
VMsProperty p = null;
-
- if (isCreateMode) {
- p = process.create(newValue);
- } else {
- p = process.modify(property, oldValue, newValue);
- }
MessageBox msg = new MessageBox(table.getShell(), SWT.ICON_INFORMATION);
- msg.setText("INFO");
- if (p != null) {
+
+ try {
if (isCreateMode) {
- msg.setMessage("Success creating emulator!");
- } else {
+ p = Creator.create(newValue);
+ msg.setMessage("Success creating emulator!");
+ }
+ else {
+ property.getWorker().modifyVM(oldValue, newValue);
+ p = property;
msg.setMessage("Success modifying emulator!");
}
- } else {
- msg.setMessage(process.getErrorMessage());
+ } catch (VMsWorkerException e) {
+ msg.setText("INFO");
+ msg.setMessage(e.getMessage());
}
+
msg.open();
+
return p;
}
}
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.ui.ResourceRegistry;
import org.tizen.emulator.manager.ui.ResourceRegistry.ImageName;
import org.tizen.emulator.manager.vms.VMsProperty;
+import org.tizen.emulator.manager.vms.VMsWorkerException;
public class ContextMenu {
Menu treeMenu;
launchItem.setImage(ResourceRegistry.getImage(ImageName.LAUNCH));
launchItem.addSelectionListener(new SelectionListener() {
@Override
- public void widgetSelected(SelectionEvent e) {
+ public void widgetSelected(SelectionEvent event) {
if(vmsTree.getSelectionCount() > 1)
return;
VMsProperty property = ((PropertyContent)vmsTree.getSelection()[0].getData()).property;
- EmulatorManager.getInstance().launchVM(property);
+ try {
+ property.getWorker().launchVM();
+ } catch (VMsWorkerException e) {
+ MessageBox alert = new MessageBox(EmulatorManager.getInstance().getShell(), SWT.OK);
+ alert.setMessage(e.getMessage());
+ alert.open();
+ }
}
@Override
- public void widgetDefaultSelected(SelectionEvent e) {
+ public void widgetDefaultSelected(SelectionEvent event) {
}
});
final MenuItem modifyItem = new MenuItem(treeMenu, SWT.NONE);
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TreeItem;
-import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.ui.ResourceRegistry;
import org.tizen.emulator.manager.vms.VMsProperty;
if(font == null) {
FontData[] fontData = item.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
- font = new Font(EmulatorManager.getInstance().getDisplay(), fontData);
+ font = new Font(Display.getCurrent(), fontData);
ResourceRegistry.addFont(SWT.BOLD, font);
}
item.setFont(font);
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.tizen.emulator.manager.vms.VMsProperty;
import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
import org.tizen.emulator.manager.vms.VMsProperty.FSImageType;
+import org.tizen.emulator.manager.vms.VMsWorkerException;
public class VMsTree {
MainDialog mainDialog;
vmsTree.addSelectionListener(new SelectionListener() {
@Override
- public void widgetSelected(SelectionEvent e) {
+ public void widgetSelected(SelectionEvent event) {
if(vmsTree.getSelectionCount() == 0)
return;
}
@Override
- public void widgetDefaultSelected(SelectionEvent e) {
+ public void widgetDefaultSelected(SelectionEvent event) {
if(vmsTree.getSelectionCount() > 1) {
return;
}
return;
VMsProperty property = ((PropertyContent)vmsTree.getSelection()[0].getData()).property;
- EmulatorManager.getInstance().launchVM(property);
+ try {
+ property.getWorker().launchVM();
+ } catch (VMsWorkerException e) {
+ MessageBox alert = new MessageBox(EmulatorManager.getInstance().getShell(), SWT.OK);
+ alert.setMessage(e.getMessage());
+ alert.open();
+ }
}
});
}
return count;
}
- public ArrayList<VMsProperty> getSelectionItems() {
+ public VMsProperty[] getSelectionItems() {
+ VMsProperty[] properties = new VMsProperty[vmsTree.getSelectionCount()];
+
+ for(int i = 0; i < properties.length; ++i) {
+ properties[i] = ((PropertyContent)vmsTree.getSelection()[i].getData()).property;
+ }
+
+ return properties;
+ }
+
+ public ArrayList<VMsProperty> getSelectionItemsList() {
ArrayList<VMsProperty> list = new ArrayList<VMsProperty>();
VMsProperty property = null;
--- /dev/null
+package org.tizen.emulator.manager.vms;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.emulator.manager.tool.FileIO;
+import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
+import org.tizen.emulator.manager.vms.xml.DisplayType.Resolution;
+import org.tizen.emulator.manager.vms.xml.EmulatorConfiguration;
+import org.tizen.emulator.manager.vms.xml.ObjectFactory;
+
+public class Creator {
+ VMsProperty property;
+ VMPropertyValue newVM;
+
+ File folder;
+
+ private Creator() {} // for createInitialVMImage;
+
+ private Creator(VMPropertyValue newVM) {
+ this.property = EmulatorVMs.getInstance().getNewProperty(newVM.imageName, Architecture.x86);;
+ this.newVM = newVM;
+
+ this.folder = new File(FileIO.getInstance().getVirtualTargetPath(newVM.imageName));
+ }
+
+ public VMsProperty createInternal() throws VMsWorkerException {
+ if (this.property == null) {
+ throw new VMsWorkerException("Create failed virtual target property");
+ }
+
+ folder.mkdirs();
+
+ try {
+ createDiskImage();
+ createFileShare();
+ createDisplay();
+ createRam();
+ createSDCard();
+ }
+ catch(VMsCreatorException e) {
+ deleteFolder(folder);
+ throw e;
+ }
+
+ File log = new File(FileIO.getInstance().getVirtualTargetLogPath(newVM.imageName));
+ log.mkdir();
+
+ settingProperty();
+
+ EmulatorVMs.getInstance().storeXML(property);
+
+ return property;
+ }
+
+ private void deleteFolder(File folder) {
+ if (folder.exists()) {
+ for (File dir : folder.listFiles()) {
+ if (dir.isFile()) {
+ dir.delete();
+ } else { // directory
+ for (File sub : dir.listFiles()) {
+ if (sub.isFile()) {
+ sub.delete();
+ }
+ }
+ dir.delete();
+ }
+ }
+ folder.delete();
+ }
+ }
+
+ private void createDiskImage() throws VMsCreatorException {
+ if (newVM.baseImagePath == null || newVM.baseImagePath.isEmpty()) {
+ newVM.baseImagePath = FileIO.getInstance().getBaseimgPath();
+ }
+
+ if (!new File(newVM.baseImagePath).exists()) {
+ throw new VMsCreatorException("Base image does not exist.");
+ }
+
+ String targetPath = folder.getAbsolutePath() + File.separator + "emulimg-" +
+ newVM.imageName + "." + Architecture.x86.toString();
+ createInitialVMImageInternal(newVM.baseImagePath, targetPath);
+ }
+
+ public void createInitialVMImageInternal(String baseImagePath, String targetImagePath) throws VMsCreatorException {
+ String exe_path = FileIO.getInstance().getBinPath() + File.separator + "qemu-img";
+
+ List<String> cmd = new ArrayList<String>();
+ cmd.add(exe_path);
+ cmd.add("create");
+ cmd.add("-b");
+ cmd.add(baseImagePath);
+ cmd.add("-f");
+ cmd.add("qcow2");
+ cmd.add(targetImagePath);
+
+ ProcessBuilder pb = new ProcessBuilder(cmd);
+ try {
+ pb.start();
+ } catch (IOException e) {
+ throw new VMsCreatorException("Emulator image create failed!\n" + e.getMessage());
+ }
+ }
+
+ // usability
+ private void createFileShare() throws VMsCreatorException {
+ if (newVM.isFileShareSupport) {
+ if (newVM.fileSharePath == null || newVM.fileSharePath.isEmpty()) {
+ throw new VMsCreatorException("Select sharing file path");
+ }
+ }
+ }
+
+ // Device
+ private void createDisplay() throws VMsCreatorException {
+ int i = newVM.resolution.indexOf('x');
+ newVM.resolutionType = new Resolution();
+ newVM.resolutionType.setWidth(Integer.valueOf(newVM.resolution.substring(0,i)));
+ newVM.resolutionType.setHeight(Integer.valueOf(newVM.resolution.substring(i+1,newVM.resolution.length())));
+
+ if (newVM.skinPath == newVM.skinPathName) {
+ newVM.skinPath = FileIO.getInstance().getSkinPath() + File.separator + newVM.skinPathName;
+ }
+ }
+
+ private void createRam() {}
+
+ private void createSDCard() throws VMsCreatorException {
+ if (newVM.isSDCardSupport) {
+ try {
+ Modifier.modifySDCard(newVM);
+ } catch (VMsWorkerException e) {
+ throw new VMsCreatorException(e.getMessage());
+ }
+ }
+ }
+
+ private void settingProperty() {
+ ObjectFactory factory = EmulatorVMs.getInstance().getObjectFactory();
+ EmulatorConfiguration ec = property.getConfiguration();
+ ec.setBaseInformation(factory.createBaseInformationType());
+ ec.setUsability(factory.createUsabilityType());
+ ec.setDevice(factory.createDeviceType());
+
+ ec.getBaseInformation().setName(newVM.imageName);
+ ec.getBaseInformation().setArchitecture(Architecture.x86.toString());
+
+ ec.getBaseInformation().setDiskImage(factory.createBaseInformationTypeDiskImage());
+ if (newVM.isDefaultImage) {
+ ec.getBaseInformation().getDiskImage().setType("standard");
+ // TODO : get version
+ ec.getBaseInformation().getDiskImage().setVersion("1.0");
+ } else {
+ ec.getBaseInformation().getDiskImage().setType("custom");
+ }
+
+ //
+ ec.getBaseInformation().getDiskImage().setBaseDiskImage(factory.createDiskImageFormatType());
+ ec.getBaseInformation().getDiskImage().setCurrentDiskImage(factory.createDiskImageFormatType());
+
+ // TODO :
+ ec.getBaseInformation().getDiskImage().getBaseDiskImage().setFormat("qcow2");
+ ec.getBaseInformation().getDiskImage().getBaseDiskImage().setValue(newVM.baseImagePath);
+ ec.getBaseInformation().getDiskImage().getCurrentDiskImage().setFormat("qcow2");
+ ec.getBaseInformation().getDiskImage().getCurrentDiskImage().setValue(
+ folder.getAbsolutePath() + File.separator + "emulimg-" + newVM.imageName + "." + Architecture.x86.toString());
+
+ ec.getUsability().setLogging(factory.createUsabilityTypeLogging());
+ ec.getUsability().getLogging().setLevel("NONE");
+ ec.getUsability().setHwVirtualization(true);
+
+ ec.getUsability().setFileSharing(factory.createUsabilityTypeFileSharing());
+ if (!newVM.fileSharePath.isEmpty()) {
+ ec.getUsability().getFileSharing().setPath(newVM.fileSharePath);
+ }
+
+ ec.getDevice().setDisplay(factory.createDisplayType());
+ ec.getDevice().getDisplay().setResolution(factory.createDisplayTypeResolution());
+ ec.getDevice().getDisplay().getResolution().setWidth(newVM.resolutionType.getWidth());
+ ec.getDevice().getDisplay().getResolution().setHeight(newVM.resolutionType.getHeight());
+
+ ec.getDevice().getDisplay().setDensity(factory.createDisplayTypeDensity());
+ ec.getDevice().getDisplay().getDensity().setUnit("dpi");
+ ec.getDevice().getDisplay().getDensity().setValue(newVM.dpi);
+
+ ec.getDevice().getDisplay().setSkinPath(factory.createDisplayTypeSkinPath());
+ ec.getDevice().getDisplay().getSkinPath().setPath(newVM.skinPath);
+
+ ec.getDevice().setRAM(factory.createRamType());
+ ec.getDevice().getRAM().setSize(factory.createRamTypeSize());
+ ec.getDevice().getRAM().getSize().setUnit("MiB");
+ ec.getDevice().getRAM().getSize().setValue(newVM.ramSize);
+
+ ec.getDevice().setStorage(factory.createStorageType());
+ ec.getDevice().getStorage().setSDCard(factory.createStorageTypeSDCard());
+ if (newVM.isSDCardSupport) {
+ ec.getDevice().getStorage().getSDCard().setDiskImage(newVM.SDCardPath);
+ }
+ }
+
+ public static VMsProperty create(VMPropertyValue newVM) throws VMsWorkerException {
+ return new Creator(newVM).createInternal();
+ }
+
+ public static void createInitialVMImage(String basePath, String targetPath) throws VMsCreatorException {
+ new Creator().createInitialVMImageInternal(basePath, targetPath);
+ }
+}
-package org.tizen.emulator.manager.tool;
+package org.tizen.emulator.manager.vms;
import java.io.BufferedInputStream;
import java.io.File;
import org.eclipse.swt.widgets.MessageBox;
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;
+import org.tizen.emulator.manager.tool.FileIO;
+import org.tizen.emulator.manager.tool.PortHelper;
public class Launcher {
private Launcher() {}
- public static void launch(VMsProperty property) {
+ static boolean launch(VMsProperty property) {
Shell shell = EmulatorManager.getInstance().getShell();
String binary;
boolean exists = false;
int portNo;
- VMProcess vmprocess = new VMProcess();
- if(!vmprocess.checkIfRunning(property))
- {
- MessageBox alert = new MessageBox(shell, SWT.OK);
- alert.setMessage("Can not execute emulator.\nEmulator instance with the same name is running now.");
- alert.open();
- return;
- }
-
//check available port number.
portNo = new PortHelper().getPortNo();
if(portNo == -1) {
MessageBox alert = new MessageBox(shell, SWT.OK);
alert.setMessage("Can not execute emulator.\n All available ports are in use.");
alert.open();
- return;
+ return false;
}
if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1)
} catch (IOException e) {
e.printStackTrace();
+ return false;
}
+ return true;
}
}
--- /dev/null
+package org.tizen.emulator.manager.vms;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.tizen.emulator.manager.tool.FileIO;
+
+public class Modifier {
+ private Modifier() {}
+
+ static void modify(VMsProperty property, VMPropertyValue oldVM, VMPropertyValue newVM) throws VMsWorkerException {
+ if(oldVM.equals(newVM)) // if nothing if modified...
+ return;
+
+ if (!newVM.resolution.equals(oldVM.resolution)) {
+ int i = newVM.resolution.indexOf('x');
+ oldVM.resolutionType.setWidth(Integer.valueOf(newVM.resolution.substring(0,i)));
+ oldVM.resolutionType.setHeight(Integer.valueOf(newVM.resolution.substring(i+1,newVM.resolution.length())));
+ property.getConfiguration().getDevice().getDisplay().setResolution(oldVM.resolutionType);
+ }
+
+ if (newVM.dpi != oldVM.dpi) {
+ property.getConfiguration().getDevice().getDisplay().getDensity().setValue(newVM.dpi);
+ }
+
+ if (newVM.skinPath != oldVM.skinPath) {
+ if (newVM.skinPath == newVM.skinPathName) {
+ newVM.skinPath = FileIO.getInstance().getSkinPath() + File.separator + newVM.skinPathName;
+ }
+ if (property.getConfiguration().getDevice().getDisplay().getSkinPath() == null) {
+ property.getConfiguration().getDevice().getDisplay().setSkinPath
+ (EmulatorVMs.getInstance().getObjectFactory().createDisplayTypeSkinPath());
+ }
+ property.getConfiguration().getDevice().getDisplay().getSkinPath().setPath(newVM.skinPath);
+ }
+
+ if (newVM.isSDCardSupport != oldVM.isSDCardSupport) {
+ if (newVM.isSDCardSupport) {
+ modifySDCard(newVM);
+ property.getConfiguration().getDevice().getStorage().getSDCard().setDiskImage(newVM.SDCardPath);
+ } else {
+ property.getConfiguration().getDevice().getStorage().getSDCard().setDiskImage(null);
+ }
+ } else if (newVM.isSDCardSupport && !newVM.SDCardPathName.equals(oldVM.SDCardPathName)) {
+ modifySDCard(newVM);
+ property.getConfiguration().getDevice().getStorage().getSDCard().setDiskImage(newVM.SDCardPath);
+ }
+
+ if (newVM.ramSize != oldVM.ramSize) {
+ property.getConfiguration().getDevice().getRAM().getSize().setValue(newVM.ramSize);
+ }
+
+ if (newVM.isFileShareSupport != oldVM.isFileShareSupport) {
+ if (newVM.isFileShareSupport && !newVM.fileSharePath.isEmpty()) {
+ property.getConfiguration().getUsability().getFileSharing().setPath(newVM.fileSharePath);
+ } else {
+ property.getConfiguration().getUsability().getFileSharing().setPath(null);
+ }
+ } else if (newVM.isFileShareSupport && !newVM.fileSharePath.equals(oldVM.fileSharePath)) {
+ property.getConfiguration().getUsability().getFileSharing().setPath(newVM.fileSharePath);
+ }
+
+ EmulatorVMs.getInstance().storeXML(property);
+ }
+
+ static void modifySDCard(VMPropertyValue newVM) throws VMsWorkerException {
+ if (newVM.SDCardPath.endsWith("MB)")) { // New
+ String sdCardName = newVM.SDCardPath.substring(0, newVM.SDCardPath.lastIndexOf(" "));
+ String dataPath = FileIO.getInstance().getDataPath() + File.separator + sdCardName;
+
+ File src = new File(dataPath);
+ if(!src.exists()) {
+ throw new VMsWorkerException("SD Card image create failed!\nFile is not existing :" + dataPath);
+ }
+
+ File dest = new File(FileIO.getInstance().getVirtualTargetPath(newVM.imageName) + File.separator + sdCardName);
+ try {
+ dest.createNewFile();
+ newVM.SDCardPath = dest.getAbsolutePath();
+ } catch (IOException e) {
+ throw new VMsWorkerException("Create new image path is failed !");
+ }
+
+ FileReader in = null;
+ FileWriter out = null;
+ try {
+ in = new FileReader(src);
+ out = new FileWriter(dest);
+
+ int c;
+ while((c = in.read()) != -1) {
+ out.write(c);
+ }
+ } catch (FileNotFoundException e) {
+ throw new VMsWorkerException("SD Card image create failed!\n" + e.getMessage());
+ } catch (IOException e) {
+ throw new VMsWorkerException("SD Card image create failed!\n" + e.getMessage());
+ }finally {
+ try {
+ if (in != null) in.close();
+ if (out != null) out.close();
+ } catch (IOException e) {
+ throw new VMsWorkerException(e.getMessage());
+ }
+ }
+ } else {
+ if (newVM.SDCardPath == null || newVM.SDCardPath.isEmpty()) {
+ throw new VMsWorkerException("Select an existing sdcard image !");
+ }
+
+ if (newVM.SDCardPath.equals("( None )")) {
+ throw new VMsWorkerException("Select an existing sdcard image !");
+ }
+ }
+ }
+}
+++ /dev/null
-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;
-
-import org.tizen.emulator.manager.tool.FileIO;
-import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
-import org.tizen.emulator.manager.vms.xml.DisplayType.Resolution;
-import org.tizen.emulator.manager.vms.xml.EmulatorConfiguration;
-import org.tizen.emulator.manager.vms.xml.ObjectFactory;
-
-public class VMProcess {
- private static String SEFARATOR = File.separator;
- private FileIO filePath;
- private String errorMessage;
-
- // for modify
- private boolean isModify = false;
-
- // for create
- private String folderPath = null;
- private VMsProperty property;
- private VMPropertyValue newVM;
-
- public VMProcess() {
- filePath = FileIO.getInstance();
- 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("windows");
-
- 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 java.exe\"");
- }
-
- 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().getVirtualTargetImagePath(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;
- int i = newVM.resolution.indexOf('x');
- oldVM.resolutionType.setWidth(Integer.valueOf(newVM.resolution.substring(0,i)));
- oldVM.resolutionType.setHeight(Integer.valueOf(newVM.resolution.substring(i+1,newVM.resolution.length())));
- property.getConfiguration().getDevice().getDisplay().setResolution(oldVM.resolutionType);
- }
-
- if (newVM.dpi != oldVM.dpi) {
- isModify = true;
- property.getConfiguration().getDevice().getDisplay().getDensity().setValue(newVM.dpi);
- }
-
- if (newVM.skinPath != oldVM.skinPath) {
- if (newVM.skinPath == newVM.skinPathName) {
- newVM.skinPath = filePath.getSkinPath() + SEFARATOR + newVM.skinPathName;
- }
- if (property.getConfiguration().getDevice().getDisplay().getSkinPath() == null) {
- property.getConfiguration().getDevice().getDisplay().setSkinPath
- (EmulatorVMs.getInstance().getObjectFactory().createDisplayTypeSkinPath());
- }
- property.getConfiguration().getDevice().getDisplay().getSkinPath().setPath(newVM.skinPath);
- }
-
- if (newVM.isSDCardSupport != oldVM.isSDCardSupport) {
- isModify = true;
- if (newVM.isSDCardSupport) {
- if (!modifySDCard(newVM)) {
- return null;
- }
- property.getConfiguration().getDevice().getStorage().getSDCard().setDiskImage(newVM.SDCardPath);
- } else {
- property.getConfiguration().getDevice().getStorage().getSDCard().setDiskImage(null);
- }
- } else if (newVM.isSDCardSupport && !newVM.SDCardPathName.equals(oldVM.SDCardPathName)) {
- if (!modifySDCard(newVM)) {
- return null;
- }
- isModify = true;
- property.getConfiguration().getDevice().getStorage().getSDCard().setDiskImage(newVM.SDCardPath);
- }
-
- if (newVM.ramSize != oldVM.ramSize) {
- isModify = true;
- property.getConfiguration().getDevice().getRAM().getSize().setValue(newVM.ramSize);
- }
-
- if (newVM.isFileShareSupport != oldVM.isFileShareSupport) {
- isModify = true;
- if (newVM.isFileShareSupport && !newVM.fileSharePath.isEmpty()) {
- property.getConfiguration().getUsability().getFileSharing().setPath(newVM.fileSharePath);
- } else {
- property.getConfiguration().getUsability().getFileSharing().setPath(null);
- }
- } else if (newVM.isFileShareSupport && !newVM.fileSharePath.equals(oldVM.fileSharePath)) {
- isModify = true;
- property.getConfiguration().getUsability().getFileSharing().setPath(newVM.fileSharePath);
- }
-
- if (isModify) {
- EmulatorVMs.getInstance().storeXML(property);
- }
-
- return property;
- }
-
- public VMsProperty create(VMPropertyValue newVM) {
- this.newVM = newVM;
- this.property = EmulatorVMs.getInstance().getNewProperty
- (newVM.imageName, Architecture.x86);
-
- if (this.property == null) {
- setErrorMessage("Create failed virtual target property");
- return null;
- }
-
- // make directory
- File folder = new File(filePath.getVirtualTargetPath(newVM.imageName));
- folderPath = folder.getAbsolutePath() + SEFARATOR;
-
- File log = new File(filePath.getVirtualTargetLogPath(newVM.imageName));
-
- folder.mkdirs();
-
- if (!createDiskImage()) {
- deleteFolder(folder);
- return null;
- }
-
- if (!createFileShare()) {
- deleteFolder(folder);
- return null;
- }
-
- if (!createDisplay()) {
- deleteFolder(folder);
- return null;
- }
-
- if (!createRam()) {
- deleteFolder(folder);
- return null;
- }
-
- if (!createSDCard()) {
- deleteFolder(folder);
- return null;
- }
-
- log.mkdir();
-
- settingProperty();
- EmulatorVMs.getInstance().storeXML(this.property);
- return this.property;
- }
-
- private void deleteFolder(File folder) {
- if (folder.exists()) {
- for (File dir : folder.listFiles()) {
- if (dir.isFile()) {
- dir.delete();
- } else { // directory
- for (File sub : dir.listFiles()) {
- if (sub.isFile()) {
- sub.delete();
- }
- }
- dir.delete();
- }
- }
- folder.delete();
- }
- }
-
- private ObjectFactory factory;
- private EmulatorConfiguration ec;
- private void settingProperty() {
- factory = EmulatorVMs.getInstance().getObjectFactory();
- ec = property.getConfiguration();
- ec.setBaseInformation(factory.createBaseInformationType());
- ec.setUsability(factory.createUsabilityType());
- ec.setDevice(factory.createDeviceType());
-
- ec.getBaseInformation().setName(newVM.imageName);
- ec.getBaseInformation().setArchitecture(Architecture.x86.toString());
-
- ec.getBaseInformation().setDiskImage(factory.createBaseInformationTypeDiskImage());
- if (newVM.isDefaultImage) {
- ec.getBaseInformation().getDiskImage().setType("standard");
- // TODO : get version
- ec.getBaseInformation().getDiskImage().setVersion("1.0");
- } else {
- ec.getBaseInformation().getDiskImage().setType("custom");
- }
-
- //
- ec.getBaseInformation().getDiskImage().setBaseDiskImage(factory.createDiskImageFormatType());
- ec.getBaseInformation().getDiskImage().setCurrentDiskImage(factory.createDiskImageFormatType());
-
- // TODO :
- ec.getBaseInformation().getDiskImage().getBaseDiskImage().setFormat("qcow2");
- ec.getBaseInformation().getDiskImage().getBaseDiskImage().setValue(newVM.baseImagePath);
- ec.getBaseInformation().getDiskImage().getCurrentDiskImage().setFormat("qcow2");
- ec.getBaseInformation().getDiskImage().getCurrentDiskImage().setValue(
- String.format("%semulimg-%s.%s", folderPath, newVM.imageName, Architecture.x86.toString()));
-
- ec.getUsability().setLogging(factory.createUsabilityTypeLogging());
- ec.getUsability().getLogging().setLevel("NONE");
- ec.getUsability().setHwVirtualization(true);
-
- ec.getUsability().setFileSharing(factory.createUsabilityTypeFileSharing());
- if (!newVM.fileSharePath.isEmpty()) {
- ec.getUsability().getFileSharing().setPath(newVM.fileSharePath);
- }
-
- ec.getDevice().setDisplay(factory.createDisplayType());
- ec.getDevice().getDisplay().setResolution(factory.createDisplayTypeResolution());
- ec.getDevice().getDisplay().getResolution().setWidth(newVM.resolutionType.getWidth());
- ec.getDevice().getDisplay().getResolution().setHeight(newVM.resolutionType.getHeight());
-
- ec.getDevice().getDisplay().setDensity(factory.createDisplayTypeDensity());
- ec.getDevice().getDisplay().getDensity().setUnit("dpi");
- ec.getDevice().getDisplay().getDensity().setValue(newVM.dpi);
-
- ec.getDevice().getDisplay().setSkinPath(factory.createDisplayTypeSkinPath());
- ec.getDevice().getDisplay().getSkinPath().setPath(newVM.skinPath);
-
- ec.getDevice().setRAM(factory.createRamType());
- ec.getDevice().getRAM().setSize(factory.createRamTypeSize());
- ec.getDevice().getRAM().getSize().setUnit("MiB");
- ec.getDevice().getRAM().getSize().setValue(newVM.ramSize);
-
- ec.getDevice().setStorage(factory.createStorageType());
- ec.getDevice().getStorage().setSDCard(factory.createStorageTypeSDCard());
- if (newVM.isSDCardSupport) {
- ec.getDevice().getStorage().getSDCard().setDiskImage(newVM.SDCardPath);
- }
- }
-
- private boolean createDiskImage() {
- if (newVM.baseImagePath == null || newVM.baseImagePath.isEmpty()) {
- newVM.baseImagePath = filePath.getBaseimgPath();
- }
-
- if (!new File(newVM.baseImagePath).exists()) {
- setErrorMessage("Base image does not exist.");
- return false;
- }
-
- String targetPath = String.format("%semulimg-%s.%s", folderPath, newVM.imageName, Architecture.x86.toString());
- if (!createBaseImage(newVM.baseImagePath, targetPath)) {
- return false;
- }
-
- return true;
- }
-
- public boolean createBaseImage(String baseImagePath, String targetImagePath) {
- String exe_path = filePath.getBinPath() + SEFARATOR + "qemu-img";
-
- List<String> cmd = new ArrayList<String>();
- cmd.add(exe_path);
- cmd.add("create");
- cmd.add("-b");
- cmd.add(baseImagePath);
- cmd.add("-f");
- cmd.add("qcow2");
- cmd.add(targetImagePath);
- ProcessBuilder pb = new ProcessBuilder(cmd);
- try {
- pb.start();
- } catch (IOException e) {
- setErrorMessage("Emulator image create failed!\n" + e.getMessage());
- return false;
- }
- return true;
- }
-
- // usability
- private boolean createFileShare() {
- if (newVM.isFileShareSupport) {
- if (newVM.fileSharePath == null || newVM.fileSharePath.isEmpty()) {
- setErrorMessage("Select sharing file path");
- return false;
- }
- }
- return true;
- }
-
- // Device
- private boolean createDisplay() {
- int i = newVM.resolution.indexOf('x');
- newVM.resolutionType = new Resolution();
- newVM.resolutionType.setWidth(Integer.valueOf(newVM.resolution.substring(0,i)));
- newVM.resolutionType.setHeight(Integer.valueOf(newVM.resolution.substring(i+1,newVM.resolution.length())));
-
- if (newVM.skinPath == newVM.skinPathName) {
- newVM.skinPath = filePath.getSkinPath() + SEFARATOR + newVM.skinPathName;
- }
- return true;
- }
-
- private boolean createRam() {
- return true;
- }
-
- private boolean createSDCard() {
- if (newVM.isSDCardSupport) {
- if (! modifySDCard(newVM)) {
- return false;
- }
- }
- return true;
- }
-
- private boolean modifySDCard(VMPropertyValue newVM) {
- if (newVM.SDCardPath.endsWith("MB)")) { // New
- String sdCardName = newVM.SDCardPath.substring(0, newVM.SDCardPath.lastIndexOf(" "));
- String dataPath = filePath.getDataPath() + SEFARATOR + sdCardName;
-
- File src = new File(dataPath);
- if(!src.exists()) {
- setErrorMessage("SD Card image create failed!\nFile is not existing :" + dataPath);
- return false;
- }
-
- File dest = new File(filePath.getVirtualTargetPath(newVM.imageName) + SEFARATOR + sdCardName);
- try {
- dest.createNewFile();
- newVM.SDCardPath = dest.getAbsolutePath();
- } catch (IOException e) {
- setErrorMessage("Create new image path is failed!");
- return false;
- }
-
- FileReader in = null;
- FileWriter out = null;
- try {
- in = new FileReader(src);
- out = new FileWriter(dest);
-
- int c;
- while((c = in.read()) != -1) {
- out.write(c);
- }
- } catch (FileNotFoundException e) {
- setErrorMessage("SD Card image create failed!\n" + e.getMessage());
- return false;
- } catch (IOException e) {
- setErrorMessage("SD Card image create failed!\n" + e.getMessage());
- return false;
- }finally {
- try {
- if (in != null) in.close();
- if (out != null) out.close();
- } catch (IOException e) {
- }
- }
- } else {
- if (newVM.SDCardPath == null || newVM.SDCardPath.isEmpty()) {
- setErrorMessage("Select an existing sdcard image!");
- return false;
- }
-
- if (newVM.SDCardPath.equals("( None )")) {
- setErrorMessage("Select an existing sdcard image!");
- return false;
- }
- }
-
- return true;
- }
-
- public String getErrorMessage() {
- return errorMessage;
- }
-
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-}
import org.tizen.emulator.manager.vms.xml.DisplayType.Resolution;
-
-public class VMPropertyValue {
- public String arcType;
+// Wrapper for convenient property managing...
+public class VMPropertyValue implements Cloneable {
+ public String archType;
public String imageName;
public String fileSharePath;
public String fileSharePathName;
- public VMPropertyValue() {
- }
-
- public VMPropertyValue(VMPropertyValue oldTarget) {
- arcType = oldTarget.arcType;
- imageName = oldTarget.imageName;
-
- isDefaultImage = oldTarget.isDefaultImage;
- baseImagePath = oldTarget.baseImagePath;
- baseImagePathName = oldTarget.baseImagePathName;
-
- resolutionType = oldTarget.resolutionType;
- resolution = oldTarget.resolution;
- dpi = oldTarget.dpi;
- skinPath = oldTarget.skinPath;
- skinPathName = oldTarget.skinPathName;
-
- isSDCardSupport = oldTarget.isSDCardSupport;
- SDCardPath = oldTarget.SDCardPath;
- SDCardPathName = oldTarget.SDCardPathName;
-
- ramSize = oldTarget.ramSize;
-
- isFileShareSupport = oldTarget.isFileShareSupport;
- fileSharePath = oldTarget.fileSharePath;
- fileSharePathName = oldTarget.fileSharePathName;
- }
+ private VMPropertyValue() {} // for clone...
- public void defaultSetting(boolean isDefault) {
- arcType = "x86"; // TODO
- imageName = "";
-
- isDefaultImage = isDefault;
- baseImagePath = "";
- baseImagePathName = isDefault ? "( emulimg-1.0.x86 )" : " ( None )";
-
- // TODO
- // HD(720x1280)
- resolutionType = new Resolution();
- resolutionType.setWidth(720);
- resolutionType.setHeight(1280);
- resolution = "720x1280";
- dpi = 316; // this value be related to resolution
- // TODO : Skin Path
- skinPath = FileIO.getInstance().getSkinPath() + File.separator + "emul_" + resolution;
- skinPathName = "emul_" + resolution;
- //
-
- isSDCardSupport = false;
- SDCardPath = "";
- SDCardPathName = "( None )";
-
- ramSize = 512;
-
- isFileShareSupport = false;
- fileSharePath = "";
- fileSharePathName = "( None )";
- }
-
- public void settingValue(VMsProperty property) {
- arcType = property.getArch().toString();
+ VMPropertyValue(VMsProperty property) {
+ archType = property.getArch().toString();
imageName = property.getName();
isDefaultImage = property.getConfiguration().getBaseInformation().getDiskImage().getType().equals("standard") ? true : false;
}
ramSize = property.getConfiguration().getDevice().getRAM().getSize().getValue();
}
+
+ public void defaultSetting(boolean isDefault) {
+ }
+
+ @Override
+ public VMPropertyValue clone() {
+ VMPropertyValue dest = new VMPropertyValue();
+
+ dest.archType = this.archType;
+ dest.imageName = this.imageName;
+
+ dest.isDefaultImage = this.isDefaultImage;
+ dest.baseImagePath = this.baseImagePath;
+ dest.baseImagePathName = this.baseImagePathName;
+
+ dest.resolutionType = this.resolutionType;
+ dest.resolution = this.resolution;
+ dest.dpi = this.dpi;
+ dest.skinPath = this.skinPath;
+ dest.skinPathName = this.skinPathName;
+
+ dest.isSDCardSupport = this.isSDCardSupport;
+ dest.SDCardPath = this.SDCardPath;
+ dest.SDCardPathName = this.SDCardPathName;
+
+ dest.ramSize = this.ramSize;
+
+ dest.isFileShareSupport = this.isFileShareSupport;
+ dest.fileSharePath = this.fileSharePath;
+ dest.fileSharePathName = this.fileSharePathName;
+
+ return dest;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj)
+ return true;
+
+ if(!(obj instanceof VMPropertyValue))
+ return false;
+
+ VMPropertyValue dest = (VMPropertyValue)obj;
+
+ if(!this.resolution.equals(dest.resolution))
+ return false;
+ if(this.dpi != dest.dpi)
+ return false;
+ if(this.skinPath != dest.skinPath)
+ return false;
+ if(this.isSDCardSupport != dest.isSDCardSupport)
+ return false;
+ if(this.ramSize != dest.ramSize)
+ return false;
+ if(this.isFileShareSupport != dest.isFileShareSupport)
+ return false;
+
+ return true;
+ }
+
+ public static VMPropertyValue getDefault(boolean isDefault) {
+ VMPropertyValue value = new VMPropertyValue();
+
+ value.archType = "x86"; // TODO
+ value.imageName = "";
+
+ value.isDefaultImage = isDefault;
+ value.baseImagePath = "";
+ value.baseImagePathName = isDefault ? "( emulimg-1.0.x86 )" : " ( None )";
+
+ // TODO
+ // HD(720x1280)
+ value.resolutionType = new Resolution();
+ value.resolutionType.setWidth(720);
+ value.resolutionType.setHeight(1280);
+ value.resolution = "720x1280";
+ value.dpi = 316; // this value be related to resolution
+ // TODO : Skin Path
+ value.skinPath = FileIO.getInstance().getSkinPath() + File.separator + "emul_" + value.resolution;
+ value.skinPathName = "emul_" + value.resolution;
+ //
+
+ value.isSDCardSupport = false;
+ value.SDCardPath = "";
+ value.SDCardPathName = "( None )";
+
+ value.ramSize = 512;
+
+ value.isFileShareSupport = false;
+ value.fileSharePath = "";
+ value.fileSharePathName = "( None )";
+
+ return value;
+ }
}
--- /dev/null
+package org.tizen.emulator.manager.vms;
+
+public class VMsCreatorException extends VMsWorkerException {
+ private static final long serialVersionUID = -1670534140703381550L;
+
+ public VMsCreatorException(String message) {
+ super(message);
+ }
+}
public class VMsProperty {
File configFile;
-
EmulatorConfiguration configuration;
+
+ VMsWorker worker;
+ VMPropertyValue value;
public VMsProperty(File configFile, EmulatorConfiguration element) {
this.configFile = configFile;
this.configuration = element;
+
+ this.worker = new VMsWorker(this);
+ this.value = new VMPropertyValue(this);
}
+ public VMPropertyValue getPropertyValue() {
+ return value;
+ }
+
+ public VMsWorker getWorker() {
+ return worker;
+ }
+
public String getName() {
if(configuration.getBaseInformation() == null)
return null;
--- /dev/null
+package org.tizen.emulator.manager.vms;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.emulator.manager.tool.FileIO;
+
+
+
+public class VMsWorker {
+ VMsProperty property;
+
+ VMsWorker(VMsProperty property) {
+ this.property = property;
+ }
+
+ public void launchVM() throws VMsWorkerException {
+ if(isRunningNow())
+ throw new VMsWorkerException("Can not execute emulator.\nEmulator instance with the same name is running now.");
+
+ Launcher.launch(property);
+ }
+
+ public boolean createVM(VMPropertyValue newVM) throws VMsWorkerException {
+ Creator.create(newVM);
+
+ return true;
+ }
+
+ public void modifyVM(VMPropertyValue oldVM, VMPropertyValue newVM) throws VMsWorkerException {
+ Modifier.modify(property, oldVM, newVM);
+ }
+
+ public void deleteVM() {
+
+ }
+
+ public void resetVM() throws VMsWorkerException {
+ String basePath = property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue();
+ String targetPath = property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
+
+ if (basePath == null || basePath.isEmpty() || targetPath == null || targetPath.isEmpty()) {
+ throw new VMsWorkerException("Fail to reset Emulator\nEmulator Name : " + property.getName());
+ }
+
+ try {
+ Creator.createInitialVMImage(basePath, targetPath);
+ } catch (VMsCreatorException e) {
+ throw new VMsWorkerException("Fail to reset Emulator\nEmulator Name : " + property.getName()
+ +"\n" + e.getMessage());
+ }
+ }
+
+ public void cloneVM() {
+
+ }
+
+ // check if the emulator instance with the same name is running now.
+ public boolean isRunningNow()
+ {
+ int isLinux = System.getProperty("os.name").toLowerCase().indexOf("linux");
+ int isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows");
+
+ 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 java.exe\"");
+ }
+
+ 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().getVirtualTargetImagePath(property.getName()))) {
+ //System.out.println("exist in"+ line);
+ stdOut.close();
+ return true;
+ }
+ }
+ }
+ else if(isWindows > -1) {
+ while ((line = stdOut.readLine()) != null) {
+ if(line.contains(property.getName()+ ":261")) {
+ //System.out.println("exist in"+ line);
+ stdOut.close();
+ return true;
+ }
+ }
+ }
+ stdOut.close();
+ //System.out.println("not exist anywhere");
+ return false;
+ } catch (Exception err) {
+ err.printStackTrace();
+ return true;
+ }
+ }
+}
--- /dev/null
+package org.tizen.emulator.manager.vms;
+
+public class VMsWorkerException extends Exception {
+ private static final long serialVersionUID = -6819776106619652987L;
+
+ public VMsWorkerException(String message) {
+ super(message);
+ }
+}