1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.handlers
;
15 import java
.util
.List
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.core
.runtime
.jobs
.Job
;
23 import org
.eclipse
.jface
.window
.Window
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.LogLevelType
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceLogLevel
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.Activator
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.IEnableEventsDialog
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceProviderGroup
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
35 import org
.eclipse
.ui
.PlatformUI
;
39 * Base command handler implementation to enable events.
42 * @author Bernd Hufmann
44 public abstract class BaseEnableEventHandler
extends BaseControlViewHandler
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * The command execution parameter.
52 protected CommandParameter fParam
= null;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
59 * Enables a list of events for given parameters.
62 * - a parameter instance with data for the command execution
64 * - list of event names
66 * - true if kernel domain else false
67 * @param filterExpression
68 * - a filter expression
70 * - a progress monitor
71 * @throws ExecutionException
72 * If the command fails for some reason
74 public abstract void enableEvents(CommandParameter param
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
77 * Enables all syscall events.
80 * - a parameter instance with data for the command execution
82 * - a progress monitor
83 * @throws ExecutionException
84 * If the command fails for some reason
86 public abstract void enableSyscalls(CommandParameter param
, IProgressMonitor monitor
) throws ExecutionException
;
89 * Enables a dynamic probe.
92 * - a parameter instance with data for the command execution
96 * - true for dynamic function entry/return probe else false
98 * - a dynamic probe information
100 * - a progress monitor
101 * @throws ExecutionException
102 * If the command fails for some reason
104 public abstract void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
107 * Enables events using log level
110 * - a parameter instance with data for the command execution
113 * @param logLevelType
117 * @param filterExpression
118 * - a filter expression
120 * - a progress monitor
121 * @throws ExecutionException
122 * If the command fails for some reason
124 public abstract void enableLogLevel(CommandParameter param
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
128 * - a parameter instance with data for the command execution
129 * @return returns the relevant domain (null if domain is not known)
131 public abstract TraceDomainComponent
getDomain(CommandParameter param
);
134 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
136 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
138 if (window
== null) {
143 // Make a copy for thread safety
144 final CommandParameter param
= fParam
.clone();
146 TargetNodeComponent node
= param
.getSession().getTargetNode();
147 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
149 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
150 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
151 dialog
.setTraceDomainComponent(getDomain(param
));
153 if (dialog
.open() != Window
.OK
) {
157 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
159 protected IStatus
run(IProgressMonitor monitor
) {
160 Exception error
= null;
163 String filter
= dialog
.getFilterExpression();
165 // Enable tracepoint events
166 if (dialog
.isTracepoints()) {
167 if (dialog
.isAllTracePoints()) {
168 enableEvents(param
, null, dialog
.isKernel(), filter
, monitor
);
170 List
<String
> eventNames
= dialog
.getEventNames();
171 if (!eventNames
.isEmpty()) {
172 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
177 // Enable syscall events
178 if (dialog
.isAllSysCalls()) {
179 enableSyscalls(param
, monitor
);
182 // Enable dynamic probe
183 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
184 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
187 // Enable dynamic function probe
188 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
189 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
192 // Enable event using a wildcard
193 if (dialog
.isWildcard()) {
194 List
<String
> eventNames
= dialog
.getEventNames();
195 eventNames
.add(dialog
.getWildcard());
197 if (!eventNames
.isEmpty()) {
198 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
202 // Enable events using log level
203 if (dialog
.isLogLevel()) {
204 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, monitor
);
207 } catch (ExecutionException e
) {
211 // refresh in all cases
215 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
217 return Status
.OK_STATUS
;