1fe8a58df9e1df9ad1f927c1c7fadf19648d1c55
[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.LogLevelType;
26 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
27 import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
28 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.IEnableEventsDialog;
29 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
30 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
31 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
32 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
33 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
34 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceProviderGroup;
35 import org.eclipse.ui.IWorkbenchWindow;
36 import org.eclipse.ui.PlatformUI;
37
38 /**
39 * <p>
40 * Base command handler implementation to enable events.
41 * </p>
42 *
43 * @author Bernd Hufmann
44 */
45 public abstract class BaseEnableEventHandler extends BaseControlViewHandler {
46
47 // ------------------------------------------------------------------------
48 // Attributes
49 // ------------------------------------------------------------------------
50 /**
51 * The command execution parameter.
52 */
53 @Nullable protected CommandParameter fParam = null;
54
55 // ------------------------------------------------------------------------
56 // Operations
57 // ------------------------------------------------------------------------
58
59 /**
60 * Enables a list of events for given parameters.
61 *
62 * @param param
63 * - a parameter instance with data for the command execution
64 * @param eventNames
65 * - list of event names
66 * @param isKernel
67 * - true if kernel domain else false
68 * @param filterExpression
69 * - a filter expression
70 * @param monitor
71 * - a progress monitor
72 * @throws ExecutionException
73 * If the command fails for some reason
74 */
75 public abstract void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
76
77 /**
78 * Enables all syscall events.
79 *
80 * @param param
81 * - a parameter instance with data for the command execution
82 * @param monitor
83 * - a progress monitor
84 * @throws ExecutionException
85 * If the command fails for some reason
86 */
87 public abstract void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
88
89 /**
90 * Enables a dynamic probe.
91 *
92 * @param param
93 * - a parameter instance with data for the command execution
94 * @param eventName
95 * - a event name
96 * @param isFunction
97 * - true for dynamic function entry/return probe else false
98 * @param probe
99 * - a dynamic probe information
100 * @param monitor
101 * - a progress monitor
102 * @throws ExecutionException
103 * If the command fails for some reason
104 */
105 public abstract void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
106
107 /**
108 * Enables events using log level
109 *
110 * @param param
111 * - a parameter instance with data for the command execution
112 * @param eventName
113 * - a event name
114 * @param logLevelType
115 * - a log level type
116 * @param level
117 * - a log level
118 * @param filterExpression
119 * - a filter expression
120 * @param monitor
121 * - a progress monitor
122 * @throws ExecutionException
123 * If the command fails for some reason
124 */
125 public abstract void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
126
127 /**
128 * @param param
129 * - a parameter instance with data for the command execution
130 * @return returns the relevant domain (null if domain is not known)
131 */
132 public abstract TraceDomainComponent getDomain(CommandParameter param);
133
134 @Override
135 public Object execute(ExecutionEvent event) throws ExecutionException {
136
137 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
138
139 if (window == null) {
140 return false;
141 }
142
143 // Make a copy for thread safety
144 CommandParameter tmpParam = null;
145 fLock.lock();
146 try {
147 tmpParam = fParam;
148 if (tmpParam == null) {
149 return null;
150 }
151 tmpParam = tmpParam.clone();
152 } finally {
153 fLock.unlock();
154 }
155 final CommandParameter param = tmpParam;
156
157 TargetNodeComponent node = param.getSession().getTargetNode();
158 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
159
160 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
161 dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
162 dialog.setTraceDomainComponent(getDomain(param));
163
164 if (dialog.open() != Window.OK) {
165 return null;
166 }
167
168 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
169 @Override
170 protected IStatus run(IProgressMonitor monitor) {
171 Exception error = null;
172
173 try {
174 String filter = dialog.getFilterExpression();
175
176 // Enable tracepoint events
177 if (dialog.isTracepoints()) {
178 if (dialog.isAllTracePoints()) {
179 enableEvents(param, null, dialog.isKernel(), filter, monitor);
180 } else {
181 List<String> eventNames = dialog.getEventNames();
182 if (!eventNames.isEmpty()) {
183 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
184 }
185 }
186 }
187
188 // Enable syscall events
189 if (dialog.isAllSysCalls()) {
190 enableSyscalls(param, monitor);
191 }
192
193 // Enable dynamic probe
194 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
195 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
196 }
197
198 // Enable dynamic function probe
199 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
200 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
201 }
202
203 // Enable event using a wildcard
204 if (dialog.isWildcard()) {
205 List<String> eventNames = dialog.getEventNames();
206 eventNames.add(dialog.getWildcard());
207
208 if (!eventNames.isEmpty()) {
209 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
210 }
211 }
212
213 // Enable events using log level
214 if (dialog.isLogLevel()) {
215 enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), filter, monitor);
216 }
217
218 } catch (ExecutionException e) {
219 error = e;
220 }
221
222 // refresh in all cases
223 refresh(param);
224
225 if (error != null) {
226 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
227 }
228 return Status.OK_STATUS;
229 }
230 };
231 job.setUser(true);
232 job.schedule();
233 return null;
234 }
235 }
This page took 0.046991 seconds and 4 git commands to generate.