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; | |
33 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; | |
498704b3 BH |
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 | |
d132bcc7 | 74 | * @param isFunction - true for dynamic function entry/return probe else false |
ccc66d01 BH |
75 | * @param probe - a dynamic probe information |
76 | * @param monitor - a progress monitor | |
77 | * @throws ExecutionException | |
78 | */ | |
d132bcc7 | 79 | abstract public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException; |
498704b3 | 80 | |
ccc66d01 BH |
81 | /** |
82 | * Enables events using log level | |
83 | * @param eventName - a event name | |
84 | * @param logLevelType - a log level type | |
85 | * @param level - a log level | |
86 | * @param monitor - a progress monitor | |
87 | * @throws ExecutionException | |
88 | */ | |
89 | abstract public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException; | |
498704b3 | 90 | |
ccc66d01 BH |
91 | /** |
92 | * @return returns the relevant domain (null if domain is not known) | |
93 | */ | |
94 | abstract TraceDomainComponent getDomain(); | |
95 | ||
498704b3 BH |
96 | /* |
97 | * (non-Javadoc) | |
98 | * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) | |
99 | */ | |
100 | @Override | |
101 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
102 | ||
103 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
104 | ||
105 | if (window == null) { | |
106 | return false; | |
107 | } | |
108 | ||
109 | TargetNodeComponent node = fSession.getTargetNode(); | |
110 | List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class); | |
d132bcc7 BH |
111 | |
112 | final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog(); | |
113 | dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0)); | |
114 | dialog.setTraceDomainComponent(getDomain()); | |
115 | ||
498704b3 BH |
116 | if (dialog.open() != Window.OK) { |
117 | return null; | |
118 | } | |
119 | ||
120 | Job job = new Job(Messages.TraceControl_ChangeEventStateJob) { | |
121 | @Override | |
122 | protected IStatus run(IProgressMonitor monitor) { | |
123 | String errorString = null; | |
124 | ||
498704b3 | 125 | try { |
ccc66d01 BH |
126 | // Enable tracepoint events |
127 | if (dialog.isTracepoints()) { | |
128 | if (dialog.isAllTracePoints()) { | |
129 | enableEvents(null, dialog.isKernel(), monitor); | |
130 | } else { | |
131 | List<String> eventNames = dialog.getEventNames(); | |
132 | if (eventNames.size() > 0) { | |
133 | enableEvents(eventNames, dialog.isKernel(), monitor); | |
134 | } | |
135 | } | |
136 | } | |
137 | ||
138 | // Enable syscall events | |
139 | if (dialog.isAllSysCalls()) { | |
140 | if (dialog.isAllSysCalls()) { | |
141 | enableSyscalls(monitor); | |
142 | } | |
143 | } | |
144 | ||
145 | // Enable dynamic probe | |
146 | if (dialog.isDynamicProbe()) { | |
147 | if ((dialog.getProbeEventName() != null && dialog.getProbeName() != null)) { | |
d132bcc7 | 148 | enableProbe(dialog.getProbeEventName(), false, dialog.getProbeName(), monitor); |
ccc66d01 BH |
149 | } |
150 | } | |
151 | ||
152 | // Enable dynamic function probe | |
153 | if (dialog.isDynamicFunctionProbe()) { | |
154 | if ((dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) { | |
d132bcc7 | 155 | enableProbe(dialog.getFunctionEventName(), true, dialog.getFunction(), monitor); |
ccc66d01 BH |
156 | } |
157 | } | |
158 | ||
159 | // Enable event using a wildcard | |
160 | if (dialog.isWildcard()) { | |
498704b3 | 161 | List<String> eventNames = dialog.getEventNames(); |
ccc66d01 BH |
162 | eventNames.add(dialog.getWildcard()); |
163 | ||
498704b3 | 164 | if (eventNames.size() > 0) { |
ccc66d01 | 165 | enableEvents(eventNames, dialog.isKernel(), monitor); |
498704b3 BH |
166 | } |
167 | } | |
ccc66d01 BH |
168 | |
169 | // Enable events using log level | |
170 | if (dialog.isLogLevel()) { | |
171 | enableLogLevel(dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), monitor); | |
172 | } | |
498704b3 | 173 | |
498704b3 BH |
174 | } catch (ExecutionException e) { |
175 | if (errorString == null) { | |
176 | errorString = new String(); | |
177 | } | |
178 | errorString += e.toString() + "\n"; //$NON-NLS-1$ | |
179 | } | |
180 | ||
181 | // get session configuration in all cases | |
182 | try { | |
183 | fSession.getConfigurationFromNode(monitor); | |
184 | } catch (ExecutionException e) { | |
185 | if (errorString == null) { | |
186 | errorString = new String(); | |
187 | } | |
188 | errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString(); //$NON-NLS-1$ | |
189 | } | |
190 | ||
191 | if (errorString != null) { | |
31a6a4e4 | 192 | return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString); |
498704b3 BH |
193 | } |
194 | return Status.OK_STATUS; | |
195 | } | |
196 | }; | |
197 | job.setUser(true); | |
198 | job.schedule(); | |
199 | ||
200 | return null; | |
201 | } | |
202 | } |