1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.codegen.simucontroller.debug; |
5 | |
6 | import java.util.Observable; |
7 | import java.util.Observer; |
8 | |
9 | import org.eclipse.debug.core.DebugEvent; |
10 | import org.eclipse.debug.core.DebugException; |
11 | import org.eclipse.debug.core.ILaunch; |
12 | import org.eclipse.debug.core.model.IBreakpoint; |
13 | import org.eclipse.debug.core.model.IDebugTarget; |
14 | import org.eclipse.debug.core.model.IStackFrame; |
15 | import org.eclipse.debug.core.model.IThread; |
16 | import org.eclipse.emf.common.notify.Notification; |
17 | |
18 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.DockModel; |
19 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockEvent; |
20 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockPerformedDebugStepEvent; |
21 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockResumedEvent; |
22 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockSimTimeChangedEvent; |
23 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockSimulationTerminatedEvent; |
24 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockStartedDebugStepEvent; |
25 | import de.uka.ipd.sdq.codegen.simucontroller.dockmodel.events.DockSuspendedEvent; |
26 | import de.uka.ipd.sdq.simucomframework.simulationdock.SimulationDockService; |
27 | |
28 | /** |
29 | * @author Snowball |
30 | * |
31 | */ |
32 | public class SimulationDebugThread extends SimulationDebugElement implements |
33 | IThread, Observer { |
34 | |
35 | private DockModel myDock; |
36 | private boolean isTerminated; |
37 | |
38 | public SimulationDebugThread(IDebugTarget myDebugTarget, ILaunch launch, DockModel dock) { |
39 | super(myDebugTarget, launch); |
40 | |
41 | if (this.myDebugTarget == null) |
42 | throw new IllegalArgumentException("Debug target has to be set"); |
43 | |
44 | this.myDock = dock; |
45 | this.myDock.addObserver(this); |
46 | } |
47 | |
48 | /* (non-Javadoc) |
49 | * @see org.eclipse.debug.core.model.IThread#getBreakpoints() |
50 | */ |
51 | public IBreakpoint[] getBreakpoints() { |
52 | return new IBreakpoint[0]; |
53 | } |
54 | |
55 | /* (non-Javadoc) |
56 | * @see org.eclipse.debug.core.model.IThread#getName() |
57 | */ |
58 | public String getName() throws DebugException { |
59 | return "Simulation Event Processor - SimTime: "+this.myDock.getSimTime(); |
60 | } |
61 | |
62 | /* (non-Javadoc) |
63 | * @see org.eclipse.debug.core.model.IThread#getPriority() |
64 | */ |
65 | public int getPriority() throws DebugException { |
66 | return 0; |
67 | } |
68 | |
69 | /* (non-Javadoc) |
70 | * @see org.eclipse.debug.core.model.IThread#getStackFrames() |
71 | */ |
72 | public IStackFrame[] getStackFrames() throws DebugException { |
73 | return new IStackFrame[0]; |
74 | } |
75 | |
76 | /* (non-Javadoc) |
77 | * @see org.eclipse.debug.core.model.IThread#getTopStackFrame() |
78 | */ |
79 | public IStackFrame getTopStackFrame() throws DebugException { |
80 | return null; |
81 | } |
82 | |
83 | /* (non-Javadoc) |
84 | * @see org.eclipse.debug.core.model.IThread#hasStackFrames() |
85 | */ |
86 | public boolean hasStackFrames() throws DebugException { |
87 | return false; |
88 | } |
89 | |
90 | /* (non-Javadoc) |
91 | * @see org.eclipse.debug.core.model.ISuspendResume#canResume() |
92 | */ |
93 | public boolean canResume() { |
94 | return true; |
95 | } |
96 | |
97 | /* (non-Javadoc) |
98 | * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend() |
99 | */ |
100 | public boolean canSuspend() { |
101 | return true; |
102 | } |
103 | |
104 | /* (non-Javadoc) |
105 | * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended() |
106 | */ |
107 | public boolean isSuspended() { |
108 | return myDock.isSuspended(); |
109 | } |
110 | |
111 | /* (non-Javadoc) |
112 | * @see org.eclipse.debug.core.model.ISuspendResume#resume() |
113 | */ |
114 | public void resume() throws DebugException { |
115 | myDock.getService().resume(); |
116 | } |
117 | |
118 | /* (non-Javadoc) |
119 | * @see org.eclipse.debug.core.model.ISuspendResume#suspend() |
120 | */ |
121 | public void suspend() throws DebugException { |
122 | myDock.getService().suspend(); |
123 | } |
124 | |
125 | /* (non-Javadoc) |
126 | * @see org.eclipse.debug.core.model.IStep#canStepInto() |
127 | */ |
128 | public boolean canStepInto() { |
129 | return false; |
130 | } |
131 | |
132 | /* (non-Javadoc) |
133 | * @see org.eclipse.debug.core.model.IStep#canStepOver() |
134 | */ |
135 | public boolean canStepOver() { |
136 | return myDebugTarget == null ? false : myDebugTarget.isSuspended(); |
137 | } |
138 | |
139 | /* (non-Javadoc) |
140 | * @see org.eclipse.debug.core.model.IStep#canStepReturn() |
141 | */ |
142 | public boolean canStepReturn() { |
143 | return false; |
144 | } |
145 | |
146 | /* (non-Javadoc) |
147 | * @see org.eclipse.debug.core.model.IStep#isStepping() |
148 | */ |
149 | public boolean isStepping() { |
150 | return myDock.isStepping(); |
151 | } |
152 | |
153 | /* (non-Javadoc) |
154 | * @see org.eclipse.debug.core.model.IStep#stepInto() |
155 | */ |
156 | public void stepInto() throws DebugException { |
157 | } |
158 | |
159 | /* (non-Javadoc) |
160 | * @see org.eclipse.debug.core.model.IStep#stepOver() |
161 | */ |
162 | public void stepOver() throws DebugException { |
163 | myDock.getService().step(); |
164 | } |
165 | |
166 | /* (non-Javadoc) |
167 | * @see org.eclipse.debug.core.model.IStep#stepReturn() |
168 | */ |
169 | public void stepReturn() throws DebugException { |
170 | } |
171 | |
172 | /* (non-Javadoc) |
173 | * @see org.eclipse.debug.core.model.ITerminate#canTerminate() |
174 | */ |
175 | public boolean canTerminate() { |
176 | return true; |
177 | } |
178 | |
179 | /* (non-Javadoc) |
180 | * @see org.eclipse.debug.core.model.ITerminate#isTerminated() |
181 | */ |
182 | public boolean isTerminated() { |
183 | return this.isTerminated; |
184 | } |
185 | |
186 | /* (non-Javadoc) |
187 | * @see org.eclipse.debug.core.model.ITerminate#terminate() |
188 | */ |
189 | public void terminate() throws DebugException { |
190 | myDock.getService().stopSimulation(); |
191 | } |
192 | |
193 | public void setSimControl(SimulationDockService service) { |
194 | } |
195 | |
196 | public void update(Observable o, Object arg) { |
197 | if (arg instanceof DockEvent) { |
198 | DockEvent dockEvent = (DockEvent) arg; |
199 | if (dockEvent.comesFrom(this.myDock)) { |
200 | if (dockEvent instanceof DockResumedEvent) { |
201 | fireEvent(this, DebugEvent.RESUME); |
202 | } |
203 | if (dockEvent instanceof DockSuspendedEvent) { |
204 | fireEvent(this, DebugEvent.SUSPEND); |
205 | } |
206 | if (dockEvent instanceof DockPerformedDebugStepEvent) { |
207 | fireEvent(this, DebugEvent.STEP_END); |
208 | } |
209 | if (dockEvent instanceof DockStartedDebugStepEvent) { |
210 | fireEvent(this, DebugEvent.STEP_OVER); |
211 | } |
212 | if (dockEvent instanceof DockSimTimeChangedEvent) { |
213 | if (this.getDebugTarget().isSuspended()){ |
214 | // Only in suspend mode update the UI, otherwise too many event will cause a |
215 | // deadlock of the debug view |
216 | fireEvent(this, DebugEvent.CHANGE); |
217 | } |
218 | } |
219 | if (dockEvent instanceof DockSimulationTerminatedEvent) { |
220 | this.isTerminated = true; |
221 | fireEvent(this, DebugEvent.TERMINATE); |
222 | } |
223 | } |
224 | } |
225 | } |
226 | |
227 | public void dispose() { |
228 | this.myDock.deleteObserver(this); |
229 | this.myDock = null; |
230 | this.myDebugTarget = null; |
231 | } |
232 | |
233 | @Override |
234 | public void notifyChanged(Notification notification) { |
235 | } |
236 | |
237 | } |