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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.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.lttng.ui.LTTngUiPlugin; | |
24 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; | |
ccc66d01 BH |
25 | import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.EnableEventsDialog; |
26 | import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableEventsDialog; | |
498704b3 | 27 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; |
ccc66d01 BH |
28 | import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType; |
29 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; | |
498704b3 | 30 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent; |
ccc66d01 | 31 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceDomainComponent; |
498704b3 BH |
32 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceProviderGroup; |
33 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent; | |
34 | import org.eclipse.ui.IWorkbenchWindow; | |
35 | import org.eclipse.ui.PlatformUI; | |
36 | ||
37 | /** | |
38 | * <b><u>EnableEventOnSessionHandler</u></b> | |
39 | * <p> | |
ccc66d01 | 40 | * Base command handler implementation to enable events. |
498704b3 BH |
41 | * </p> |
42 | */ | |
43 | abstract public class BaseEnableEventHandler extends BaseControlViewHandler { | |
44 | ||
45 | // ------------------------------------------------------------------------ | |
46 | // Attributes | |
47 | // ------------------------------------------------------------------------ | |
48 | /** | |
49 | * The session component the command is to be executed on. | |
50 | */ | |
51 | protected TraceSessionComponent fSession = null; | |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Operations | |
55 | // ------------------------------------------------------------------------ | |
ccc66d01 BH |
56 | /** |
57 | * Enables a list of events for given parameters. | |
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 | */ | |
63 | abstract public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException; | |
64 | /** | |
65 | * Enables all syscall events. | |
66 | * @param monitor - a progress monitor | |
67 | * @throws ExecutionException | |
68 | */ | |
69 | abstract public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException; | |
70 | ||
71 | /** | |
72 | * Enables a dynamic probe. | |
73 | * @param eventName - a event name | |
74 | * @param probe - a dynamic probe information | |
75 | * @param monitor - a progress monitor | |
76 | * @throws ExecutionException | |
77 | */ | |
78 | abstract public void enableProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException; | |
498704b3 | 79 | |
ccc66d01 BH |
80 | /** |
81 | * Enables a dynamic function entry/return probe. | |
82 | * @param eventName - a event name | |
83 | * @param function - a dynamic function entry/return probe information | |
84 | * @param monitor - a progress monitor | |
85 | * @throws ExecutionException | |
86 | */ | |
87 | abstract public void enableFunctionProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException; | |
88 | ||
89 | /** | |
90 | * Enables events using log level | |
91 | * @param eventName - a event name | |
92 | * @param logLevelType - a log level type | |
93 | * @param level - a log level | |
94 | * @param monitor - a progress monitor | |
95 | * @throws ExecutionException | |
96 | */ | |
97 | abstract public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException; | |
498704b3 | 98 | |
ccc66d01 BH |
99 | /** |
100 | * @return returns the relevant domain (null if domain is not known) | |
101 | */ | |
102 | abstract TraceDomainComponent getDomain(); | |
103 | ||
498704b3 BH |
104 | /* |
105 | * (non-Javadoc) | |
106 | * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) | |
107 | */ | |
108 | @Override | |
109 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
110 | ||
111 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
112 | ||
113 | if (window == null) { | |
114 | return false; | |
115 | } | |
116 | ||
117 | TargetNodeComponent node = fSession.getTargetNode(); | |
118 | List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class); | |
ccc66d01 BH |
119 | |
120 | final IEnableEventsDialog dialog = new EnableEventsDialog(window.getShell(), (TraceProviderGroup)providers.get(0), getDomain()); | |
121 | ||
498704b3 BH |
122 | if (dialog.open() != Window.OK) { |
123 | return null; | |
124 | } | |
125 | ||
126 | Job job = new Job(Messages.TraceControl_ChangeEventStateJob) { | |
127 | @Override | |
128 | protected IStatus run(IProgressMonitor monitor) { | |
129 | String errorString = null; | |
130 | ||
498704b3 | 131 | try { |
ccc66d01 BH |
132 | // Enable tracepoint events |
133 | if (dialog.isTracepoints()) { | |
134 | if (dialog.isAllTracePoints()) { | |
135 | enableEvents(null, dialog.isKernel(), monitor); | |
136 | } else { | |
137 | List<String> eventNames = dialog.getEventNames(); | |
138 | if (eventNames.size() > 0) { | |
139 | enableEvents(eventNames, dialog.isKernel(), monitor); | |
140 | } | |
141 | } | |
142 | } | |
143 | ||
144 | // Enable syscall events | |
145 | if (dialog.isAllSysCalls()) { | |
146 | if (dialog.isAllSysCalls()) { | |
147 | enableSyscalls(monitor); | |
148 | } | |
149 | } | |
150 | ||
151 | // Enable dynamic probe | |
152 | if (dialog.isDynamicProbe()) { | |
153 | if ((dialog.getProbeEventName() != null && dialog.getProbeName() != null)) { | |
154 | enableProbe(dialog.getProbeEventName(), dialog.getProbeName(), monitor); | |
155 | } | |
156 | } | |
157 | ||
158 | // Enable dynamic function probe | |
159 | if (dialog.isDynamicFunctionProbe()) { | |
160 | if ((dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) { | |
161 | enableFunctionProbe(dialog.getFunctionEventName(), dialog.getFunction(), monitor); | |
162 | } | |
163 | } | |
164 | ||
165 | // Enable event using a wildcard | |
166 | if (dialog.isWildcard()) { | |
498704b3 | 167 | List<String> eventNames = dialog.getEventNames(); |
ccc66d01 BH |
168 | eventNames.add(dialog.getWildcard()); |
169 | ||
498704b3 | 170 | if (eventNames.size() > 0) { |
ccc66d01 | 171 | enableEvents(eventNames, dialog.isKernel(), monitor); |
498704b3 BH |
172 | } |
173 | } | |
ccc66d01 BH |
174 | |
175 | // Enable events using log level | |
176 | if (dialog.isLogLevel()) { | |
177 | enableLogLevel(dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), monitor); | |
178 | } | |
498704b3 | 179 | |
498704b3 BH |
180 | } catch (ExecutionException e) { |
181 | if (errorString == null) { | |
182 | errorString = new String(); | |
183 | } | |
184 | errorString += e.toString() + "\n"; //$NON-NLS-1$ | |
185 | } | |
186 | ||
187 | // get session configuration in all cases | |
188 | try { | |
189 | fSession.getConfigurationFromNode(monitor); | |
190 | } catch (ExecutionException e) { | |
191 | if (errorString == null) { | |
192 | errorString = new String(); | |
193 | } | |
194 | errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString(); //$NON-NLS-1$ | |
195 | } | |
196 | ||
197 | if (errorString != null) { | |
198 | return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, errorString); | |
199 | } | |
200 | return Status.OK_STATUS; | |
201 | } | |
202 | }; | |
203 | job.setUser(true); | |
204 | job.schedule(); | |
205 | ||
206 | return null; | |
207 | } | |
208 | } |