Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aad7ddf28f4d0e2c016b98a7c855e9b5640ba938 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*******************************************************************************
 * Copyright (c) 2007 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package com.windriver.tcf.dsf.ui;

import java.util.concurrent.RejectedExecutionException;

import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.ThreadSafe;
import org.eclipse.dd.dsf.debug.ui.viewmodel.launch.StackFramesLayoutNode;
import org.eclipse.dd.dsf.debug.ui.viewmodel.launch.StandardLaunchRootLayoutNode;
import org.eclipse.dd.dsf.debug.ui.viewmodel.launch.StandardProcessLayoutNode;
import org.eclipse.dd.dsf.debug.ui.viewmodel.launch.StandardLaunchRootLayoutNode.LaunchesEvent;
import org.eclipse.dd.dsf.service.DsfSession;
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMAdapter;
import org.eclipse.dd.dsf.ui.viewmodel.IVMLayoutNode;
import org.eclipse.dd.dsf.ui.viewmodel.IVMRootLayoutNode;
import org.eclipse.dd.dsf.ui.viewmodel.dm.AbstractDMVMProvider;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchesListener2;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;


@SuppressWarnings("restriction")
public class LaunchVMProvider extends AbstractDMVMProvider 
implements IDebugEventSetListener, ILaunchesListener2 {

    @ThreadSafe
    public LaunchVMProvider(AbstractVMAdapter adapter, IPresentationContext presentationContext, 
            DsfSession session, ILaunch launch) 
    {
        super(adapter, presentationContext, session);

        IVMRootLayoutNode launchNode = new StandardLaunchRootLayoutNode(this, launch);
        // Container node to contain all processes and threads
        IVMLayoutNode containerNode = new ContainerLayoutNode(this, getSession());
        IVMLayoutNode processesNode = new StandardProcessLayoutNode(this);
        launchNode.setChildNodes(new IVMLayoutNode[] { containerNode, processesNode});

        IVMLayoutNode threadsNode = new ThreadLayoutNode(this, getSession());
        containerNode.setChildNodes(new IVMLayoutNode[] { threadsNode });

        IVMLayoutNode stackFramesNode = new StackFramesLayoutNode(this, getSession());
        threadsNode.setChildNodes(new IVMLayoutNode[] { stackFramesNode });

        setRootLayoutNode(launchNode);

        DebugPlugin.getDefault().addDebugEventListener(this);
        DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
    }


    public void handleDebugEvents(final DebugEvent[] events) {
        if (isDisposed()) return;

        // We're in session's executor thread.  Re-dispach to VM Adapter 
        // executor thread and then call root layout node.
        try {
            getExecutor().execute(new Runnable() {
                public void run() {
                    if (isDisposed()) return;

                    for (final DebugEvent event : events) {
                        IVMRootLayoutNode rootLayoutNode = getRootLayoutNode();
                        if (rootLayoutNode != null && rootLayoutNode.getDeltaFlags(event) != 0) {
                            rootLayoutNode.createDelta(
                                    event, 
                                    new DataRequestMonitor<IModelDelta>(getExecutor(), null) {
                                        @Override
                                        public void handleCompleted() {
                                            if (getStatus().isOK()) {
                                                getModelProxy().fireModelChangedNonDispatch(getData());
                                            }
                                        }
                                        @Override
                                        public String toString() {
                                            return "Result of a delta for debug event: '" + event.toString() +
                                            "' in VMP: '" + LaunchVMProvider.this + "'" +
                                            "\n" + getData();
                                        }
                                    });
                        }
                    }
                }});
        }
        catch (RejectedExecutionException e) {
            // Ignore.  This exception could be thrown if the provider is being 
            // shut down.  
        }
    }

    @Override
    public void dispose() {
        DebugPlugin.getDefault().removeDebugEventListener(this);
        DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
        super.dispose();
    }

    public void launchesAdded(ILaunch[] launches) {
        handleLaunchesEvent(new LaunchesEvent(launches, LaunchesEvent.Type.ADDED)); 
    }

    public void launchesRemoved(ILaunch[] launches) {
        handleLaunchesEvent(new LaunchesEvent(launches, LaunchesEvent.Type.REMOVED)); 
    }

    public void launchesChanged(ILaunch[] launches) {
        handleLaunchesEvent(new LaunchesEvent(launches, LaunchesEvent.Type.CHANGED)); 
    }

    public void launchesTerminated(ILaunch[] launches) {
        handleLaunchesEvent(new LaunchesEvent(launches, LaunchesEvent.Type.TERMINATED)); 
    }

    private void handleLaunchesEvent(final LaunchesEvent event) {
        if (isDisposed()) return;

        // We're in session's executor thread.  Re-dispach to VM Adapter 
        // executor thread and then call root layout node.
        try {
            getExecutor().execute(new Runnable() {
                public void run() {
                    if (isDisposed()) return;

                    IVMRootLayoutNode rootLayoutNode = getRootLayoutNode();
                    if (rootLayoutNode != null && rootLayoutNode.getDeltaFlags(event) != 0) {
                        rootLayoutNode.createDelta(
                                event, 
                                new DataRequestMonitor<IModelDelta>(getExecutor(), null) {
                                    @Override
                                    public void handleCompleted() {
                                        if (getStatus().isOK()) {
                                            getModelProxy().fireModelChangedNonDispatch(getData());
                                        }
                                    }
                                    @Override
                                    public String toString() {
                                        return "Result of a delta for launch event: '" + event.toString() +
                                        "' in VMP: '" + LaunchVMProvider.this + "'" +
                                        "\n" + getData();
                                    }
                                });
                    }
                }});
        }
        catch (RejectedExecutionException e) {
            // Ignore.  This exception could be thrown if the provider is being 
            // shut down.  
        }
    }
}

Back to the top