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