Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseEnableEventHandler.java
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.internal.lttng2.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.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;
35
36 /**
37 * <b><u>EnableEventOnSessionHandler</u></b>
38 * <p>
39 * Base command handler implementation to enable events.
40 * </p>
41 */
42 abstract public class BaseEnableEventHandler extends BaseControlViewHandler {
43
44 // ------------------------------------------------------------------------
45 // Attributes
46 // ------------------------------------------------------------------------
47 /**
48 * The command execution parameter.
49 */
50 protected CommandParameter fParam = null;
51
52 // ------------------------------------------------------------------------
53 // Operations
54 // ------------------------------------------------------------------------
55 /**
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
62 */
63 abstract public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException;
64
65 /**
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
70 */
71 abstract public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
72
73 /**
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
81 */
82 abstract public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
83
84 /**
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
92 */
93 abstract public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException;
94
95 /**
96 * @param - a parameter instance with data for the command execution
97 * @return returns the relevant domain (null if domain is not known)
98 */
99 abstract TraceDomainComponent getDomain(CommandParameter param);
100
101 /*
102 * (non-Javadoc)
103 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
104 */
105 @Override
106 public Object execute(ExecutionEvent event) throws ExecutionException {
107
108 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
109
110 if (window == null) {
111 return false;
112 }
113 fLock.lock();
114 try {
115 // Make a copy for thread safety
116 final CommandParameter param = fParam.clone();
117
118 TargetNodeComponent node = param.getSession().getTargetNode();
119 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
120
121 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
122 dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
123 dialog.setTraceDomainComponent(getDomain(param));
124
125 if (dialog.open() != Window.OK) {
126 return null;
127 }
128
129 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
130 @Override
131 protected IStatus run(IProgressMonitor monitor) {
132 StringBuffer errorString = new StringBuffer();
133
134 try {
135 // Enable tracepoint events
136 if (dialog.isTracepoints()) {
137 if (dialog.isAllTracePoints()) {
138 enableEvents(param, null, dialog.isKernel(), monitor);
139 } else {
140 List<String> eventNames = dialog.getEventNames();
141 if (!eventNames.isEmpty()) {
142 enableEvents(param, eventNames, dialog.isKernel(), monitor);
143 }
144 }
145 }
146
147 // Enable syscall events
148 if (dialog.isAllSysCalls()) {
149 enableSyscalls(param, monitor);
150 }
151
152 // Enable dynamic probe
153 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
154 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
155 }
156
157 // Enable dynamic function probe
158 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
159 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
160 }
161
162 // Enable event using a wildcard
163 if (dialog.isWildcard()) {
164 List<String> eventNames = dialog.getEventNames();
165 eventNames.add(dialog.getWildcard());
166
167 if (!eventNames.isEmpty()) {
168 enableEvents(param, eventNames, dialog.isKernel(), monitor);
169 }
170 }
171
172 // Enable events using log level
173 if (dialog.isLogLevel()) {
174 enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), monitor);
175 }
176
177 } catch (ExecutionException e) {
178 errorString.append(e.toString());
179 errorString.append('\n');
180 }
181
182 // get session configuration in all cases
183 try {
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());
189 }
190
191 if (errorString.length() > 0) {
192 return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
193 }
194 return Status.OK_STATUS;
195 }
196 };
197 job.setUser(true);
198 job.schedule();
199 } finally {
200 fLock.unlock();
201 }
202 return null;
203 }
204 }
This page took 0.035613 seconds and 6 git commands to generate.