lttng: Fix Javadoc and formatting in lttng2.ui
[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 monitor
67 * - a progress monitor
68 * @throws ExecutionException
69 * If the command fails for some reason
70 */
71 abstract public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException;
72
73 /**
74 * Enables all syscall events.
75 *
76 * @param param
77 * - a parameter instance with data for the command execution
78 * @param monitor
79 * - a progress monitor
80 * @throws ExecutionException
81 * If the command fails for some reason
82 */
83 abstract public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
84
85 /**
86 * Enables a dynamic probe.
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
98 * @throws ExecutionException
99 * If the command fails for some reason
100 */
101 abstract public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
102
103 /**
104 * Enables events using log level
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
116 * @throws ExecutionException
117 * If the command fails for some reason
118 */
119 abstract public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException;
120
121 /**
122 * @param param
123 * - a parameter instance with data for the command execution
124 * @return returns the relevant domain (null if domain is not known)
125 */
126 abstract TraceDomainComponent getDomain(CommandParameter param);
127
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 }
140 fLock.lock();
141 try {
142 // Make a copy for thread safety
143 final CommandParameter param = fParam.clone();
144
145 TargetNodeComponent node = param.getSession().getTargetNode();
146 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
147
148 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
149 dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
150 dialog.setTraceDomainComponent(getDomain(param));
151
152 if (dialog.open() != Window.OK) {
153 return null;
154 }
155
156 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
157 @Override
158 protected IStatus run(IProgressMonitor monitor) {
159 Exception error = null;
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 }
171 }
172 }
173
174 // Enable syscall events
175 if (dialog.isAllSysCalls()) {
176 enableSyscalls(param, monitor);
177 }
178
179 // Enable dynamic probe
180 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
181 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
182 }
183
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 }
188
189 // Enable event using a wildcard
190 if (dialog.isWildcard()) {
191 List<String> eventNames = dialog.getEventNames();
192 eventNames.add(dialog.getWildcard());
193
194 if (!eventNames.isEmpty()) {
195 enableEvents(param, eventNames, dialog.isKernel(), monitor);
196 }
197 }
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) {
205 error = e;
206 }
207
208 // refresh in all cases
209 refresh(param);
210
211 if (error != null) {
212 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
213 }
214 return Status.OK_STATUS;
215 }
216 };
217 job.setUser(true);
218 job.schedule();
219 } finally {
220 fLock.unlock();
221 }
222 return null;
223 }
224 }
This page took 0.035453 seconds and 5 git commands to generate.