gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / handlers / BaseEnableEventHandler.java
CommitLineData
498704b3 1/**********************************************************************
ba3a9bd2 2 * Copyright (c) 2012, 2013 Ericsson
cfdb727a 3 *
498704b3
BH
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
cfdb727a
AM
8 *
9 * Contributors:
498704b3 10 * Bernd Hufmann - Initial API and implementation
ba3a9bd2 11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
498704b3 12 **********************************************************************/
8e8c0226 13package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers;
498704b3
BH
14
15import java.util.List;
16
17import org.eclipse.core.commands.ExecutionEvent;
18import org.eclipse.core.commands.ExecutionException;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.Status;
22import org.eclipse.core.runtime.jobs.Job;
23import org.eclipse.jface.window.Window;
8e8c0226
AM
24import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType;
25import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
26import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
27import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.IEnableEventsDialog;
28import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
29import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
30import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
31import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
32import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
33import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
498704b3
BH
34import org.eclipse.ui.IWorkbenchWindow;
35import org.eclipse.ui.PlatformUI;
36
37/**
498704b3 38 * <p>
ccc66d01 39 * Base command handler implementation to enable events.
498704b3 40 * </p>
cfdb727a 41 *
dbd4432d 42 * @author Bernd Hufmann
498704b3 43 */
77735e82 44public abstract class BaseEnableEventHandler extends BaseControlViewHandler {
498704b3
BH
45
46 // ------------------------------------------------------------------------
47 // Attributes
48 // ------------------------------------------------------------------------
49 /**
c56972bb 50 * The command execution parameter.
498704b3 51 */
c56972bb 52 protected CommandParameter fParam = null;
498704b3
BH
53
54 // ------------------------------------------------------------------------
55 // Operations
56 // ------------------------------------------------------------------------
cfdb727a 57
ccc66d01
BH
58 /**
59 * Enables a list of events for given parameters.
cfdb727a
AM
60 *
61 * @param param
62 * - a parameter instance with data for the command execution
63 * @param eventNames
64 * - list of event names
65 * @param isKernel
66 * - true if kernel domain else false
d4514365
BH
67 * @param filterExpression
68 * - a filter expression
cfdb727a
AM
69 * @param monitor
70 * - a progress monitor
ccc66d01 71 * @throws ExecutionException
cfdb727a 72 * If the command fails for some reason
ccc66d01 73 */
77735e82 74 public abstract void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
c56972bb 75
ccc66d01
BH
76 /**
77 * Enables all syscall events.
cfdb727a
AM
78 *
79 * @param param
80 * - a parameter instance with data for the command execution
81 * @param monitor
82 * - a progress monitor
ccc66d01 83 * @throws ExecutionException
cfdb727a 84 * If the command fails for some reason
ccc66d01 85 */
77735e82 86 public abstract void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
cfdb727a 87
ccc66d01
BH
88 /**
89 * Enables a dynamic probe.
cfdb727a
AM
90 *
91 * @param param
92 * - a parameter instance with data for the command execution
93 * @param eventName
94 * - a event name
95 * @param isFunction
96 * - true for dynamic function entry/return probe else false
97 * @param probe
98 * - a dynamic probe information
99 * @param monitor
100 * - a progress monitor
ccc66d01 101 * @throws ExecutionException
cfdb727a 102 * If the command fails for some reason
ccc66d01 103 */
77735e82 104 public abstract void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
cfdb727a 105
ccc66d01
BH
106 /**
107 * Enables events using log level
cfdb727a
AM
108 *
109 * @param param
110 * - a parameter instance with data for the command execution
111 * @param eventName
112 * - a event name
113 * @param logLevelType
114 * - a log level type
115 * @param level
116 * - a log level
d4514365
BH
117 * @param filterExpression
118 * - a filter expression
cfdb727a
AM
119 * @param monitor
120 * - a progress monitor
ccc66d01 121 * @throws ExecutionException
cfdb727a
AM
122 * If the command fails for some reason
123 */
77735e82 124 public abstract void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
cfdb727a 125
ccc66d01 126 /**
cfdb727a
AM
127 * @param param
128 * - a parameter instance with data for the command execution
ccc66d01
BH
129 * @return returns the relevant domain (null if domain is not known)
130 */
77735e82 131 public abstract TraceDomainComponent getDomain(CommandParameter param);
ccc66d01 132
498704b3
BH
133 @Override
134 public Object execute(ExecutionEvent event) throws ExecutionException {
135
136 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
137
138 if (window == null) {
139 return false;
140 }
c56972bb
BH
141 fLock.lock();
142 try {
143 // Make a copy for thread safety
144 final CommandParameter param = fParam.clone();
498704b3 145
c56972bb
BH
146 TargetNodeComponent node = param.getSession().getTargetNode();
147 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
d132bcc7 148
c56972bb
BH
149 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
150 dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
151 dialog.setTraceDomainComponent(getDomain(param));
d132bcc7 152
c56972bb
BH
153 if (dialog.open() != Window.OK) {
154 return null;
155 }
498704b3 156
c56972bb
BH
157 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
158 @Override
159 protected IStatus run(IProgressMonitor monitor) {
f455db37 160 Exception error = null;
c56972bb
BH
161
162 try {
d4514365
BH
163 String filter = dialog.getFilterExpression();
164
c56972bb
BH
165 // Enable tracepoint events
166 if (dialog.isTracepoints()) {
167 if (dialog.isAllTracePoints()) {
d4514365 168 enableEvents(param, null, dialog.isKernel(), filter, monitor);
c56972bb
BH
169 } else {
170 List<String> eventNames = dialog.getEventNames();
171 if (!eventNames.isEmpty()) {
d4514365 172 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
c56972bb 173 }
ccc66d01
BH
174 }
175 }
ccc66d01 176
c56972bb 177 // Enable syscall events
ccc66d01 178 if (dialog.isAllSysCalls()) {
c56972bb
BH
179 enableSyscalls(param, monitor);
180 }
ccc66d01 181
c56972bb
BH
182 // Enable dynamic probe
183 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
184 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
185 }
ccc66d01 186
c56972bb
BH
187 // Enable dynamic function probe
188 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
189 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
190 }
ccc66d01 191
c56972bb
BH
192 // Enable event using a wildcard
193 if (dialog.isWildcard()) {
194 List<String> eventNames = dialog.getEventNames();
195 eventNames.add(dialog.getWildcard());
ccc66d01 196
c56972bb 197 if (!eventNames.isEmpty()) {
d4514365 198 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
c56972bb 199 }
498704b3 200 }
c56972bb
BH
201
202 // Enable events using log level
203 if (dialog.isLogLevel()) {
d4514365 204 enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), filter, monitor);
c56972bb
BH
205 }
206
207 } catch (ExecutionException e) {
f455db37 208 error = e;
ccc66d01 209 }
498704b3 210
f455db37
BH
211 // refresh in all cases
212 refresh(param);
498704b3 213
f455db37 214 if (error != null) {
cfdb727a 215 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
498704b3 216 }
c56972bb 217 return Status.OK_STATUS;
498704b3 218 }
c56972bb
BH
219 };
220 job.setUser(true);
221 job.schedule();
222 } finally {
223 fLock.unlock();
224 }
498704b3
BH
225 return null;
226 }
227}
This page took 0.060647 seconds and 5 git commands to generate.