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