Update internal packages export in LTTng 2.0 control + update java doc
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseEnableEventHandler.java
CommitLineData
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 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
498704b3
BH
13
14import java.util.List;
15
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.core.runtime.IStatus;
20import org.eclipse.core.runtime.Status;
21import org.eclipse.core.runtime.jobs.Job;
22import org.eclipse.jface.window.Window;
9315aeee
BH
23import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
24import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
115b4a01 25import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
115b4a01
BH
26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog;
27import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
9315aeee 28import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
115b4a01 29import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
115b4a01
BH
30import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
31import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
32import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup;
498704b3
BH
33import org.eclipse.ui.IWorkbenchWindow;
34import org.eclipse.ui.PlatformUI;
35
36/**
498704b3 37 * <p>
ccc66d01 38 * Base command handler implementation to enable events.
498704b3 39 * </p>
dbd4432d
BH
40 *
41 * @author Bernd Hufmann
498704b3
BH
42 */
43abstract public class BaseEnableEventHandler extends BaseControlViewHandler {
44
45 // ------------------------------------------------------------------------
46 // Attributes
47 // ------------------------------------------------------------------------
48 /**
c56972bb 49 * The command execution parameter.
498704b3 50 */
c56972bb 51 protected CommandParameter fParam = null;
498704b3
BH
52
53 // ------------------------------------------------------------------------
54 // Operations
55 // ------------------------------------------------------------------------
ccc66d01
BH
56 /**
57 * Enables a list of events for given parameters.
c56972bb 58 * @param - a parameter instance with data for the command execution
ccc66d01
BH
59 * @param eventNames - list of event names
60 * @param isKernel - true if kernel domain else false
61 * @param monitor - a progress monitor
62 * @throws ExecutionException
63 */
c56972bb
BH
64 abstract public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException;
65
ccc66d01
BH
66 /**
67 * Enables all syscall events.
c56972bb 68 * @param - a parameter instance with data for the command execution
ccc66d01
BH
69 * @param monitor - a progress monitor
70 * @throws ExecutionException
71 */
c56972bb 72 abstract public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
ccc66d01
BH
73
74 /**
75 * Enables a dynamic probe.
c56972bb 76 * @param - a parameter instance with data for the command execution
ccc66d01 77 * @param eventName - a event name
d132bcc7 78 * @param isFunction - true for dynamic function entry/return probe else false
ccc66d01
BH
79 * @param probe - a dynamic probe information
80 * @param monitor - a progress monitor
81 * @throws ExecutionException
82 */
c56972bb 83 abstract public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
498704b3 84
ccc66d01
BH
85 /**
86 * Enables events using log level
c56972bb 87 * @param - a parameter instance with data for the command execution
ccc66d01
BH
88 * @param eventName - a event name
89 * @param logLevelType - a log level type
90 * @param level - a log level
91 * @param monitor - a progress monitor
92 * @throws ExecutionException
93 */
c56972bb 94 abstract public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException;
498704b3 95
ccc66d01 96 /**
c56972bb 97 * @param - a parameter instance with data for the command execution
ccc66d01
BH
98 * @return returns the relevant domain (null if domain is not known)
99 */
c56972bb 100 abstract TraceDomainComponent getDomain(CommandParameter param);
ccc66d01 101
498704b3
BH
102 /*
103 * (non-Javadoc)
104 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
105 */
106 @Override
107 public Object execute(ExecutionEvent event) throws ExecutionException {
108
109 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
110
111 if (window == null) {
112 return false;
113 }
c56972bb
BH
114 fLock.lock();
115 try {
116 // Make a copy for thread safety
117 final CommandParameter param = fParam.clone();
498704b3 118
c56972bb
BH
119 TargetNodeComponent node = param.getSession().getTargetNode();
120 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
d132bcc7 121
c56972bb
BH
122 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
123 dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
124 dialog.setTraceDomainComponent(getDomain(param));
d132bcc7 125
c56972bb
BH
126 if (dialog.open() != Window.OK) {
127 return null;
128 }
498704b3 129
c56972bb
BH
130 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
131 @Override
132 protected IStatus run(IProgressMonitor monitor) {
f455db37 133 Exception error = null;
c56972bb
BH
134
135 try {
136 // Enable tracepoint events
137 if (dialog.isTracepoints()) {
138 if (dialog.isAllTracePoints()) {
139 enableEvents(param, null, dialog.isKernel(), monitor);
140 } else {
141 List<String> eventNames = dialog.getEventNames();
142 if (!eventNames.isEmpty()) {
143 enableEvents(param, eventNames, dialog.isKernel(), monitor);
144 }
ccc66d01
BH
145 }
146 }
ccc66d01 147
c56972bb 148 // Enable syscall events
ccc66d01 149 if (dialog.isAllSysCalls()) {
c56972bb
BH
150 enableSyscalls(param, monitor);
151 }
ccc66d01 152
c56972bb
BH
153 // Enable dynamic probe
154 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
155 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
156 }
ccc66d01 157
c56972bb
BH
158 // Enable dynamic function probe
159 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
160 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
161 }
ccc66d01 162
c56972bb
BH
163 // Enable event using a wildcard
164 if (dialog.isWildcard()) {
165 List<String> eventNames = dialog.getEventNames();
166 eventNames.add(dialog.getWildcard());
ccc66d01 167
c56972bb
BH
168 if (!eventNames.isEmpty()) {
169 enableEvents(param, eventNames, dialog.isKernel(), monitor);
170 }
498704b3 171 }
c56972bb
BH
172
173 // Enable events using log level
174 if (dialog.isLogLevel()) {
175 enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), monitor);
176 }
177
178 } catch (ExecutionException e) {
f455db37 179 error = e;
ccc66d01 180 }
498704b3 181
f455db37
BH
182 // refresh in all cases
183 refresh(param);
498704b3 184
f455db37
BH
185 if (error != null) {
186 return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
498704b3 187 }
c56972bb 188 return Status.OK_STATUS;
498704b3 189 }
c56972bb
BH
190 };
191 job.setUser(true);
192 job.schedule();
193 } finally {
194 fLock.unlock();
195 }
498704b3
BH
196 return null;
197 }
198}
This page took 0.049705 seconds and 5 git commands to generate.