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
.ui
.views
.control
.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
.core
.control
.model
.LogLevelType
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.IEnableEventsDialog
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.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 abstract public 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 abstract public 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 abstract public 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 abstract public 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 abstract public 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 abstract TraceDomainComponent
getDomain(CommandParameter param
);
135 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
138 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
140 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
142 if (window
== null) {
147 // Make a copy for thread safety
148 final CommandParameter param
= fParam
.clone();
150 TargetNodeComponent node
= param
.getSession().getTargetNode();
151 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
153 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
154 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
155 dialog
.setTraceDomainComponent(getDomain(param
));
157 if (dialog
.open() != Window
.OK
) {
161 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
163 protected IStatus
run(IProgressMonitor monitor
) {
164 Exception error
= null;
167 String filter
= dialog
.getFilterExpression();
169 // Enable tracepoint events
170 if (dialog
.isTracepoints()) {
171 if (dialog
.isAllTracePoints()) {
172 enableEvents(param
, null, dialog
.isKernel(), filter
, monitor
);
174 List
<String
> eventNames
= dialog
.getEventNames();
175 if (!eventNames
.isEmpty()) {
176 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
181 // Enable syscall events
182 if (dialog
.isAllSysCalls()) {
183 enableSyscalls(param
, monitor
);
186 // Enable dynamic probe
187 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
188 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
191 // Enable dynamic function probe
192 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
193 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
196 // Enable event using a wildcard
197 if (dialog
.isWildcard()) {
198 List
<String
> eventNames
= dialog
.getEventNames();
199 eventNames
.add(dialog
.getWildcard());
201 if (!eventNames
.isEmpty()) {
202 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
206 // Enable events using log level
207 if (dialog
.isLogLevel()) {
208 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, monitor
);
211 } catch (ExecutionException e
) {
215 // refresh in all cases
219 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
221 return Status
.OK_STATUS
;