1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

[158610] Converted the IRunControl.can*() methods to be asynchronous.

This commit is contained in:
Pawel Piech 2008-03-28 17:42:49 +00:00
parent f740036430
commit e42dcea7a8
9 changed files with 139 additions and 101 deletions

View file

@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.actions;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
import org.eclipse.dd.dsf.concurrent.Immutable;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.debug.internal.ui.DsfDebugUIPlugin;
@ -44,7 +46,15 @@ public class DsfResumeCommand implements IResumeHandler {
fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) {
@Override public void doExecute() {
request.setEnabled(getRunControl().canResume(getContext()));
getRunControl().canResume(
getContext(),
new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) {
@Override
protected void handleCompleted() {
request.setEnabled(isSuccess() && getData());
request.done();
}
});
}
});
}

View file

@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.actions;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
import org.eclipse.dd.dsf.concurrent.Immutable;
import org.eclipse.dd.dsf.debug.internal.ui.DsfDebugUIPlugin;
import org.eclipse.dd.dsf.debug.service.IRunControl.StepType;
@ -44,7 +46,15 @@ public class DsfStepIntoCommand implements IStepIntoHandler {
fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) {
@Override public void doExecute() {
request.setEnabled(getStepQueueMgr().canEnqueueStep(getContext(), StepType.STEP_INTO));
getStepQueueMgr().canEnqueueStep(
getContext(), StepType.STEP_INTO,
new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) {
@Override
protected void handleCompleted() {
request.setEnabled(isSuccess() && getData());
request.done();
}
});
}
});
}

View file

@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.actions;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
import org.eclipse.dd.dsf.concurrent.Immutable;
import org.eclipse.dd.dsf.debug.internal.ui.DsfDebugUIPlugin;
import org.eclipse.dd.dsf.debug.service.IRunControl.StepType;
@ -44,7 +46,15 @@ public class DsfStepOverCommand implements IStepOverHandler {
fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) {
@Override public void doExecute() {
request.setEnabled(getStepQueueMgr().canEnqueueStep(getContext(), StepType.STEP_OVER));
getStepQueueMgr().canEnqueueStep(
getContext(), StepType.STEP_OVER,
new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) {
@Override
protected void handleCompleted() {
request.setEnabled(isSuccess() && getData());
request.done();
}
});
}
});
}

View file

@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.actions;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
import org.eclipse.dd.dsf.concurrent.Immutable;
import org.eclipse.dd.dsf.debug.internal.ui.DsfDebugUIPlugin;
import org.eclipse.dd.dsf.debug.service.IRunControl.StepType;
@ -44,7 +46,15 @@ public class DsfStepReturnCommand implements IStepReturnHandler {
fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) {
@Override public void doExecute() {
request.setEnabled(getStepQueueMgr().canEnqueueStep(getContext(), StepType.STEP_RETURN));
getStepQueueMgr().canEnqueueStep(
getContext(), StepType.STEP_RETURN,
new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) {
@Override
protected void handleCompleted() {
request.setEnabled(isSuccess() && getData());
request.done();
}
});
}
});
}

View file

@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.actions;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
import org.eclipse.dd.dsf.concurrent.Immutable;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.debug.internal.ui.DsfDebugUIPlugin;
@ -43,7 +45,15 @@ public class DsfSuspendCommand implements ISuspendHandler {
fExecutor.submit(new DsfCommandRunnable(fTracker, request.getElements()[0], request) {
@Override public void doExecute() {
request.setEnabled(getRunControl().canSuspend(getContext()));
getRunControl().canSuspend(
getContext(),
new DataRequestMonitor<Boolean>(ImmediateExecutor.getInstance(), null) {
@Override
protected void handleCompleted() {
request.setEnabled(isSuccess() && getData());
request.done();
}
});
}
});
}

View file

@ -115,15 +115,13 @@ public interface IRunControl extends IDMService
* Run control commands. They all require the IExecutionContext object on
* which they perform the operations.
*/
boolean canResume(IExecutionDMContext context);
boolean canSuspend(IExecutionDMContext context);
void canResume(IExecutionDMContext context, DataRequestMonitor<Boolean> rm);
void canSuspend(IExecutionDMContext context, DataRequestMonitor<Boolean> rm);
boolean isSuspended(IExecutionDMContext context);
void resume(IExecutionDMContext context, RequestMonitor requestMonitor);
void suspend(IExecutionDMContext context, RequestMonitor requestMonitor);
public enum StepType { STEP_OVER, STEP_INTO, STEP_RETURN };
public enum StepType { STEP_OVER, STEP_INTO, STEP_RETURN, INSTRUCTION_STEP_OVER, INSTRUCTION_STEP_INTO, INSTRUCTION_STEP_RETUTRN };
boolean isStepping(IExecutionDMContext context);
boolean canStep(IExecutionDMContext context, StepType stepType);
void canStep(IExecutionDMContext context, StepType stepType, DataRequestMonitor<Boolean> rm);
void step(IExecutionDMContext context, StepType stepType, RequestMonitor requestMonitor);
boolean canInstructionStep(IExecutionDMContext context, StepType stepType);
void instructionStep(IExecutionDMContext context, StepType stepType, RequestMonitor requestMonitor);
}

