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
.lttng
.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
.lttng
.ui
.LTTngUiPlugin
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.EnableEventsDialog
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.IEnableEventsDialog
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.LogLevelType
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceLogLevel
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
32 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceProviderGroup
;
33 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
35 import org
.eclipse
.ui
.PlatformUI
;
38 * <b><u>EnableEventOnSessionHandler</u></b>
40 * Base command handler implementation to enable events.
43 abstract public class BaseEnableEventHandler
extends BaseControlViewHandler
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * The session component the command is to be executed on.
51 protected TraceSessionComponent fSession
= null;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 * Enables a list of events for given parameters.
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(List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
;
65 * Enables all syscall events.
66 * @param monitor - a progress monitor
67 * @throws ExecutionException
69 abstract public void enableSyscalls(IProgressMonitor monitor
) throws ExecutionException
;
72 * Enables a dynamic probe.
73 * @param eventName - a event name
74 * @param probe - a dynamic probe information
75 * @param monitor - a progress monitor
76 * @throws ExecutionException
78 abstract public void enableProbe(String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
81 * Enables a dynamic function entry/return probe.
82 * @param eventName - a event name
83 * @param function - a dynamic function entry/return probe information
84 * @param monitor - a progress monitor
85 * @throws ExecutionException
87 abstract public void enableFunctionProbe(String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
90 * Enables events using log level
91 * @param eventName - a event name
92 * @param logLevelType - a log level type
93 * @param level - a log level
94 * @param monitor - a progress monitor
95 * @throws ExecutionException
97 abstract public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
;
100 * @return returns the relevant domain (null if domain is not known)
102 abstract TraceDomainComponent
getDomain();
106 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
109 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
111 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
113 if (window
== null) {
117 TargetNodeComponent node
= fSession
.getTargetNode();
118 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
120 final IEnableEventsDialog dialog
= new EnableEventsDialog(window
.getShell(), (TraceProviderGroup
)providers
.get(0), getDomain());
122 if (dialog
.open() != Window
.OK
) {
126 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
128 protected IStatus
run(IProgressMonitor monitor
) {
129 String errorString
= null;
132 // Enable tracepoint events
133 if (dialog
.isTracepoints()) {
134 if (dialog
.isAllTracePoints()) {
135 enableEvents(null, dialog
.isKernel(), monitor
);
137 List
<String
> eventNames
= dialog
.getEventNames();
138 if (eventNames
.size() > 0) {
139 enableEvents(eventNames
, dialog
.isKernel(), monitor
);
144 // Enable syscall events
145 if (dialog
.isAllSysCalls()) {
146 if (dialog
.isAllSysCalls()) {
147 enableSyscalls(monitor
);
151 // Enable dynamic probe
152 if (dialog
.isDynamicProbe()) {
153 if ((dialog
.getProbeEventName() != null && dialog
.getProbeName() != null)) {
154 enableProbe(dialog
.getProbeEventName(), dialog
.getProbeName(), monitor
);
158 // Enable dynamic function probe
159 if (dialog
.isDynamicFunctionProbe()) {
160 if ((dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
161 enableFunctionProbe(dialog
.getFunctionEventName(), dialog
.getFunction(), monitor
);
165 // Enable event using a wildcard
166 if (dialog
.isWildcard()) {
167 List
<String
> eventNames
= dialog
.getEventNames();
168 eventNames
.add(dialog
.getWildcard());
170 if (eventNames
.size() > 0) {
171 enableEvents(eventNames
, dialog
.isKernel(), monitor
);
175 // Enable events using log level
176 if (dialog
.isLogLevel()) {
177 enableLogLevel(dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), monitor
);
180 } catch (ExecutionException e
) {
181 if (errorString
== null) {
182 errorString
= new String();
184 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
187 // get session configuration in all cases
189 fSession
.getConfigurationFromNode(monitor
);
190 } catch (ExecutionException e
) {
191 if (errorString
== null) {
192 errorString
= new String();
194 errorString
+= Messages
.TraceControl_ListSessionFailure
+ ": " + e
.toString(); //$NON-NLS-1$
197 if (errorString
!= null) {
198 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, errorString
);
200 return Status
.OK_STATUS
;