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
66 * @param filterExpression
67 * - a filter expression
69 * - a progress monitor
70 * @throws ExecutionException
71 * If the command fails for some reason
73 abstract public void enableEvents(CommandParameter param
, List
<String
> eventNames
, boolean isKernel
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
76 * Enables all syscall events.
79 * - a parameter instance with data for the command execution
81 * - a progress monitor
82 * @throws ExecutionException
83 * If the command fails for some reason
85 abstract public void enableSyscalls(CommandParameter param
, IProgressMonitor monitor
) throws ExecutionException
;
88 * Enables a dynamic probe.
91 * - a parameter instance with data for the command execution
95 * - true for dynamic function entry/return probe else false
97 * - a dynamic probe information
99 * - a progress monitor
100 * @throws ExecutionException
101 * If the command fails for some reason
103 abstract public void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
106 * Enables events using log level
109 * - a parameter instance with data for the command execution
112 * @param logLevelType
116 * @param filterExpression
117 * - a filter expression
119 * - a progress monitor
120 * @throws ExecutionException
121 * If the command fails for some reason
123 abstract public void enableLogLevel(CommandParameter param
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
;
127 * - a parameter instance with data for the command execution
128 * @return returns the relevant domain (null if domain is not known)
130 abstract TraceDomainComponent
getDomain(CommandParameter param
);
134 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
137 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
139 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
141 if (window
== null) {
146 // Make a copy for thread safety
147 final CommandParameter param
= fParam
.clone();
149 TargetNodeComponent node
= param
.getSession().getTargetNode();
150 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
152 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
153 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
154 dialog
.setTraceDomainComponent(getDomain(param
));
156 if (dialog
.open() != Window
.OK
) {
160 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
162 protected IStatus
run(IProgressMonitor monitor
) {
163 Exception error
= null;
166 String filter
= dialog
.getFilterExpression();
168 // Enable tracepoint events
169 if (dialog
.isTracepoints()) {
170 if (dialog
.isAllTracePoints()) {
171 enableEvents(param
, null, dialog
.isKernel(), filter
, monitor
);
173 List
<String
> eventNames
= dialog
.getEventNames();
174 if (!eventNames
.isEmpty()) {
175 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
180 // Enable syscall events
181 if (dialog
.isAllSysCalls()) {
182 enableSyscalls(param
, monitor
);
185 // Enable dynamic probe
186 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
187 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
190 // Enable dynamic function probe
191 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
192 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
195 // Enable event using a wildcard
196 if (dialog
.isWildcard()) {
197 List
<String
> eventNames
= dialog
.getEventNames();
198 eventNames
.add(dialog
.getWildcard());
200 if (!eventNames
.isEmpty()) {
201 enableEvents(param
, eventNames
, dialog
.isKernel(), filter
, monitor
);
205 // Enable events using log level
206 if (dialog
.isLogLevel()) {
207 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), filter
, monitor
);
210 } catch (ExecutionException e
) {
214 // refresh in all cases
218 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
220 return Status
.OK_STATUS
;