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