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
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.IEnableEventsDialog
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.LogLevelType
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
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
;
37 * <b><u>EnableEventOnSessionHandler</u></b>
39 * Base command handler implementation to enable events.
42 abstract public class BaseEnableEventHandler
extends BaseControlViewHandler
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * The command execution parameter.
50 protected CommandParameter fParam
= null;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 * Enables a list of events for given parameters.
57 * @param - a parameter instance with data for the command execution
58 * @param eventNames - list of event names
59 * @param isKernel - true if kernel domain else false
60 * @param monitor - a progress monitor
61 * @throws ExecutionException
63 abstract public void enableEvents(CommandParameter param
, List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
;
66 * Enables all syscall events.
67 * @param - a parameter instance with data for the command execution
68 * @param monitor - a progress monitor
69 * @throws ExecutionException
71 abstract public void enableSyscalls(CommandParameter param
, IProgressMonitor monitor
) throws ExecutionException
;
74 * Enables a dynamic probe.
75 * @param - a parameter instance with data for the command execution
76 * @param eventName - a event name
77 * @param isFunction - true for dynamic function entry/return probe else false
78 * @param probe - a dynamic probe information
79 * @param monitor - a progress monitor
80 * @throws ExecutionException
82 abstract public void enableProbe(CommandParameter param
, String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
85 * Enables events using log level
86 * @param - a parameter instance with data for the command execution
87 * @param eventName - a event name
88 * @param logLevelType - a log level type
89 * @param level - a log level
90 * @param monitor - a progress monitor
91 * @throws ExecutionException
93 abstract public void enableLogLevel(CommandParameter param
, String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
;
96 * @param - a parameter instance with data for the command execution
97 * @return returns the relevant domain (null if domain is not known)
99 abstract TraceDomainComponent
getDomain(CommandParameter param
);
103 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
106 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
108 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
110 if (window
== null) {
115 // Make a copy for thread safety
116 final CommandParameter param
= fParam
.clone();
118 TargetNodeComponent node
= param
.getSession().getTargetNode();
119 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
121 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
122 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
123 dialog
.setTraceDomainComponent(getDomain(param
));
125 if (dialog
.open() != Window
.OK
) {
129 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
131 protected IStatus
run(IProgressMonitor monitor
) {
132 StringBuffer errorString
= new StringBuffer();
135 // Enable tracepoint events
136 if (dialog
.isTracepoints()) {
137 if (dialog
.isAllTracePoints()) {
138 enableEvents(param
, null, dialog
.isKernel(), monitor
);
140 List
<String
> eventNames
= dialog
.getEventNames();
141 if (!eventNames
.isEmpty()) {
142 enableEvents(param
, eventNames
, dialog
.isKernel(), monitor
);
147 // Enable syscall events
148 if (dialog
.isAllSysCalls()) {
149 enableSyscalls(param
, monitor
);
152 // Enable dynamic probe
153 if (dialog
.isDynamicProbe() && (dialog
.getProbeEventName() != null) && (dialog
.getProbeName() != null)) {
154 enableProbe(param
, dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
157 // Enable dynamic function probe
158 if (dialog
.isDynamicFunctionProbe() && (dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
159 enableProbe(param
, dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
162 // Enable event using a wildcard
163 if (dialog
.isWildcard()) {
164 List
<String
> eventNames
= dialog
.getEventNames();
165 eventNames
.add(dialog
.getWildcard());
167 if (!eventNames
.isEmpty()) {
168 enableEvents(param
, eventNames
, dialog
.isKernel(), monitor
);
172 // Enable events using log level
173 if (dialog
.isLogLevel()) {
174 enableLogLevel(param
, dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), monitor
);
177 } catch (ExecutionException e
) {
178 errorString
.append(e
.toString());
179 errorString
.append('\n');
182 // get session configuration in all cases
184 param
.getSession().getConfigurationFromNode(monitor
);
185 } catch (ExecutionException e
) {
186 errorString
.append(Messages
.TraceControl_ListSessionFailure
);
187 errorString
.append(": "); //$NON-NLS-1$
188 errorString
.append(e
.toString());
191 if (errorString
.length() > 0) {
192 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, errorString
.toString());
194 return Status
.OK_STATUS
;