Add capability to enable events with different parameters on session,
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / model / impl / TraceSessionComponent.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.lttng.ui.views.control.model.impl;
13
14 import java.util.List;
15
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19 import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
20 import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
21 import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo;
22 import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo;
23 import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent;
24 import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType;
25 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel;
26 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
27 import org.eclipse.linuxtools.lttng.ui.views.control.property.TraceSessionPropertySource;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.ui.views.properties.IPropertySource;
30
31 /**
32 * <b><u>TraceSessionComponent</u></b>
33 * <p>
34 * Implementation of the trace session component.
35 * </p>
36 */
37 public class TraceSessionComponent extends TraceControlComponent {
38
39 // ------------------------------------------------------------------------
40 // Constants
41 // ------------------------------------------------------------------------
42 /**
43 * Path to icon file for this component (inactive state).
44 */
45 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
46 /**
47 * Path to icon file for this component (active state).
48 */
49 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
50 /**
51 * Path to icon file for this component (destroyed state).
52 */
53 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
54
55 // ------------------------------------------------------------------------
56 // Attributes
57 // ------------------------------------------------------------------------
58 /**
59 * The session information.
60 */
61 private ISessionInfo fSessionInfo = null;
62 /**
63 * A flag to indicate if session has been destroyed.
64 */
65 private boolean fIsDestroyed = false;
66 /**
67 * The image to be displayed in state active.
68 */
69 private Image fActiveImage = null;
70 /**
71 * The image to be displayed in state destroyed
72 */
73 private Image fDestroyedImage = null;
74
75 // ------------------------------------------------------------------------
76 // Constructors
77 // ------------------------------------------------------------------------
78 /**
79 * Constructor
80 * @param name - the name of the component.
81 * @param parent - the parent of this component.
82 */
83 public TraceSessionComponent(String name, ITraceControlComponent parent) {
84 super(name, parent);
85 setImage(TRACE_SESSION_ICON_FILE_INACTIVE);
86 setToolTip(Messages.TraceControl_SessionDisplayName);
87 fSessionInfo = new SessionInfo(name);
88 fActiveImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
89 fDestroyedImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
90 }
91
92 // ------------------------------------------------------------------------
93 // Accessors
94 // ------------------------------------------------------------------------
95 /*
96 * (non-Javadoc)
97 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
98 */
99 @Override
100 public Image getImage() {
101 if (fIsDestroyed) {
102 return fDestroyedImage;
103 }
104
105 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
106 return super.getImage();
107 }
108
109 return fActiveImage;
110 }
111
112 /**
113 * @return the whether the session is destroyed or not.
114 */
115 public boolean isDestroyed() {
116 return fIsDestroyed;
117 }
118
119 /**
120 * Sets the session destroyed state to the given value.
121 * @param destroyed - value to set.
122 */
123 public void setDestroyed(boolean destroyed) {
124 fIsDestroyed = destroyed;
125 }
126
127 /**
128 * @return the session state state (active or inactive).
129 */
130 public TraceSessionState getSessionState() {
131 return fSessionInfo.getSessionState();
132 }
133
134 /**
135 * Sets the session state to the given value.
136 * @param state - state to set.
137 */
138 public void setSessionState(TraceSessionState state) {
139 fSessionInfo.setSessionState(state);
140 }
141
142 /**
143 * Sets the event state to the value specified by the given name.
144 * @param stateName - state to set.
145 */
146 public void setSessionState(String stateName) {
147 fSessionInfo.setSessionState(stateName);
148 }
149
150 /**
151 * @return path string where session is located.
152 */
153 public String getSessionPath() {
154 return fSessionInfo.getSessionPath();
155 }
156
157 /**
158 * Sets the path string (where session is located) to the given value.
159 * @param path - session path to set.
160 */
161 public void setSessionPath(String sessionPath) {
162 fSessionInfo.setSessionPath(sessionPath);
163 }
164
165 /*
166 * (non-Javadoc)
167 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
168 */
169 @SuppressWarnings("rawtypes")
170 @Override
171 public Object getAdapter(Class adapter) {
172 if (adapter == IPropertySource.class) {
173 return new TraceSessionPropertySource(this);
174 }
175 return null;
176 }
177
178 /**
179 * @return all available domains of this session.
180 */
181 public TraceDomainComponent[] getDomains() {
182 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
183 return (TraceDomainComponent[])sessions.toArray(new TraceDomainComponent[sessions.size()]);
184 }
185
186 /**
187 * @return the parent target node
188 */
189 public TargetNodeComponent getTargetNode() {
190 return ((TraceSessionGroup)getParent()).getTargetNode();
191 }
192
193 // ------------------------------------------------------------------------
194 // Operations
195 // ------------------------------------------------------------------------
196 /**
197 * Retrieves the session configuration from the node.
198 * @throws ExecutionException
199 */
200 public void getConfigurationFromNode() throws ExecutionException {
201 getConfigurationFromNode(new NullProgressMonitor());
202 }
203
204 /**
205 * Retrieves the session configuration from the node.
206 * @param monitor - a progress monitor
207 * @throws ExecutionException
208 */
209 public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException {
210 removeAllChildren();
211 fSessionInfo = getControlService().getSession(getName(), monitor);
212 IDomainInfo[] domains = fSessionInfo.getDomains();
213 for (int i = 0; i < domains.length; i++) {
214 TraceDomainComponent domainComponent = new TraceDomainComponent(domains[i].getName(), this);
215 addChild(domainComponent);
216 domainComponent.setDomainInfo(domains[i]);
217 }
218 }
219
220 /**
221 * Starts the session.
222 * throws ExecutionExecption
223 */
224 public void startSession() throws ExecutionException {
225 startSession(new NullProgressMonitor());
226 }
227
228 /**
229 * Starts the session.
230 * @param monitor - a progress monitor
231 * throws ExecutionExecption
232 */
233 public void startSession(IProgressMonitor monitor) throws ExecutionException {
234 getControlService().startSession(getName(), monitor);
235 }
236
237 /**
238 * Starts the session.
239 * throws ExecutionExecption
240 */
241 public void stopSession() throws ExecutionException {
242 startSession(new NullProgressMonitor());
243 }
244
245 /**
246 * Starts the session.
247 * @param monitor - a progress monitor
248 * throws ExecutionExecption
249 */
250 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
251 getControlService().stopSession(getName(), monitor);
252 }
253
254 /**
255 * Enables a list of events with no additional parameters.
256 * @param eventNames - a list of event names to enabled.
257 * @param isKernel - a flag for indicating kernel or UST.
258 * @throws ExecutionException
259 */
260 public void enableEvent(List<String> eventNames, boolean isKernel) throws ExecutionException {
261 enableEvents(eventNames, isKernel, new NullProgressMonitor());
262 }
263
264 /**
265 * Enables a list of events with no additional parameters.
266 * @param eventNames - a list of event names to enabled.
267 * @param isKernel - a flag for indicating kernel or UST.
268 * @param monitor - a progress monitor
269 * @throws ExecutionException
270 */
271 public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
272 getControlService().enableEvents(getName(), null, eventNames, isKernel, monitor);
273 }
274
275 /**
276 * Enables all syscalls (for kernel domain)
277 * @throws ExecutionException
278 */
279 public void enableSyscalls() throws ExecutionException {
280 enableSyscalls(new NullProgressMonitor());
281 }
282
283 /**
284 * Enables all syscalls (for kernel domain)
285 * @param monitor - a progress monitor
286 * @throws ExecutionException
287 */
288 public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
289 getControlService().enableSyscalls(getName(), null, monitor);
290 }
291
292 /**
293 * Enables a dynamic probe (for kernel domain)
294 * @param eventName - event name for probe
295 * @param probe - the actual probe
296 * @throws ExecutionException
297 */
298 public void enableProbe(String eventName, String probe) throws ExecutionException {
299 enableProbe(eventName, probe, new NullProgressMonitor());
300 }
301
302 /**
303 * Enables a dynamic probe (for kernel domain)
304 * @param eventName - event name for probe
305 * @param probe - the actual probe
306 * @param monitor - a progress monitor
307 * @throws ExecutionException
308 */
309 public void enableProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException {
310 getControlService().enableProbe(getName(), null, eventName, probe, monitor);
311 }
312
313 /**
314 * Enables a dynamic function entry/return probe (for kernel domain)
315 * @param eventName - event name for probe
316 * @param probe - the actual probe
317 * @throws ExecutionException
318 */
319 public void enableFunctionProbe(String eventName, String probe) throws ExecutionException {
320 enableFunctionProbe(eventName, probe, new NullProgressMonitor());
321 }
322
323 /**
324 * Enables a dynamic function entry/return probe (for kernel domain)
325 * @param eventName - event name for probe
326 * @param probe - the actual probe
327 * @param monitor - a progress monitor
328 * @throws ExecutionException
329 */
330 public void enableFunctionProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException {
331 getControlService().enableFunctionProbe(getName(), null, eventName, probe, monitor);
332 }
333
334 /**
335 * Enables events using log level.
336 * @param eventName - a event name
337 * @param logLevelType - a log level type
338 * @param level - a log level
339 * @throws ExecutionException
340 */
341 public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level) throws ExecutionException {
342 enableLogLevel(eventName, logLevelType, level, new NullProgressMonitor());
343 }
344
345 /**
346 * Enables events using log level.
347 * @param eventName - a event name
348 * @param logLevelType - a log level type
349 * @param level - a log level
350 * @param monitor - a progress monitor
351 * @throws ExecutionException
352 */
353 public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
354 getControlService().enableLogLevel(getName(), null, eventName, logLevelType, level, monitor);
355 }
356 }
This page took 0.04486 seconds and 5 git commands to generate.