Path lastCreated = Paths.get(lastCreatedPropertyPath);
// Use last-created_xxx.xml
if (Files.exists(lastCreated)) {
- return EmulatorManager.getVMKeeper().newProperty(lastCreated);
+ return EmulatorManager.getVMKeeper().loadProperty(lastCreated);
}
return null;
image.addEmulator(vm);
}
}
+
+ // FIXME
+ vm.initVMWorker();
}
public void removeEmulator(VMProperty vm) {
continue;
}
- prop.initVMWorker();
-
binaryVersion = prop.getBaseImageBinaryVersion();
path = prop.getBaseImagePath();
base = prop.getPropertyValue().baseImage;
} else { // property file
- VMProperty defaultProperty = EmulatorManager.getVMKeeper().newProperty(f.toPath());
+ VMProperty defaultProperty = EmulatorManager.getVMKeeper().loadProperty(f.toPath());
if (defaultProperty != null) {
platform.getPropertyList().add(defaultProperty);
}
} else { // property file
- VMProperty defaultProperty = EmulatorManager.getVMKeeper().newProperty(f.toPath());
+ VMProperty defaultProperty = EmulatorManager.getVMKeeper().loadProperty(f.toPath());
if (defaultProperty != null) {
platform.getPropertyList().add(defaultProperty);
}
public void reloadProperty() {
- if (getCurrentProperty().getWorker().isModified()) {
- MainDialog.refreshVMProperty(currentProperty);
- String msg = Messages.getString("VMsMainView.ReloadVMProperty.0"); //$NON-NLS-1$
- EMLogger.getLogger().info(msg);
- MainDialog.getStatusBar().info(msg);
- Display.getCurrent().asyncExec(new Runnable() {
- @Override
- public void run() {
- try {
- Thread.sleep(2000);
- MainDialog.getStatusBar().reset();
- } catch (InterruptedException e) {
- EMLogger.getLogger().warning(e.getMessage());
- }
- }
- });
- }
+ // no nothing
}
}
throw e;
}
- property = EmulatorManager.getVMKeeper().newProperty(newVM);
+ property = EmulatorManager.getVMKeeper().createProperty(newVM);
// Save last created property file.
Path lastCreatedpropertyFile = null;
for (Path path : stream) {
if (Files.isRegularFile(path)) {
VMProperty property
- = newProperty(path);
+ = loadProperty(path);
if (property != null) {
listChanged(property, ChangeType.ADDED);
}
for (Path path : stream) {
if (Files.isRegularFile(path)) {
- VMProperty property = newProperty(path);
+ VMProperty property = loadProperty(path);
if (property != null) {
listChanged(property, ChangeType.ADDED);
properties.add(property);
import org.tizen.emulator.manager.vms.exception.VMWorkerException;
public interface IVMWorker {
- public void sendRemoteLog(String msg);
public void initLauncher();
public void launchVM() throws VMLauncherException, VMWorkerException;
public synchronized void addVM(Path propertyFilePath) {
assert Files.isRegularFile(propertyFilePath);
- VMProperty property = newProperty(propertyFilePath);
+ VMProperty property = loadProperty(propertyFilePath);
assert property.getHealth() != Health.CORRUPTED && !properties.contains(property);
package org.tizen.emulator.manager.vms;
+import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.Messages;
import org.tizen.emulator.manager.vms.exception.VMWorkerException;
}
modifyFileShare(newVM);
- property.setPropertyValue(newVM);
+ EmulatorManager.getVMKeeper().modifyProperty(property, newVM);
}
private static void modifyFileShare(VMPropertyValue newVM) throws VMWorkerException {
*/
public abstract Queue<VMProperty> getProperties();
- public VMProperty newProperty(VMPropertyValue value) {
+ public VMProperty createProperty(VMPropertyValue value) {
return VMProperty.createNew(value);
}
- public VMProperty newProperty(Path propertyFile) {
+ public VMProperty modifyProperty(VMProperty property, VMPropertyValue value) {
+ return property.modify(value);
+ }
+
+ public VMProperty loadProperty(Path propertyFile) {
return VMProperty.loadFrom(propertyFile);
}
private VMPropertyValue value = null;
private Health health = Health.NOT_CHECKED;
+ private State preState = State.NOT_SET;
private State state = State.NOT_SET;
private long lastLaunched;
}
static VMProperty loadFrom(Path propertyFile) {
- VMProperty property = new VMProperty(propertyFile);
- property.refresh();
-
- return property;
+ return new VMProperty(propertyFile);
}
static VMProperty createNew(VMPropertyValue value) {
Path propertyFile = Paths.get(propertyFilename);
assert Files.notExists(propertyFile);
- VMProperty property = new VMProperty(propertyFile);
- property.setPropertyValue(value);
+ return new VMProperty(propertyFile, value);
- return property;
}
private VMProperty(Path propertyFile) {
this.propertyFile = propertyFile;
+ refresh();
+ }
+
+ private VMProperty(Path propertyFile, VMPropertyValue value) {
+ this.propertyFile = propertyFile;
+ setPropertyValue(value);
+ }
+
+ public VMProperty modify(VMPropertyValue value) {
+ setPropertyValue(value);
+
+ return this;
}
private void stateChanged() {
}
};
+ // FIXME: called from Profile class
public void initVMWorker() {
ExtensionItem item = null;
if (getPropertyValue().baseImage == null) {
return value;
}
- public void setPropertyValue(VMPropertyValue value) {
+ private void setPropertyValue(VMPropertyValue value) {
this.value = value;
configuration = new VMPropertyConfiguration(value);
}
public VMWorkerCommon getWorker() {
- if (worker == null) {
- initVMWorker();
- }
return worker;
}
return true;
}
+ public State getPreState() {
+ return preState;
+ }
+
public State getState() {
return state;
}
assert this.state != State.RUNNING;
break;
case READY:
- if (this.state == State.RUNNING) {
- if (worker != null) {
- worker.sendRemoteLog("stop"); //$NON-NLS-1$
- }
- }
break;
case LAUNCHING:
assert this.state == State.READY;
break;
case RUNNING:
assert this.state == State.LAUNCHING || this.state == State.READY;
- if (worker != null) {
- worker.sendRemoteLog("start"); //$NON-NLS-1$
- }
break;
default:
break;
}
+ this.preState = this.state;
this.state = state;
stateChanged();
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.vms.VMProperty.State;
import org.tizen.emulator.manager.vms.exception.VMLauncherException;
import org.tizen.emulator.manager.vms.exception.VMWorkerException;
import org.tizen.emulator.manager.vms.helper.QemuImgProc;
public class VMWorkerCommon implements IVMWorker {
private VMProperty property;
private ILauncher launcher;
- private boolean isModified;
- @Override
- public void sendRemoteLog(String msg) {
+ protected VMWorkerCommon() {
+ // TODO: this logic should move to plugins
+ VMProperty.addStateChangeListener(new StateChangeListener<VMProperty>() {
+ @Override
+ public void stateChanged(VMProperty property) {
+ if (property.getState() == State.READY && property.getPreState() == State.RUNNING) {
+ sendRemoteLog("stop"); //$NON-NLS-1$
+ }
+
+ if (property.getState() == State.RUNNING) {
+ sendRemoteLog("start"); //$NON-NLS-1$
+ }
+ }
+ });
+ }
+
+ @Deprecated // All state changed event should be using StateChangeListener
+ protected void sendRemoteLog(String msg) {
}
@Override
return launcher;
}
- public void setVMProperty(VMProperty property) {
+ void setVMProperty(VMProperty property) {
this.property = property;
}
- public VMProperty getProperty() {
- return property;
- }
-
@Override
public void launchVM() throws VMLauncherException, VMWorkerException {
launchVM(false, null);
true);
}
- if (isModified) {
- property = EmulatorManager.getVMKeeper().newProperty(
- property.getPropertyFile());
- if (property == null) {
- throw new VMWorkerException(
- Messages.getString("VMWorkerCommon.LaunchError.0"), true); //$NON-NLS-1$
- }
- }
-
// Do argument validation.
List<IOption> optList = property.getPropertyValue().baseImage.getOptionList();
if (optList == null) {
true);
}
- if (isModified) {
- throw new VMWorkerException(
- Messages.getString("VMWorkerCommon.ModifyError.0"), //$NON-NLS-1$
- true);
- }
-
isRunningNow();
Modifier.modify(property, newVM);
return result;
}
-
- /**
- * If property had been modified by other emulator manager(cli),
- * this method will be return true.
- * @return return true if property had been modified
- */
- public boolean isModified() {
- return isModified;
- }
}
/*