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