~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbSelectPrevTraceRecordCommand.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2010, 2011 Ericsson and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 * 
 
8
 * Contributors:
 
9
 *     Ericsson - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.dsf.gdb.internal.ui.commands;
 
12
 
 
13
import java.util.Hashtable;
 
14
import java.util.concurrent.ExecutionException;
 
15
import java.util.concurrent.RejectedExecutionException;
 
16
 
 
17
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
 
18
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
 
19
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
 
20
import org.eclipse.cdt.dsf.concurrent.Query;
 
21
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
 
22
import org.eclipse.cdt.dsf.datamodel.DMContexts;
 
23
import org.eclipse.cdt.dsf.gdb.internal.commands.ISelectPrevTraceRecordHandler;
 
24
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
 
25
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl;
 
26
import org.eclipse.cdt.dsf.gdb.service.GDBTraceControl_7_2.TraceRecordSelectedChangedEvent;
 
27
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceRecordDMContext;
 
28
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceStatusDMData;
 
29
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceTargetDMContext;
 
30
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
 
31
import org.eclipse.cdt.dsf.service.DsfSession;
 
32
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
 
33
import org.eclipse.core.runtime.CoreException;
 
34
import org.eclipse.core.runtime.IProgressMonitor;
 
35
import org.eclipse.debug.core.IRequest;
 
36
import org.eclipse.debug.core.commands.AbstractDebugCommand;
 
37
import org.eclipse.debug.core.commands.IDebugCommandRequest;
 
38
import org.eclipse.debug.core.commands.IEnabledStateRequest;
 
39
 
 
40
/**
 
41
 * Command to select the previous trace record
 
42
 * 
 
43
 * @since 2.1
 
44
 */
 
45
@SuppressWarnings("restriction")
 
46
public class GdbSelectPrevTraceRecordCommand extends AbstractDebugCommand implements ISelectPrevTraceRecordHandler {
 
47
        private final DsfExecutor fExecutor;
 
48
        private final DsfServicesTracker fTracker;
 
49
        private final DsfSession fSession;
 
50
 
 
51
        public GdbSelectPrevTraceRecordCommand(DsfSession session) {
 
52
                fExecutor = session.getExecutor();
 
53
                fTracker = new DsfServicesTracker(GdbUIPlugin.getBundleContext(), session.getId());
 
54
                fSession = session;
 
55
        }    
 
56
 
 
57
        public void dispose() {
 
58
                fTracker.dispose();
 
59
        }
 
60
 
 
61
        @Override
 
62
        protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException {
 
63
                if (targets.length != 1) {
 
64
                        return;
 
65
                }
 
66
 
 
67
                final ITraceTargetDMContext dmc = DMContexts.getAncestorOfType(((IDMVMContext)targets[0]).getDMContext(), ITraceTargetDMContext.class);
 
68
                if (dmc == null) {
 
69
                        return;
 
70
                }
 
71
 
 
72
        Query<Object> selectRecordQuery = new Query<Object>() {
 
73
            @Override
 
74
            public void execute(final DataRequestMonitor<Object> rm) {
 
75
                        final IGDBTraceControl traceControl = fTracker.getService(IGDBTraceControl.class);
 
76
 
 
77
                        if (traceControl != null) {
 
78
                                traceControl.getCurrentTraceRecordContext(
 
79
                                            dmc,
 
80
                                                new DataRequestMonitor<ITraceRecordDMContext>(fExecutor, rm) {
 
81
                                                        @Override
 
82
                                                        protected void handleSuccess() {
 
83
                                                         final ITraceRecordDMContext prevDmc = traceControl.createPrevRecordContext(getData());
 
84
                                                         traceControl.selectTraceRecord(prevDmc, new RequestMonitor(ImmediateExecutor.getInstance(), rm) {
 
85
                                                             @Override
 
86
                                                             protected void handleSuccess() {
 
87
                                                                 fSession.dispatchEvent(new TraceRecordSelectedChangedEvent(prevDmc), new Hashtable<String, String>());
 
88
                                                                 rm.done();
 
89
                                                             }
 
90
                                                         });
 
91
                                                        };
 
92
                                                });
 
93
                        } else {
 
94
                                rm.done();
 
95
                        }
 
96
                }
 
97
        };
 
98
        try {
 
99
                fExecutor.execute(selectRecordQuery);
 
100
                selectRecordQuery.get();
 
101
                } catch (InterruptedException e) {
 
102
                } catch (ExecutionException e) {
 
103
        } catch (RejectedExecutionException e) {
 
104
                // Can be thrown if the session is shutdown
 
105
        }
 
106
        }
 
107
 
 
108
        @Override
 
109
        protected boolean isExecutable(Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request)
 
110
        throws CoreException 
 
111
        {
 
112
                if (targets.length != 1) {
 
113
                        return false;
 
114
                }
 
115
 
 
116
                final ITraceTargetDMContext dmc = DMContexts.getAncestorOfType(((IDMVMContext)targets[0]).getDMContext(), ITraceTargetDMContext.class);
 
117
                if (dmc == null) {
 
118
                        return false;
 
119
                }
 
120
 
 
121
        Query<Boolean> canSelectRecordQuery = new Query<Boolean>() {
 
122
                @Override
 
123
                public void execute(final DataRequestMonitor<Boolean> rm) {
 
124
                        IGDBTraceControl traceControl = fTracker.getService(IGDBTraceControl.class);
 
125
 
 
126
                        if (traceControl != null) {
 
127
                                traceControl.getTraceStatus(dmc, new DataRequestMonitor<ITraceStatusDMData>(fExecutor, rm) {
 
128
                                        @Override
 
129
                                        protected void handleSuccess() {
 
130
                                                if (getData().getNumberOfCollectedFrame() > 0) {
 
131
                                                        IGDBTraceControl traceControl = fTracker.getService(IGDBTraceControl.class);
 
132
                                                        if (traceControl != null) {
 
133
                                                                traceControl.isTracing(dmc, new DataRequestMonitor<Boolean>(fExecutor, rm) {
 
134
                                                                        @Override
 
135
                                                                        protected void handleSuccess() {
 
136
                                                                                rm.setData(!getData());
 
137
                                                                                rm.done();
 
138
                                                                        };
 
139
                                                                });
 
140
                                                        } else {
 
141
                                                                rm.setData(false);
 
142
                                                                rm.done();
 
143
                                                        }
 
144
                                                } else {
 
145
                                                        rm.setData(false);
 
146
                                                        rm.done();
 
147
                                                }
 
148
                                        };
 
149
                                });
 
150
                        } else {
 
151
                                rm.setData(false);
 
152
                                rm.done();
 
153
                        }
 
154
                }
 
155
        };
 
156
                try {
 
157
                        fExecutor.execute(canSelectRecordQuery);
 
158
                        return canSelectRecordQuery.get();
 
159
                } catch (InterruptedException e) {
 
160
                } catch (ExecutionException e) {
 
161
                } catch (RejectedExecutionException e) {
 
162
                        // Can be thrown if the session is shutdown
 
163
                }
 
164
 
 
165
                return false;
 
166
        }
 
167
 
 
168
        @Override
 
169
        protected Object getTarget(Object element) {
 
170
                if (element instanceof IDMVMContext) {
 
171
                        return element;
 
172
                }
 
173
                return null;
 
174
        }
 
175
 
 
176
        @Override
 
177
        protected boolean isRemainEnabled(IDebugCommandRequest request) {
 
178
                return true;
 
179
        }
 
180
}