1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.handlers
;
14 import java
.util
.List
;
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
;
38 * Base command handler implementation to enable events.
41 * @author Bernd Hufmann
43 abstract public class BaseEnableEventHandler
extends BaseControlViewHandler
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * The command execution parameter.
51 protected CommandParameter fParam
= null;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * Enables a list of events for given parameters.
61 * - a parameter instance with data for the command execution
63 * - list of event names
65 * - true if kernel domain else false
67 * - a progress monitor
68 * @throws ExecutionException
69 * If the command fails for some reason
71 abstract public void enableEvents(CommandParameter param
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
;
74 * Enables all syscall events.
77 * - a parameter instance with data for the command execution
79 * - a progress monitor
80 * @throws ExecutionException
81 * If the command fails for some reason
83 abstract public void enableSyscalls(CommandParameter param
, IProgressMonitor monitor
) throws ExecutionException
;
86 * Enables a dynamic probe.
89 * - a parameter instance with data for the command execution
93 * - true for dynamic function entry/return probe else false
95 * - a dynamic probe information
97 * - a progress monitor
98 * @throws ExecutionException
99 * If the command fails for some reason
101 abstract public void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
104 * Enables events using log level
107 * - a parameter instance with data for the command execution
110 * @param logLevelType
115 * - a progress monitor
116 * @throws ExecutionException
117 * If the command fails for some reason
119 abstract public void enableLogLevel(CommandParameter param
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
;
123 * - a parameter instance with data for the command execution
124 * @return returns the relevant domain (null if domain is not known)
126 abstract TraceDomainComponent
getDomain(CommandParameter param
);
130 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
133 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
135 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
137 if (window
== null) {
142 // Make a copy for thread safety
143 final CommandParameter param
= fParam
.clone();
145 TargetNodeComponent node
= param
.getSession().getTargetNode();
146 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
148 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
149 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
150 dialog
.setTraceDomainComponent(getDomain(param
));
152 if (dialog
.open() != Window
.OK
) {
156 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
158 protected IStatus
run(IProgressMonitor monitor
) {
159 Exception error
= null;
162 // Enable tracepoint events
163 if (dialog
.isTracepoints()) {
164 if (dialog
.isAllTracePoints()) {
165 enableEvents(param
, null, dialog
.isKernel(), monitor
);
167 List
<String
> eventNames
= dialog
.getEventNames();
168 if (!eventNames
.isEmpty()) {
169 enableEvents(param
, eventNames
, dialog
.isKernel(), monitor
);
174 // Enable syscall events
175 if (dialog
.isAllSysCalls()) {
176 enableSyscalls(param
, monitor
);
179 // Enable dynamic probe
180 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
181 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
184 // Enable dynamic function probe
185 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
186 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
189 // Enable event using a wildcard
190 if (dialog
.isWildcard()) {
191 List
<String
> eventNames
= dialog
.getEventNames();
192 eventNames
.add(dialog
.getWildcard());
194 if (!eventNames
.isEmpty()) {
195 enableEvents(param
, eventNames
, dialog
.isKernel(), monitor
);
199 // Enable events using log level
200 if (dialog
.isLogLevel()) {
201 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), monitor
);
204 } catch (ExecutionException e
) {
208 // refresh in all cases
212 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
214 return Status
.OK_STATUS
;