Removed MachineProcess
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 29 Sep 2019 22:02:02 +0000 (00:02 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 29 Sep 2019 22:02:02 +0000 (00:02 +0200)
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugTarget.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineProcess.java [deleted file]

index 357fe82..328c589 100644 (file)
@@ -1,7 +1,5 @@
 package net.mograsim.plugin.launch;
 
-import java.util.Arrays;
-
 import org.eclipse.core.resources.IMarkerDelta;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.PlatformObject;
@@ -21,34 +19,27 @@ import org.eclipse.debug.core.model.IProcess;
 import org.eclipse.debug.core.model.IStepFilters;
 import org.eclipse.debug.core.model.IThread;
 
+import net.mograsim.logic.model.LogicExecuter;
 import net.mograsim.machine.Machine;
+import net.mograsim.machine.MachineDefinition;
 import net.mograsim.plugin.MograsimActivator;
 
 public class MachineDebugTarget extends PlatformObject implements IDebugTarget, IMemoryBlockRetrievalExtension
 {
-       private final MachineProcess process;
-
-       public MachineDebugTarget(MachineProcess process)
-       {
-               this.process = process;
-
-               DebugPlugin.getDefault().addDebugEventListener(es -> Arrays.stream(es).filter(e -> e.getSource() == process).forEach(e ->
-               {
-                       switch (e.getKind())
-                       {
-                       case DebugEvent.RESUME:
-                               fireResumeEvent(e.getDetail());
-                               break;
-                       case DebugEvent.SUSPEND:
-                               fireSuspendEvent(e.getDetail());
-                               break;
-                       case DebugEvent.TERMINATE:
-                               fireTerminateEvent();
-                               break;
-                       default:
-                               // ignore
-                       }
-               }));
+       private final ILaunch launch;
+       private final Machine machine;
+       private final LogicExecuter exec;
+
+       private boolean running;
+
+       public MachineDebugTarget(ILaunch launch, MachineDefinition machineDefinition)
+       {
+               this.launch = launch;
+               this.machine = machineDefinition.createNew();
+               this.exec = new LogicExecuter(machine.getTimeline());
+
+               exec.startLiveExecution();
+               running = true;
 
                getLaunch().addDebugTarget(this);
                fireCreationEvent();
@@ -56,13 +47,13 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget,
 
        public Machine getMachine()
        {
-               return process.getMachine();
+               return machine;
        }
 
        @Override
        public String getName() throws DebugException
        {
-               return process.getName();
+               return "Mograsim machine \"" + machine.getDefinition().getId() + '"';
        }
 
        @Override
@@ -80,60 +71,77 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget,
        @Override
        public ILaunch getLaunch()
        {
-               return process.getLaunch();
+               return launch;
        }
 
        public void setExecutionSpeed(double speed)
        {
-               process.setExecutionSpeed(speed);
+               exec.setSpeedFactor(speed);
        }
 
        @Override
        public boolean isSuspended()
        {
-               return process.isSuspended();
+               return exec.isPaused();
        }
 
        @Override
        public boolean canSuspend()
        {
-               return process.canSuspend();
+               return !isTerminated() && !isSuspended();
        }
 
        @Override
        public void suspend() throws DebugException
        {
-               process.suspend();
+               if (isTerminated())
+                       throwDebugException("Can't suspend a terminated MachineProcess");
+               if (isSuspended())
+                       throwDebugException("Can't suspend a suspended MachineProcess");
+
+               exec.pauseLiveExecution();
+               fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
        }
 
        @Override
        public boolean canResume()
        {
-               return process.canResume();
+               return !isTerminated() && isSuspended();
        }
 
        @Override
        public void resume() throws DebugException
        {
-               process.resume();
+               if (isTerminated())
+                       throwDebugException("Can't resume a terminated MachineProcess");
+               if (!isSuspended())
+                       throwDebugException("Can't resume a non-suspended MachineProcess");
+
+               exec.unpauseLiveExecution();
+               fireResumeEvent(DebugEvent.CLIENT_REQUEST);
        }
 
        @Override
        public boolean isTerminated()
        {
-               return process.isTerminated();
+               return !running;
        }
 
        @Override
        public boolean canTerminate()
        {
-               return process.canTerminate();
+               return !isTerminated();
        }
 
        @Override
        public void terminate() throws DebugException
        {
-               process.terminate();
+               if (isTerminated())
+                       return;
+
+               exec.stopLiveExecution();
+               running = false;
+               fireTerminateEvent();
        }
 
        @Override
@@ -199,9 +207,9 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget,
        }
 
        @Override
-       public MachineProcess getProcess()
+       public IProcess getProcess()
        {
-               return process;
+               return null;
        }
 
        @Override
@@ -234,9 +242,6 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget,
                if (adapter == ILaunch.class)
                        return (T) getLaunch();
 
-               if (adapter == IProcess.class)
-                       return (T) getProcess();
-
                // CONTEXTLAUNCHING
                if (adapter == ILaunchConfiguration.class)
                        return (T) getLaunch().getLaunchConfiguration();
@@ -289,4 +294,10 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget,
        {
                DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { event });
        }
+
+       private static void throwDebugException(String message) throws DebugException
+       {
+               throw new DebugException(
+                               new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, DebugException.TARGET_REQUEST_FAILED, message, null));
+       }
 }
