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
.linuxtools
.internal
.lttng2
.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 isFunction - true for dynamic function entry/return probe else false
75 * @param probe - a dynamic probe information
76 * @param monitor - a progress monitor
77 * @throws ExecutionException
79 abstract public void enableProbe(String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
82 * Enables events using log level
83 * @param eventName - a event name
84 * @param logLevelType - a log level type
85 * @param level - a log level
86 * @param monitor - a progress monitor
87 * @throws ExecutionException
89 abstract public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
;
92 * @return returns the relevant domain (null if domain is not known)
94 abstract TraceDomainComponent
getDomain();
98 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
101 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
103 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
105 if (window
== null) {
109 TargetNodeComponent node
= fSession
.getTargetNode();
110 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
112 final IEnableEventsDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableEventsDialog();
113 dialog
.setTraceProviderGroup((TraceProviderGroup
)providers
.get(0));
114 dialog
.setTraceDomainComponent(getDomain());
116 if (dialog
.open() != Window
.OK
) {
120 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
122 protected IStatus
run(IProgressMonitor monitor
) {
123 String errorString
= null;
126 // Enable tracepoint events
127 if (dialog
.isTracepoints()) {
128 if (dialog
.isAllTracePoints()) {
129 enableEvents(null, dialog
.isKernel(), monitor
);
131 List
<String
> eventNames
= dialog
.getEventNames();
132 if (eventNames
.size() > 0) {
133 enableEvents(eventNames
, dialog
.isKernel(), monitor
);
138 // Enable syscall events
139 if (dialog
.isAllSysCalls()) {
140 if (dialog
.isAllSysCalls()) {
141 enableSyscalls(monitor
);
145 // Enable dynamic probe
146 if (dialog
.isDynamicProbe()) {
147 if ((dialog
.getProbeEventName() != null && dialog
.getProbeName() != null)) {
148 enableProbe(dialog
.getProbeEventName(), false, dialog
.getProbeName(), monitor
);
152 // Enable dynamic function probe
153 if (dialog
.isDynamicFunctionProbe()) {
154 if ((dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
155 enableProbe(dialog
.getFunctionEventName(), true, dialog
.getFunction(), monitor
);
159 // Enable event using a wildcard
160 if (dialog
.isWildcard()) {
161 List
<String
> eventNames
= dialog
.getEventNames();
162 eventNames
.add(dialog
.getWildcard());
164 if (eventNames
.size() > 0) {
165 enableEvents(eventNames
, dialog
.isKernel(), monitor
);
169 // Enable events using log level
170 if (dialog
.isLogLevel()) {
171 enableLogLevel(dialog
.getLogLevelEventName(), dialog
.getLogLevelType(), dialog
.getLogLevel(), monitor
);
174 } catch (ExecutionException e
) {
175 if (errorString
== null) {
176 errorString
= new String();
178 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
181 // get session configuration in all cases
183 fSession
.getConfigurationFromNode(monitor
);
184 } catch (ExecutionException e
) {
185 if (errorString
== null) {
186 errorString
= new String();
188 errorString
+= Messages
.TraceControl_ListSessionFailure
+ ": " + e
.toString(); //$NON-NLS-1$
191 if (errorString
!= null) {
192 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, errorString
);
194 return Status
.OK_STATUS
;