First submit for debug plugin
[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 ILaunch getLaunch() {
79                 return this.getDebugTarget().getLaunch();
80         }
81
82         public boolean canResume() {
83                 return isSuspended;
84         }
85
86         public boolean canSuspend() {
87                 return !isSuspended;
88         }
89
90         public boolean isSuspended() {
91                 return isSuspended;
92         }
93
94         protected void setSuspended(boolean isSuspended) {
95                 this.isSuspended = isSuspended;
96         }
97
98         protected void prepareForResume() {
99                 isSuspended = false;
100                 this.createName() ;
101                 this.frames = null ;
102                 DebugEvent ev = new DebugEvent(this, DebugEvent.RESUME, DebugEvent.CLIENT_REQUEST);
103                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });            
104         }
105
106         public void resume() throws DebugException {
107                 this.prepareForResume() ;
108                 ((PHPDebugTarget) this.getDebugTarget()).getPHPDBGProxy().resume(this);
109         }
110
111         /*
112         public void doSuspend(SuspensionPoint suspensionPoint) {
113 //              this.getPHPDebuggerProxy().readFrames(this);
114                 this.createName(suspensionPoint) ;
115                 this.suspend() ;
116         }
117         */
118
119         public void suspend()  {
120                 isStepping = false ;
121                 isSuspended = true;
122                 DebugEvent ev = new DebugEvent(this, DebugEvent.SUSPEND, DebugEvent.BREAKPOINT);
123                 DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
124         }
125
126         public boolean canStepInto() {
127                 return isSuspended && this.hasStackFrames();
128         }
129
130         public boolean canStepOver() {
131                 return isSuspended && this.hasStackFrames();
132         }
133
134         public boolean canStepReturn() {
135                 return false;
136         }
137
138         public boolean isStepping() {
139                 return isStepping;
140         }
141
142         public void stepInto() throws DebugException {
143                 isStepping = true ;
144                 this.createName() ;
145                 this.frames = null ;
146                 frames[0].stepInto();
147         }
148
149         public void stepOver() throws DebugException {
150                 isStepping = true ;             
151                 this.createName() ;
152                 this.frames = null ;            
153                 frames[0].stepOver() ;
154         }
155
156         public void stepReturn() throws DebugException {
157         }
158
159         public boolean canTerminate() {
160                 return !isTerminated;
161         }
162
163         public boolean isTerminated() {
164                 return isTerminated;
165         }
166
167         public void terminate() throws DebugException {
168                 isTerminated = true;
169                 this.frames = null;
170         }
171
172         public Object getAdapter(Class arg0) {
173                 return null;
174         }
175
176         public void setStackFrames(PHPStackFrame[] frames) {
177                 this.frames = frames;
178         }
179
180         public String getName() {
181                 return name;
182         }
183
184         public void setName(String name) {
185                 this.name = name;
186         }
187
188         protected void createName() {
189                 //this.createName(null) ;       
190         }
191
192         /*      
193         protected void createName(SuspensionPoint suspensionPoint) {
194                 this.name = "PHP Thread - " + this.getId()  ;
195                 if (suspensionPoint != null) { 
196                         this.name += " (" + suspensionPoint + ")" ;
197                 }
198         }
199         */
200
201         public int getId() {
202                 return id;
203         }
204
205         public void setId(int id) {
206                 this.id = id;
207         }
208
209 }