View file

@ -18,6 +18,7 @@ import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfRunnable;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -64,10 +65,8 @@ public class StepQueueManager extends AbstractDsfService
private static class StepRequest {
StepType fStepType;
boolean fIsInstructionStep;
StepRequest(StepType type, boolean instruction) {
StepRequest(StepType type) {
fStepType = type;
fIsInstructionStep = instruction;
}
}
@ -116,17 +115,17 @@ public class StepQueueManager extends AbstractDsfService
/**
* Checks whether a step command can be queued up for given context.
*/
public boolean canEnqueueStep(IExecutionDMContext execCtx, StepType stepType) {
return (fRunControl.isSuspended(execCtx) && fRunControl.canStep(execCtx, stepType)) ||
(fRunControl.isStepping(execCtx) && !isSteppingTimedOut(execCtx));
public void canEnqueueStep(IExecutionDMContext execCtx, StepType stepType, DataRequestMonitor<Boolean> rm) {
if (doCanEnqueueStep(execCtx, stepType)) {
rm.setData(true);
rm.done();
} else {
fRunControl.canStep(execCtx, stepType, rm);
}
}
/**
* Checks whether an instruction step command can be queued up for given context.
*/
public boolean canEnqueueInstructionStep(IExecutionDMContext execCtx, StepType stepType) {
return (fRunControl.isSuspended(execCtx) && fRunControl.canInstructionStep(execCtx, stepType)) ||
(fRunControl.isStepping(execCtx) && !isSteppingTimedOut(execCtx));
private boolean doCanEnqueueStep(IExecutionDMContext execCtx, StepType stepType) {
return fRunControl.isStepping(execCtx) && !isSteppingTimedOut(execCtx);
}
/**
@ -144,40 +143,25 @@ public class StepQueueManager extends AbstractDsfService
* @param execCtx Execution context that should perform the step.
* @param stepType Type of step to execute.
*/
public void enqueueStep(IExecutionDMContext execCtx, StepType stepType) {
if (fRunControl.canStep(execCtx, stepType)) {
fRunControl.step(execCtx, stepType, new RequestMonitor(getExecutor(), null));
} else if (canEnqueueStep(execCtx, stepType)) {
List<StepRequest> stepQueue = fStepQueues.get(execCtx);
if (stepQueue == null) {
stepQueue = new LinkedList<StepRequest>();
fStepQueues.put(execCtx, stepQueue);
}
if (stepQueue.size() < fQueueDepth) {
stepQueue.add(new StepRequest(stepType, false));
}
}
}
/**
* Adds an instruction step command to the execution queue for given
* context.
* @param execCtx Execution context that should perform the step.
* @param stepType Type of step to execute.
*/
public void enqueueInstructionStep(IExecutionDMContext execCtx, StepType stepType) {
if (fRunControl.canInstructionStep(execCtx, stepType)) {
fRunControl.instructionStep(execCtx, stepType, new RequestMonitor(getExecutor(), null));
} else if (canEnqueueInstructionStep(execCtx, stepType)) {
List<StepRequest> stepQueue = fStepQueues.get(execCtx);
if (stepQueue == null) {
stepQueue = new LinkedList<StepRequest>();
fStepQueues.put(execCtx, stepQueue);
}
if (stepQueue.size() < fQueueDepth) {
stepQueue.add(new StepRequest(stepType, true));
}
}
public void enqueueStep(final IExecutionDMContext execCtx, final StepType stepType) {
fRunControl.canStep(
execCtx, stepType, new DataRequestMonitor<Boolean>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (isSuccess() && getData()) {
fRunControl.step(execCtx, stepType, new RequestMonitor(getExecutor(), null));
} else if (doCanEnqueueStep(execCtx, stepType)) {
List<StepRequest> stepQueue = fStepQueues.get(execCtx);
if (stepQueue == null) {
stepQueue = new LinkedList<StepRequest>();
fStepQueues.put(execCtx, stepQueue);
}
if (stepQueue.size() < fQueueDepth) {
stepQueue.add(new StepRequest(stepType));
}
}
}
});
}
/**
@ -191,7 +175,7 @@ public class StepQueueManager extends AbstractDsfService
///////////////////////////////////////////////////////////////////////////
@DsfServiceEventHandler
public void eventDispatched(ISuspendedDMEvent e) {
public void eventDispatched(final ISuspendedDMEvent e) {
// Take care of the stepping time out
fTimedOutFlags.remove(e.getDMContext());
ScheduledFuture<?> future = fTimedOutFutures.remove(e.getDMContext());
@ -200,26 +184,23 @@ public class StepQueueManager extends AbstractDsfService
// Check if there's a step pending, if so execute it
if (fStepQueues.containsKey(e.getDMContext())) {
List<StepRequest> queue = fStepQueues.get(e.getDMContext());
StepRequest request = queue.remove(queue.size() - 1);
final StepRequest request = queue.remove(queue.size() - 1);
if (queue.isEmpty()) fStepQueues.remove(e.getDMContext());
if (request.fIsInstructionStep) {
if (fRunControl.canInstructionStep(e.getDMContext(), request.fStepType)) {
fRunControl.instructionStep(
e.getDMContext(), request.fStepType, new RequestMonitor(getExecutor(), null));
} else {
// For whatever reason we can't step anymore, so clear out
// the step queue.
fStepQueues.remove(e.getDMContext());
}
} else {
if (fRunControl.canStep(e.getDMContext(), request.fStepType)) {
fRunControl.step(e.getDMContext(), request.fStepType,new RequestMonitor(getExecutor(), null));
} else {
// For whatever reason we can't step anymore, so clear out
// the step queue.
fStepQueues.remove(e.getDMContext());
}
}
fRunControl.canStep(
e.getDMContext(), request.fStepType,
new DataRequestMonitor<Boolean>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (isSuccess() && getData()) {
fRunControl.step(
e.getDMContext(), request.fStepType, new RequestMonitor(getExecutor(), null));
} else {
// For whatever reason we can't step anymore, so clear out
// the step queue.
fStepQueues.remove(e.getDMContext());
}
}
});
}
}

View file

@ -219,13 +219,23 @@ public class PDARunControl extends AbstractDsfService
}
public boolean canResume(IExecutionDMContext context) {
public void canResume(IExecutionDMContext context, DataRequestMonitor<Boolean> rm) {
rm.setData(doCanResume(context));
rm.done();
}
private boolean doCanResume(IExecutionDMContext context) {
return isSuspended(context) && !fResumePending;
}
}
public boolean canSuspend(IExecutionDMContext context) {
public void canSuspend(IExecutionDMContext context, DataRequestMonitor<Boolean> rm) {
rm.setData(doCanSuspend(context));
rm.done();
}
private boolean doCanSuspend(IExecutionDMContext context) {
return !isSuspended(context);
}
}
public boolean isSuspended(IExecutionDMContext context) {
return fSuspended;
@ -238,7 +248,7 @@ public class PDARunControl extends AbstractDsfService
public void resume(IExecutionDMContext context, final RequestMonitor rm) {
assert context != null;
if (canResume(context)) {
if (doCanResume(context)) {
fResumePending = true;
fCommandControl.queueCommand(
new PDAResumeCommand(fCommandControl.getProgramDMContext()),
@ -260,7 +270,7 @@ public class PDARunControl extends AbstractDsfService
public void suspend(IExecutionDMContext context, final RequestMonitor rm){
assert context != null;
if (canSuspend(context)) {
if (doCanSuspend(context)) {
fCommandControl.queueCommand(
new PDASuspendCommand(fCommandControl.getProgramDMContext()),
new DataRequestMonitor<PDACommandResult>(getExecutor(), rm));
@ -270,14 +280,14 @@ public class PDARunControl extends AbstractDsfService
}
}
public boolean canStep(IExecutionDMContext context, StepType stepType) {
return canResume(context);
public void canStep(IExecutionDMContext context, StepType stepType, DataRequestMonitor<Boolean> rm) {
canResume(context, rm);
}
public void step(IExecutionDMContext context, StepType stepType, final RequestMonitor rm) {
assert context != null;
if (canResume(context)) {
if (doCanResume(context)) {
fResumePending = true;
fStepping = true;
@ -299,14 +309,6 @@ public class PDARunControl extends AbstractDsfService
}
}
public boolean canInstructionStep(IExecutionDMContext context, StepType stepType) {
return false;
}
public void instructionStep(IExecutionDMContext context, StepType stepType, RequestMonitor rm) {
PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Operation not implemented");
}
public void getExecutionContexts(final IContainerDMContext containerDmc, final DataRequestMonitor<IExecutionDMContext[]> rm) {
PDAPlugin.failRequest(rm, NOT_SUPPORTED, "Operation not implemented");
}

View file

@ -110,13 +110,20 @@ public class GDBRunControl extends MIRunControl {
}
@Override
public void suspend(IExecutionDMContext context, RequestMonitor requestMonitor){
if (canSuspend(context)) {
fGdb.interrupt();
} else {
requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_STATE, "Context cannot be suspended.", null)); //$NON-NLS-1$
}
requestMonitor.done();
public void suspend(IExecutionDMContext context, final RequestMonitor rm){
canSuspend(
context,
new DataRequestMonitor<Boolean>(getExecutor(), rm) {
@Override
protected void handleSuccess() {
if (getData()) {
fGdb.interrupt();
} else {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INVALID_STATE, "Context cannot be suspended.", null)); //$NON-NLS-1$
}
rm.done();
}
});
}