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 // ------------------------------------------------------------------------
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
64 abstract public void enableEvents(CommandParameter param
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
;
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
72 abstract public void enableSyscalls(CommandParameter param
, IProgressMonitor monitor
) throws ExecutionException
;
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
83 abstract public void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
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
94 abstract public void enableLogLevel(CommandParameter param
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
;
97 * @param - a parameter instance with data for the command execution
98 * @return returns the relevant domain (null if domain is not known)
100 abstract TraceDomainComponent
getDomain(CommandParameter param
);
104 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
107 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
109 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
111 if (window
== null) {
116 // Make a copy for thread safety
117 final CommandParameter param
= fParam
.clone();
119 TargetNodeComponent node
= param
.getSession().getTargetNode();
120 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
122 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
123 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
124 dialog
.setTraceDomainComponent(getDomain(param
));
126 if (dialog
.open() != Window
.OK
) {
130 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
132 protected IStatus
run(IProgressMonitor monitor
) {
133 Exception error
= null;
136 // Enable tracepoint events
137 if (dialog
.isTracepoints()) {
138 if (dialog
.isAllTracePoints()) {
139 enableEvents(param
, null, dialog
.isKernel(), monitor
);
141 List
<String
> eventNames
= dialog
.getEventNames();
142 if (!eventNames
.isEmpty()) {
143 enableEvents(param
, eventNames
, dialog
.isKernel(), monitor
);
148 // Enable syscall events
149 if (dialog
.isAllSysCalls()) {
150 enableSyscalls(param
, monitor
);
153 // Enable dynamic probe
154 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
155 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
158 // Enable dynamic function probe
159 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
160 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
163 // Enable event using a wildcard
164 if (dialog
.isWildcard()) {
165 List
<String
> eventNames
= dialog
.getEventNames();
166 eventNames
.add(dialog
.getWildcard());
168 if (!eventNames
.isEmpty()) {
169 enableEvents(param
, eventNames
, dialog
.isKernel(), monitor
);
173 // Enable events using log level
174 if (dialog
.isLogLevel()) {
175 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), monitor
);
178 } catch (ExecutionException e
) {
182 // refresh in all cases
186 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ChangeEventStateFailure
, error
);
188 return Status
.OK_STATUS
;