Commit | Line | Data |
---|---|---|
498704b3 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.control.handlers; | |
13 | ||
14 | import java.util.List; | |
15 | ||
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; | |
34 | ||
35 | /** | |
36 | * <b><u>EnableEventOnSessionHandler</u></b> | |
37 | * <p> | |
38 | * Command handler implementation to enable events for a known session and default channel 'channel0' | |
39 | * (which will be created if doesn't exist). | |
40 | * </p> | |
41 | */ | |
42 | abstract public class BaseEnableEventHandler extends BaseControlViewHandler { | |
43 | ||
44 | // ------------------------------------------------------------------------ | |
45 | // Attributes | |
46 | // ------------------------------------------------------------------------ | |
47 | /** | |
48 | * The session component the command is to be executed on. | |
49 | */ | |
50 | protected TraceSessionComponent fSession = null; | |
51 | ||
52 | // ------------------------------------------------------------------------ | |
53 | // Operations | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
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; | |
60 | ||
61 | /* | |
62 | * (non-Javadoc) | |
63 | * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) | |
64 | */ | |
65 | @Override | |
66 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
67 | ||
68 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
69 | ||
70 | if (window == null) { | |
71 | return false; | |
72 | } | |
73 | ||
74 | TargetNodeComponent node = fSession.getTargetNode(); | |
75 | List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class); | |
76 | List<ITraceControlComponent> kernelProvider = providers.get(0).getChildren(KernelProviderComponent.class); | |
77 | ||
78 | final IEnableKernelEventsDialog dialog = new EnableKernelEventDialog(window.getShell(), (KernelProviderComponent)kernelProvider.get(0)); | |
79 | ||
80 | if (dialog.open() != Window.OK) { | |
81 | return null; | |
82 | } | |
83 | ||
84 | Job job = new Job(Messages.TraceControl_ChangeEventStateJob) { | |
85 | @Override | |
86 | protected IStatus run(IProgressMonitor monitor) { | |
87 | String errorString = null; | |
88 | ||
89 | // Enable tracepoint events | |
90 | try { | |
91 | if (dialog.isAllTracePoints()) { | |
92 | enableEvents(null, monitor); | |
93 | } else { | |
94 | List<String> eventNames = dialog.getEventNames(); | |
95 | if (eventNames.size() > 0) { | |
96 | enableEvents(eventNames, monitor); | |
97 | } | |
98 | } | |
99 | } catch (ExecutionException e) { | |
100 | if (errorString == null) { | |
101 | errorString = new String(); | |
102 | } | |
103 | errorString += e.toString() + "\n"; //$NON-NLS-1$ | |
104 | } | |
105 | ||
106 | // Enable syscall events | |
107 | try { | |
108 | if (dialog.isAllSysCalls()) { | |
109 | enableSyscalls(monitor); | |
110 | } | |
111 | } catch (ExecutionException e) { | |
112 | if (errorString == null) { | |
113 | errorString = new String(); | |
114 | } | |
115 | errorString += e.toString() + "\n"; //$NON-NLS-1$ | |
116 | } | |
117 | ||
118 | // Enable dynamic probe | |
119 | try { | |
120 | if ((dialog.getProbeEventName() != null && dialog.getProbeName() != null)) { | |
121 | enableProbe(dialog.getProbeEventName(), dialog.getProbeName(), monitor); | |
122 | } | |
123 | } catch (ExecutionException e) { | |
124 | if (errorString == null) { | |
125 | errorString = new String(); | |
126 | } | |
127 | errorString += e.toString() + "\n"; //$NON-NLS-1$ | |
128 | } | |
129 | ||
130 | // Enable dynamic function probe | |
131 | try { | |
132 | if ((dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) { | |
133 | fSession.enableFunctionProbe(dialog.getFunctionEventName(), dialog.getFunction(), monitor); | |
134 | } | |
135 | } catch (ExecutionException e) { | |
136 | if (errorString == null) { | |
137 | errorString = new String(); | |
138 | } | |
139 | errorString += e.toString() + "\n"; //$NON-NLS-1$ | |
140 | } | |
141 | ||
142 | // get session configuration in all cases | |
143 | try { | |
144 | fSession.getConfigurationFromNode(monitor); | |
145 | } catch (ExecutionException e) { | |
146 | if (errorString == null) { | |
147 | errorString = new String(); | |
148 | } | |
149 | errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString(); //$NON-NLS-1$ | |
150 | } | |
151 | ||
152 | if (errorString != null) { | |
153 | return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, errorString); | |
154 | } | |
155 | return Status.OK_STATUS; | |
156 | } | |
157 | }; | |
158 | job.setUser(true); | |
159 | job.schedule(); | |
160 | ||
161 | return null; | |
162 | } | |
163 | } |