\ No newline at end of file
index e9b6531..2c2c19c 100644 (file)
@@ -122,7 +122,8 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate
 
                // TODO parse RAM
 
-               MachineDebugTarget debugTarget = new MachineDebugTarget(new MachineProcess(launch, machineDefinition));
+               MachineDebugTarget debugTarget = new MachineDebugTarget(launch, machineDefinition);
+               debugTarget.suspend();
                debugTarget.setExecutionSpeed(1);
                Machine machine = debugTarget.getMachine();
                machine.getMicroInstructionMemory().bind(mpm);
diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineProcess.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineProcess.java
deleted file mode 100644 (file)
index f386690..0000000
+++ /dev/null
@@ -1,266 +0,0 @@
-package net.mograsim.plugin.launch;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.PlatformObject;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.model.IDebugTarget;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.core.model.IStreamsProxy;
-import org.eclipse.debug.core.model.ISuspendResume;
-
-import net.mograsim.logic.model.LogicExecuter;
-import net.mograsim.machine.Machine;
-import net.mograsim.machine.MachineDefinition;
-import net.mograsim.plugin.MograsimActivator;
-
-public class MachineProcess extends PlatformObject implements IProcess, ISuspendResume
-{
-       private final ILaunch launch;
-       private final Machine machine;
-       private final LogicExecuter exec;
-
-       private boolean running;
-
-       public MachineProcess(ILaunch launch, MachineDefinition machineDefinition)
-       {
-               this.launch = launch;
-               this.machine = machineDefinition.createNew();
-               this.exec = new LogicExecuter(machine.getTimeline());
-
-               exec.startLiveExecution();
-               running = true;
-
-               launch.addProcess(this);
-               fireCreationEvent();
-       }
-
-       public Machine getMachine()
-       {
-               return machine;
-       }
-
-       @Override
-       public ILaunch getLaunch()
-       {
-               return launch;
-       }
-
-       public String getName()
-       {
-               return "Mograsim machine \"" + machine.getDefinition().getId() + '"';
-       }
-
-       @Override
-       public String getLabel()
-       {
-               return getName() + " (" + getStatusString() + ')';
-       }
-
-       public String getStatusString()
-       {
-               return isTerminated() ? "terminated" : isSuspended() ? "paused" : "running";
-       }
-
-       public void setExecutionSpeed(double speed)
-       {
-               exec.setSpeedFactor(speed);
-       }
-
-       @Override
-       public boolean isSuspended()
-       {
-               return exec.isPaused();
-       }
-
-       @Override
-       public boolean canSuspend()
-       {
-               return !isTerminated() && !isSuspended();
-       }
-
-       @Override
-       public void suspend() throws DebugException
-       {
-               if (isTerminated())
-                       throwDebugException("Can't suspend a terminated MachineProcess");
-               if (isSuspended())
-                       throwDebugException("Can't suspend a suspended MachineProcess");
-
-               exec.pauseLiveExecution();
-               fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
-       }
-
-       @Override
-       public boolean canResume()
-       {
-               return !isTerminated() && isSuspended();
-       }
-
-       @Override
-       public void resume() throws DebugException
-       {
-               if (isTerminated())
-                       throwDebugException("Can't resume a terminated MachineProcess");
-               if (!isSuspended())
-                       throwDebugException("Can't resume a non-suspended MachineProcess");
-
-               exec.unpauseLiveExecution();
-               fireResumeEvent(DebugEvent.CLIENT_REQUEST);
-       }
-
-       @Override
-       public boolean isTerminated()
-       {
-               return !running;
-       }
-
-       @Override
-       public boolean canTerminate()
-       {
-               return !isTerminated();
-       }
-
-       @Override
-       public void terminate() throws DebugException
-       {
-               if (isTerminated())
-                       return;
-
-               exec.stopLiveExecution();
-               running = false;
-               fireTerminateEvent();
-       }
-
-       @Override
-       public int getExitValue() throws DebugException
-       {
-               if (!isTerminated())
-                       throwDebugException("Can't get the exit value of a running process");
-
-               return 0;
-       }
-
-       @Override
-       public IStreamsProxy getStreamsProxy()
-       {
-               return null;
-       }
-
-       private Map<String, String> attributes;
-
-       @Override
-       public void setAttribute(String key, String value)
-       {
-               if (attributes == null)
-                       attributes = new HashMap<>(5);
-               Object origVal = attributes.get(key);
-               if (origVal != null && origVal.equals(value))
-                       return;
-               attributes.put(key, value);
-               fireChangeEvent();
-       }
-
-       @Override
-       public String getAttribute(String key)
-       {
-               if (attributes == null)
-                       return null;
-               return attributes.get(key);
-       }
-
-       @SuppressWarnings("unchecked")
-       @Override
-       public <T> T getAdapter(Class<T> adapter)
-       {
-               if (adapter.equals(IProcess.class))
-                       return (T) this;
-
-               if (adapter.equals(IDebugTarget.class))
-               {
-                       ILaunch launch = getLaunch();
-                       IDebugTarget[] targets = launch.getDebugTargets();
-                       for (int i = 0; i < targets.length; i++)
-                               if (this.equals(targets[i].getProcess()))
-                                       return (T) targets[i];
-                       return null;
-               }
-
-               if (adapter.equals(ILaunch.class))
-                       return (T) getLaunch();
-
-               if (adapter.equals(ILaunchConfiguration.class))
-                       return (T) getLaunch().getLaunchConfiguration();
-
-               return super.getAdapter(adapter);
-       }
-
-       /**
-        * Fires a creation event.
-        */
-       private void fireCreationEvent()
-       {
-               fireEvent(new DebugEvent(this, DebugEvent.CREATE));
-       }
-
-       /**
-        * Fires a change event.
-        */
-       private void fireChangeEvent()
-       {
-               fireEvent(new DebugEvent(this, DebugEvent.CHANGE));
-       }
-
-       /**
-        * Fires a resume for this debug element with the specified detail code.
-        *
-        * @param detail detail code for the resume event, such as <code>DebugEvent.STEP_OVER</code>
-        */
-       private void fireResumeEvent(int detail)
-       {
-               fireEvent(new DebugEvent(this, DebugEvent.RESUME, detail));
-       }
-
-       /**
-        * Fires a suspend event for this debug element with the specified detail code.
-        *
-        * @param detail detail code for the suspend event, such as <code>DebugEvent.BREAKPOINT</code>
-        */
-       private void fireSuspendEvent(int detail)
-       {
-               fireEvent(new DebugEvent(this, DebugEvent.SUSPEND, detail));
-       }
-
-       /**
-        * Fires a terminate event.
-        */
-       private void fireTerminateEvent()
-       {
-               fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
-       }
-
-       /**
-        * Fires the given debug event.
-        *
-        * @param event debug event to fire
-        */
-       private static void fireEvent(DebugEvent event)
-       {
-               DebugPlugin manager = DebugPlugin.getDefault();
-               if (manager != null)
-                       manager.fireDebugEventSet(new DebugEvent[] { event });
-       }
-
-       private static void throwDebugException(String message) throws DebugException
-       {
-               throw new DebugException(
-                               new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, DebugException.TARGET_REQUEST_FAILED, message, null));
-       }
-}
\ No newline at end of file