Show errors in console
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / model / PHPThread.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpdt.internal.debug.core.model;
13
14 import org.eclipse.debug.core.DebugEvent;
15 import org.eclipse.debug.core.DebugException;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.ILaunch;
18 import org.eclipse.debug.core.model.IBreakpoint;
19 import org.eclipse.debug.core.model.IDebugTarget;
20 import org.eclipse.debug.core.model.IStackFrame;
21 import org.eclipse.debug.core.model.IThread;
22
23 public class PHPThread implements IThread {
24
25         private PHPStackFrame[] frames;
26         private IDebugTarget target;
27         private boolean isSuspended = false;
28         private boolean isTerminated = false;
29         private boolean isStepping = false;
30         private String name ;
31         private int id ;
32         
33         public PHPThread(IDebugTarget target, int id) {
34                 this.target = target;
35                 this.setId(id) ;
36                 this.createName() ;
37         }
38
39         public IStackFrame[] getStackFrames() throws DebugException {
40                 return frames;
41         }
42
43         public int getStackFramesSize() {
44                 return frames.length;
45         }
46
47         public boolean hasStackFrames() {
48                 if (frames == null) {
49                         return false;
50                 }
51                 return frames.length > 0;
52         }
53
54         public int getPriority() throws DebugException {
55                 return 0;
56         }
57
58         public IStackFrame getTopStackFrame() throws DebugException {
59                 if (frames == null || frames.length == 0) {
60                         return null;
61                 }
62                 return (IStackFrame) frames[0];
63         }
64
65
66         public IBreakpoint[] getBreakpoints() {
67                 return null;
68         }
69
70         public String getModelIdentifier() {
71                 return this.getDebugTarget().getModelIdentifier();
72         }
73
74         public IDebugTarget getDebugTarget() {
75                 return target;
76         }
77
78         public void setDebugTarget(IDebugTarget target) {
79                 this.target= target;
80         }
81         
82         public ILaunch getLaunch() {
83                 return this.getDebugTarget().getLaunch();
84         }
85
86         public boolean canResume() {
87                 return isSuspended;
88         }
89
90         public boolean canSuspend() {
91                 return !isSuspended;
92         }
93
94         public boolean isSuspended() {
95                 return isSuspended;
96         }
97
98         protected void setSuspended(boolean isSuspended) {
99                 this.isSuspended = isSuspended;
100         }
101
102         protected void prepareForResume() {
103                 isSuspended = false;
104                 this.createName() ;
105                 this.frames = null ;
106                 DebugEvent ev = new DebugEvent(this, DebugEvent.RESUME, DebugEvent.CLIENT_REQUEST);
107                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });            
108         }
109
110         public void resume() throws DebugException {
111                 this.prepareForResume() ;
112                 ((PHPDebugTarget) this.getDebugTarget()).getPHPDBGProxy().resume();
113         }
114
115         /*
116         public void doSuspend(SuspensionPoint suspensionPoint) {
117 //              this.getPHPDebuggerProxy().readFrames(this);
118                 this.createName(suspensionPoint) ;
119                 this.suspend() ;
120         }
121         */
122
123         public void suspend()  {
124                 isStepping = false;
125                 isSuspended = true;
126                 DebugEvent ev = new DebugEvent(this, DebugEvent.SUSPEND, DebugEvent.BREAKPOINT);
127                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
128         }
129
130         public boolean canStepInto() {
131                 return isSuspended && this.hasStackFrames();
132         }
133
134         public boolean canStepOver() {
135                 return isSuspended && this.hasStackFrames();
136         }
137
138         public boolean canStepReturn() {
139                 return false;
140         }
141
142         public boolean isStepping() {
143                 return isStepping;
144         }
145
146         public void stepInto() throws DebugException {
147                 isStepping = true ;
148                 this.createName() ;
149                 this.frames = null ;
150                 frames[0].stepInto();
151         }
152
153         public void stepOver() throws DebugException {
154                 isStepping = true ;             
155                 this.createName() ;
156                 this.frames = null ;            
157                 frames[0].stepOver() ;
158         }
159
160         public void stepReturn() throws DebugException {
161         }
162
163         public boolean canTerminate() {
164                 return !isTerminated;
165         }
166
167         public boolean isTerminated() {
168                 return isTerminated;
169         }
170
171         public void terminate() throws DebugException {
172                 isTerminated = true;
173                 this.frames = null;
174                 getDebugTarget().terminate();
175         }
176
177         public Object getAdapter(Class arg0) {
178                 return null;
179         }
180
181         public void setStackFrames(PHPStackFrame[] frames) {
182                 this.frames = frames;
183         }
184
185         public String getName() {
186                 return name;
187         }
188
189         public void setName(String name) {
190                 this.name = name;
191         }
192
193         protected void createName() {
194                 //this.createName(null) ;       
195         }
196
197         /*      
198         protected void createName(SuspensionPoint suspensionPoint) {
199                 this.name = "PHP Thread - " + this.getId()  ;
200                 if (suspensionPoint != null) { 
201                         this.name += " (" + suspensionPoint + ")" ;
202                 }
203         }
204         */
205
206         public int getId() {
207                 return id;
208         }
209
210         public void setId(int id) {
211                 this.id = id;
212         }
213
214 }