/********************************************************************** Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html Contributors: IBM Corporation - Initial implementation Vicente Fernando - www.alfersoft.com.ar **********************************************************************/ package net.sourceforge.phpdt.internal.debug.core.model; 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.model.IBreakpoint; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IStackFrame; import org.eclipse.debug.core.model.IThread; public class PHPThread implements IThread { private PHPStackFrame[] frames; private IDebugTarget target; private boolean isSuspended = false; private boolean isTerminated = false; private boolean isStepping = false; private String name ; private int id ; public PHPThread(IDebugTarget target, int id) { this.target = target; this.setId(id) ; this.createName() ; } public IStackFrame[] getStackFrames() throws DebugException { return frames; } public int getStackFramesSize() { return frames.length; } public boolean hasStackFrames() { if (frames == null) { return false; } return frames.length > 0; } public int getPriority() throws DebugException { return 0; } public IStackFrame getTopStackFrame() throws DebugException { if (frames == null || frames.length == 0) { return null; } return (IStackFrame) frames[0]; } public IBreakpoint[] getBreakpoints() { return null; } public String getModelIdentifier() { return this.getDebugTarget().getModelIdentifier(); } public IDebugTarget getDebugTarget() { return target; } public void setDebugTarget(IDebugTarget target) { this.target= target; } public ILaunch getLaunch() { return this.getDebugTarget().getLaunch(); } public boolean canResume() { return isSuspended; } public boolean canSuspend() { return !isSuspended; } public boolean isSuspended() { return isSuspended; } protected void setSuspended(boolean isSuspended) { this.isSuspended = isSuspended; } protected void prepareForResume() { isSuspended = false; this.createName() ; this.frames = null ; DebugEvent ev = new DebugEvent(this, DebugEvent.RESUME, DebugEvent.CLIENT_REQUEST); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); } public void resume() throws DebugException { this.prepareForResume() ; ((PHPDebugTarget) this.getDebugTarget()).getPHPDBGProxy().resume(); } /* public void doSuspend(SuspensionPoint suspensionPoint) { // this.getPHPDebuggerProxy().readFrames(this); this.createName(suspensionPoint) ; this.suspend() ; } */ public void suspend() { isStepping = false; isSuspended = true; DebugEvent ev = new DebugEvent(this, DebugEvent.SUSPEND, DebugEvent.BREAKPOINT); DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev }); } public boolean canStepInto() { return isSuspended && this.hasStackFrames(); } public boolean canStepOver() { return isSuspended && this.hasStackFrames(); } public boolean canStepReturn() { return false; } public boolean isStepping() { return isStepping; } public void stepInto() throws DebugException { isStepping = true ; this.createName() ; this.frames = null ; frames[0].stepInto(); } public void stepOver() throws DebugException { isStepping = true ; this.createName() ; this.frames = null ; frames[0].stepOver() ; } public void stepReturn() throws DebugException { } public boolean canTerminate() { return !isTerminated; } public boolean isTerminated() { return isTerminated; } public void terminate() throws DebugException { isTerminated = true; this.frames = null; getDebugTarget().terminate(); } public Object getAdapter(Class arg0) { return null; } public void setStackFrames(PHPStackFrame[] frames) { this.frames = frames; } public String getName() { return name; } public void setName(String name) { this.name = name; } protected void createName() { //this.createName(null) ; } /* protected void createName(SuspensionPoint suspensionPoint) { this.name = "PHP Thread - " + this.getId() ; if (suspensionPoint != null) { this.name += " (" + suspensionPoint + ")" ; } } */ public int getId() { return id; } public void setId(int id) { this.id = id; } }