~vil/pydev/upstream

« back to all changes in this revision

Viewing changes to org.python.pydev.debug/src/org/python/pydev/debug/model/PyDebugTarget.java

  • Committer: Vladimír Lapáček
  • Date: 2006-08-30 18:38:44 UTC
  • Revision ID: vladimir.lapacek@gmail.com-20060830183844-f4d82c1239a7770a
Initial import of upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Author: atotic
 
3
 * Created on Mar 23, 2004
 
4
 * License: Common Public License v1.0
 
5
 */
 
6
package org.python.pydev.debug.model;
 
7
 
 
8
import org.eclipse.core.runtime.IPath;
 
9
import org.eclipse.debug.core.DebugEvent;
 
10
import org.eclipse.debug.core.DebugException;
 
11
import org.eclipse.debug.core.DebugPlugin;
 
12
import org.eclipse.debug.core.IBreakpointManager;
 
13
import org.eclipse.debug.core.ILaunch;
 
14
import org.eclipse.debug.core.model.IProcess;
 
15
import org.eclipse.debug.core.model.IThread;
 
16
import org.python.pydev.debug.model.remote.RemoteDebugger;
 
17
/**
 
18
 * Debugger class that represents a single python process.
 
19
 * 
 
20
 * It deals with events from RemoteDebugger.
 
21
 * Breakpoint updating.
 
22
 */
 
23
public class PyDebugTarget extends AbstractDebugTarget {
 
24
        //private ILaunch launch;
 
25
        private IProcess process;               
 
26
 
 
27
        public PyDebugTarget(ILaunch launch, IProcess process, IPath file, RemoteDebugger debugger) {
 
28
                this.launch = launch;
 
29
                this.process = process;
 
30
                this.file = file;
 
31
                this.debugger = debugger;
 
32
                this.threads = new IThread[0];
 
33
                launch.addDebugTarget(this);
 
34
                debugger.setTarget(this);
 
35
                IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
 
36
                breakpointManager.addBreakpointListener(this);
 
37
                // we have to know when we get removed, so that we can shut off the debugger
 
38
                DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
 
39
        }               
 
40
 
 
41
        public void launchRemoved(ILaunch launch) {
 
42
                // shut down the remote debugger when parent launch
 
43
                if (launch == this.launch) {
 
44
                        IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
 
45
                        breakpointManager.removeBreakpointListener(this);
 
46
                        debugger.dispose();
 
47
                        debugger = null;
 
48
                }
 
49
        }       
 
50
 
 
51
        public IProcess getProcess() {
 
52
                return process;
 
53
        }
 
54
 
 
55
        public boolean canTerminate() {
 
56
                // We can always terminate, it does no harm
 
57
            if(process == null){
 
58
                return false;
 
59
        }
 
60
                return true;
 
61
        }
 
62
 
 
63
        public boolean isTerminated() {
 
64
        if(process == null){
 
65
            return true;
 
66
        }
 
67
                return process.isTerminated();
 
68
        }
 
69
 
 
70
        public void terminate() throws DebugException {
 
71
                if (debugger != null){
 
72
                        debugger.disconnect();
 
73
        }
 
74
        
 
75
                threads = new IThread[0];
 
76
                if(process != null){
 
77
                        process.terminate();
 
78
                        process = null;
 
79
                }
 
80
                fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
 
81
        }               
 
82
        
 
83
        //From IDebugElement
 
84
        public ILaunch getLaunch() {
 
85
                return launch;
 
86
        }       
 
87
}