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
.EnableKernelEventDialog
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.IEnableKernelEventsDialog
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceProviderGroup
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
32 import org
.eclipse
.ui
.IWorkbenchWindow
;
33 import org
.eclipse
.ui
.PlatformUI
;
36 * <b><u>EnableEventOnSessionHandler</u></b>
38 * Command handler implementation to enable events for a known session and default channel 'channel0'
39 * (which will be created if doesn't exist).
42 abstract public class BaseEnableEventHandler
extends BaseControlViewHandler
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * The session component the command is to be executed on.
50 protected TraceSessionComponent fSession
= null;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 abstract void enableEvents(List
<String
> eventNames
, IProgressMonitor monitor
) throws ExecutionException
;
57 abstract void enableSyscalls(IProgressMonitor monitor
) throws ExecutionException
;
58 abstract void enableProbe(String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
59 abstract void enableFunctionProbe(String eventName
, String probe
, IProgressMonitor monitor
) throws ExecutionException
;
63 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
66 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
68 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
74 TargetNodeComponent node
= fSession
.getTargetNode();
75 List
<ITraceControlComponent
> providers
= node
.getChildren(TraceProviderGroup
.class);
76 List
<ITraceControlComponent
> kernelProvider
= providers
.get(0).getChildren(KernelProviderComponent
.class);
78 final IEnableKernelEventsDialog dialog
= new EnableKernelEventDialog(window
.getShell(), (KernelProviderComponent
)kernelProvider
.get(0));
80 if (dialog
.open() != Window
.OK
) {
84 Job job
= new Job(Messages
.TraceControl_ChangeEventStateJob
) {
86 protected IStatus
run(IProgressMonitor monitor
) {
87 String errorString
= null;
89 // Enable tracepoint events
91 if (dialog
.isAllTracePoints()) {
92 enableEvents(null, monitor
);
94 List
<String
> eventNames
= dialog
.getEventNames();
95 if (eventNames
.size() > 0) {
96 enableEvents(eventNames
, monitor
);
99 } catch (ExecutionException e
) {
100 if (errorString
== null) {
101 errorString
= new String();
103 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
106 // Enable syscall events
108 if (dialog
.isAllSysCalls()) {
109 enableSyscalls(monitor
);
111 } catch (ExecutionException e
) {
112 if (errorString
== null) {
113 errorString
= new String();
115 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
118 // Enable dynamic probe
120 if ((dialog
.getProbeEventName() != null && dialog
.getProbeName() != null)) {
121 enableProbe(dialog
.getProbeEventName(), dialog
.getProbeName(), monitor
);
123 } catch (ExecutionException e
) {
124 if (errorString
== null) {
125 errorString
= new String();
127 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
130 // Enable dynamic function probe
132 if ((dialog
.getFunctionEventName() != null) && (dialog
.getFunction() != null)) {
133 fSession
.enableFunctionProbe(dialog
.getFunctionEventName(), dialog
.getFunction(), monitor
);
135 } catch (ExecutionException e
) {
136 if (errorString
== null) {
137 errorString
= new String();
139 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
142 // get session configuration in all cases
144 fSession
.getConfigurationFromNode(monitor
);
145 } catch (ExecutionException e
) {
146 if (errorString
== null) {
147 errorString
= new String();
149 errorString
+= Messages
.TraceControl_ListSessionFailure
+ ": " + e
.toString(); //$NON-NLS-1$
152 if (errorString
!= null) {
153 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, errorString
);
155 return Status
.OK_STATUS
;