import java.io.File;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.resources.FilePathResources;
return false;
}
- property.getWorker().createNewBaseImage(property, path);
+ // block other function while to create base image
+ property.setRunning(true);
+ WorkerThread worker = new WorkerThread(property, path);
+ worker.start();
+
return true;
}
+ private class WorkerThread extends Thread {
+ VMProperty property;
+ String path;
+
+ public WorkerThread(VMProperty property, String path) {
+ this.property = property;
+ this.path = path;
+ }
+
+ @Override
+ public void run() {
+ try {
+ property.getWorker().createNewBaseImage(property, path);
+ } catch (VMWorkerException e) {
+ final String error = e.getMessage();
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ new MessageDialog(null).openWarningDialog(error);
+
+ }
+ });
+ } finally {
+ property.setRunning(false);
+ }
+ }
+ }
+
public void cloneVirtualMachine(VMProperty property) {
MessageDialog msg = new MessageDialog();
public class VMWorkerCommon implements IVMWorker {
private VMProperty property;
- private WorkerThread worker = null;
- private String baseImagePath = null;
- private String baseImagePartPath = null;
- private Object lock = new Object();
private ILauncher launcher;
private boolean isModified;
return property;
}
- public String getBaseImagePath() {
- return baseImagePath;
- }
-
- public String getBaseImagePartPath() {
- return baseImagePartPath;
- }
-
@Override
public void launchVM() throws VMLauncherException, VMWorkerException {
launchVM(false, null);
checkPropertyModification();
isRunningNow();
- baseImagePath = dest;
- baseImagePartPath = dest + ".part"; //$NON-NLS-1$
+ String baseImagePath = dest;
+ String baseImagePartPath = dest + ".part"; //$NON-NLS-1$
File childImage = new File(property.getConfiguration()
.getBaseInformation().getDiskImage().getCurrentDiskImage()
cmd.add(baseImagePartPath);
final QemuImgProc proc = new QemuImgProc(cmd);
- /*
- * long childSize = childImage.length(); long baseSize =
- * baseImage.length(); final long maxSize = childSize + baseSize;
- * final File destFile = new File(dest); final CreateBaseImageDialog
- * dialog = new
- * CreateBaseImageDialog(EmulatorManager.getInstance().getMainDialog
- * ().getShell()); dialog.Open(destFile, maxSize);
- */
-
- worker = new WorkerThread(proc, lock);
- worker.setDaemon(false);
- worker.start();
- synchronized (lock) {
- try {
- lock.wait(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- if (worker.isError()) {
- throw new VMWorkerException(
- Messages.getString("VMWorkerCommon.Qemu-imgError.0") //$NON-NLS-1$
- + StringResources.NEW_LINE
- + Messages.getString("VMWorkerCommon.Qemu-imgError.1") //$NON-NLS-1$
- + FilePathResources.getTizenVmsPath()
- + File.separator + "emulator-manager)"); //$NON-NLS-1$
- }
- }
- } catch (VMWorkerException e) {
- throw e;
- } finally {
- // lock.release
- WorkerLock.release();
- }
-
- // TODO: This code will be moved console source
- if (EmulatorManager.isConsoleMode()) {
- System.out.println(Messages.getString("VMWorkerCommon.ExportAsInfo.0") //$NON-NLS-1$
- + StringResources.NEW_LINE
- + Messages.getString("VMWorkerCommon.ExportAsInfo.1")); //$NON-NLS-1$
- synchronized (lock) {
- while (worker.isAlive()) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- if (worker.isError()) {
- throw new VMWorkerException(
- Messages.getString("VMWorkerCommon.Qemu-imgError.0") //$NON-NLS-1$
- + StringResources.NEW_LINE
- + Messages.getString("VMWorkerCommon.Qemu-imgError.1") //$NON-NLS-1$
- + FilePathResources.getTizenVmsPath()
- + File.separator + "emulator-manager)"); //$NON-NLS-1$
- }
- }
- }
-
- /*
- * if (! proc.Running()) { //dialog.Close(); throw new
- * VMsWorkerException(
- * "Failed to create new base image becauese of failed qemu-img processing!"
- * + StringResources.NEW_LINE +
- * "You can get more information in log file (" +
- * FileIO.getInstance().getTizenVmsArchPath() + File.separator +
- * "emulator-manager)"); } //dialog.Close();
- */
- }
-
- class WorkerThread extends Thread {
- QemuImgProc proc;
- boolean isError;
- Object lock;
-
- public WorkerThread(QemuImgProc proc, Object lock) {
- this.proc = proc;
- this.lock = lock;
- isError = false;
- }
-
- public void run() {
- //
+ // start make custom base image
File file = new File(FilePathResources.getTizenVmsPath()
+ File.separator + property.getName() + ".lock"); //$NON-NLS-1$
try {
} catch (IOException e) {
EMLogger.getLogger().warning(e.getMessage());
}
- //
if (!proc.Running()) {
- isError = true;
+ EMLogger.getLogger().info("Failed to create base image."
+ + StringResources.NEW_LINE
+ + "Base image path: " + baseImagePath);
+ deleteFile(new File(baseImagePartPath));
+ throw new VMWorkerException(
+ Messages.getString("VMWorkerCommon.Qemu-imgError.0") //$NON-NLS-1$
+ + StringResources.NEW_LINE
+ + Messages.getString("VMWorkerCommon.Qemu-imgError.1") //$NON-NLS-1$
+ + FilePathResources.getTizenVmsPath()
+ + File.separator + "emulator-manager)"); //$NON-NLS-1$
}
- synchronized (lock) {
- if (file != null) {
- file.delete();
- }
- File baseFile = new File(baseImagePath);
- File partFile = new File(baseImagePartPath);
- partFile.renameTo(baseFile);
- lock.notifyAll();
+
+ // success to create custom base image
+ File baseFile = new File(baseImagePath);
+ File partFile = new File(baseImagePartPath);
+ if (baseFile.exists()) {
+ EMLogger.getLogger().fine("Base image file is already exist. So, this file will be deleted.");
+ baseFile.delete();
}
- }
- public boolean isError() {
- return isError;
+ if (!partFile.renameTo(baseFile)) {
+ deleteFile(baseFile);
+ deleteFile(partFile);
+ String error ="Failed to rename base image file. Please, try again to create base image.";
+ EMLogger.getLogger().warning(error);
+ throw new VMWorkerException(error);
+ }
+
+ if (file != null) {
+ EMLogger.getLogger().fine("Delete property lock file.");
+ file.delete();
+ }
+
+ EMLogger.getLogger().info("Success to create base image."
+ + StringResources.NEW_LINE
+ + "Base image path: " + baseImagePath);
+ } finally {
+ // lock.release
+ WorkerLock.release();
}
}
// check if the emulator instance with the same name is running now.
public boolean isRunningNow() throws VMWorkerException {
- // to check running 'create base image' routine
- if (worker != null) {
- if (worker.isAlive()) {
- throw new VMWorkerException("[" + property.getName() + "]" //$NON-NLS-1$ //$NON-NLS-2$
- + Messages.getString("VMWorkerCommon.WorkingError.0")); //$NON-NLS-1$
- }
- }
-
File file = new File(FilePathResources.getTizenVmsPath()
+ File.separator + property.getName() + ".lock"); //$NON-NLS-1$
if (file.exists()) {