35943d851ce17a2bb3506bc05ab731f027685917
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / BaseEnableEventHandler.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
14
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22 import org.eclipse.core.runtime.jobs.Job;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.eclipse.jface.window.Window;
25 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ITraceLogLevel;
26 import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
27 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType;
28 import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
29 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.IEnableEventsDialog;
30 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
31 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
32 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
33 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
34 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
35 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
36 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService;
37 import org.eclipse.ui.IWorkbenchWindow;
38 import org.eclipse.ui.PlatformUI;
39
40 /**
41 * <p>
42 * Base command handler implementation to enable events.
43 * </p>
44 *
45 * @author Bernd Hufmann
46 */
47 public abstract class BaseEnableEventHandler extends BaseControlViewHandler {
48
49 // ------------------------------------------------------------------------
50 // Attributes
51 // ------------------------------------------------------------------------
52 /**
53 * The command execution parameter.
54 */
55 @Nullable
56 protected CommandParameter fParam = null;
57
58 // ------------------------------------------------------------------------
59 // Operations
60 // ------------------------------------------------------------------------
61
62 /**
63 * Enables a list of events for given parameters.
64 *
65 * @param param
66 * - a parameter instance with data for the command execution
67 * @param eventNames
68 * - list of event names
69 * @param domain
70 * - the domain type ({@link TraceDomainType})
71 * @param filterExpression
72 * - a filter expression
73 * @param excludedEvents
74 * - list of events to exclude
75 * @param monitor
76 * - a progress monitor
77 * @throws ExecutionException
78 * If the command fails for some reason
79 */
80 public abstract void enableEvents(CommandParameter param, List<String> eventNames, TraceDomainType domain, String filterExpression, List<String> excludedEvents, IProgressMonitor monitor) throws ExecutionException;
81
82 /**
83 * Enables all syscall events.
84 *
85 * @param param
86 * - a parameter instance with data for the command execution
87 * @param syscallNames
88 * - a list of syscall names
89 * @param monitor
90 * - a progress monitor
91 * @throws ExecutionException
92 * If the command fails for some reason
93 */
94 public abstract void enableSyscalls(CommandParameter param, List<String> syscallNames, IProgressMonitor monitor) throws ExecutionException;
95
96 /**
97 * Enables a dynamic probe.
98 *
99 * @param param
100 * - a parameter instance with data for the command execution
101 * @param eventName
102 * - a event name
103 * @param isFunction
104 * - true for dynamic function entry/return probe else false
105 * @param probe
106 * - a dynamic probe information
107 * @param monitor
108 * - a progress monitor
109 * @throws ExecutionException
110 * If the command fails for some reason
111 */
112 public abstract void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
113
114 /**
115 * Enables events using log level
116 *
117 * @param param
118 * - a parameter instance with data for the command execution
119 * @param eventNames
120 * - a list of event names
121 * @param logLevelType
122 * - a log level type
123 * @param level
124 * - a log level
125 * @param filterExpression
126 * - a filter expression
127 * @param domain
128 * - the domain type
129 * @param monitor
130 * - a progress monitor
131 * @throws ExecutionException
132 * If the command fails for some reason
133 */
134 public abstract void enableLogLevel(CommandParameter param, List<String> eventNames, LogLevelType logLevelType, ITraceLogLevel level, String filterExpression, TraceDomainType domain, IProgressMonitor monitor) throws ExecutionException;
135
136 /**
137 * @param param
138 * - a parameter instance with data for the command execution
139 * @return returns the relevant domain (null if domain is not known)
140 */
141 public abstract TraceDomainComponent getDomain(CommandParameter param);
142
143 @Override
144 public Object execute(ExecutionEvent event) throws ExecutionException {
145
146 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
147
148 if (window == null) {
149 return false;
150 }
151
152 // Make a copy for thread safety
153 CommandParameter tmpParam = null;
154 fLock.lock();
155 try {
156 tmpParam = fParam;
157 if (tmpParam == null) {
158 return null;
159 }
160 tmpParam = tmpParam.clone();
161 } finally {
162 fLock.unlock();
163 }
164 final CommandParameter param = tmpParam;
165
166 TargetNodeComponent node = param.getSession().getTargetNode();
167 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
168
169 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
170 dialog.setTraceProviderGroup((TraceProviderGroup) providers.get(0));
171 dialog.setTraceDomainComponent(getDomain(param));
172
173 if (dialog.open() != Window.OK) {
174 return null;
175 }
176
177 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
178 @Override
179 protected IStatus run(IProgressMonitor monitor) {
180 Exception error = null;
181 try {
182 String filter = dialog.getFilterExpression();
183 List<String> eventNames = null;
184 switch (dialog.getDomain()) {
185 case KERNEL:
186 case UST:
187 if (dialog.isAllEvents()) {
188 enableEvents(param, null, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor);
189 } else if (dialog.isTracepoints()) {
190 // Enable tracepoint events
191 if (dialog.isAllTracePoints()) {
192 enableEvents(param, null, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor);
193 } else {
194 eventNames = dialog.getEventNames();
195 if (!eventNames.isEmpty()) {
196 enableEvents(param, eventNames, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor);
197 }
198 }
199 }
200
201 // Enable syscall events
202 if (dialog.isSyscalls()) {
203 // Enable all syscall events
204 if (dialog.isAllSyscalls()) {
205 enableSyscalls(param, ILttngControlService.ALL_EVENTS, monitor);
206 } else {
207 List<String> syscallNames = dialog.getEventNames();
208 if (!syscallNames.isEmpty()) {
209 enableSyscalls(param, syscallNames, monitor);
210 }
211 }
212 }
213
214 // Enable dynamic probe
215 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
216 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
217 }
218
219 // Enable dynamic function probe
220 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
221 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
222 }
223
224 // Enable event using a wildcard
225 if (dialog.isWildcard()) {
226 eventNames = dialog.getEventNames();
227 eventNames.add(dialog.getWildcard());
228
229 if (!eventNames.isEmpty()) {
230 enableEvents(param, eventNames, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor);
231 }
232 }
233
234 // Enable events using log level
235 if (dialog.isLogLevel()) {
236 enableLogLevel(param, dialog.getEventNames(), dialog.getLogLevelType(), dialog.getLogLevel(), filter, dialog.getDomain(), monitor);
237 }
238 break;
239 case JUL:
240 case LOG4J:
241 eventNames = dialog.getEventNames();
242 if (dialog.isAllEvents()) {
243 eventNames = null;
244 }
245 if (dialog.isLogLevel()) {
246 enableLogLevel(param, eventNames, dialog.getLogLevelType(), dialog.getLogLevel(), filter, dialog.getDomain(), monitor);
247 } else {
248 enableEvents(param, eventNames, dialog.getDomain(), filter, dialog.getExcludedEvents(), monitor);
249 }
250 break;
251 //$CASES-OMITTED$
252 default:
253 break;
254 }
255 } catch (ExecutionException e) {
256 error = e;
257 }
258
259 // refresh in all cases
260 refresh(param);
261
262 if (error != null) {
263 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
264 }
265 return Status.OK_STATUS;
266 }
267 };
268 job.setUser(true);
269 job.schedule();
270 return null;
271 }
272 }
This page took 0.038609 seconds and 4 git commands to generate.