Add support for UST-only nodes in Control View (Bug 388477)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / 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.internal.lttng2.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.internal.lttng2.core.control.model.IChannelInfo;
20 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
21 import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
22 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
23 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
24 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
25 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo;
26 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
27 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
28 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
29 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceSessionPropertySource;
30 import org.eclipse.swt.graphics.Image;
31 import org.eclipse.ui.views.properties.IPropertySource;
32
33 /**
34 * <p>
35 * Implementation of the trace session component.
36 * </p>
37 *
38 * @author Bernd Hufmann
39 */
40 public class TraceSessionComponent extends TraceControlComponent {
41
42 // ------------------------------------------------------------------------
43 // Constants
44 // ------------------------------------------------------------------------
45 /**
46 * Path to icon file for this component (inactive state).
47 */
48 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
49 /**
50 * Path to icon file for this component (active state).
51 */
52 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
53 /**
54 * Path to icon file for this component (destroyed state).
55 */
56 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
57
58 // ------------------------------------------------------------------------
59 // Attributes
60 // ------------------------------------------------------------------------
61 /**
62 * The session information.
63 */
64 private ISessionInfo fSessionInfo = null;
65 /**
66 * A flag to indicate if session has been destroyed.
67 */
68 private boolean fIsDestroyed = false;
69 /**
70 * The image to be displayed in state active.
71 */
72 private Image fActiveImage = null;
73 /**
74 * The image to be displayed in state destroyed
75 */
76 private Image fDestroyedImage = null;
77
78 // ------------------------------------------------------------------------
79 // Constructors
80 // ------------------------------------------------------------------------
81 /**
82 * Constructor
83 * @param name - the name of the component.
84 * @param parent - the parent of this component.
85 */
86 public TraceSessionComponent(String name, ITraceControlComponent parent) {
87 super(name, parent);
88 setImage(TRACE_SESSION_ICON_FILE_INACTIVE);
89 setToolTip(Messages.TraceControl_SessionDisplayName);
90 fSessionInfo = new SessionInfo(name);
91 fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
92 fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
93 }
94
95 // ------------------------------------------------------------------------
96 // Accessors
97 // ------------------------------------------------------------------------
98 /*
99 * (non-Javadoc)
100 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
101 */
102 @Override
103 public Image getImage() {
104 if (fIsDestroyed) {
105 return fDestroyedImage;
106 }
107
108 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
109 return super.getImage();
110 }
111
112 return fActiveImage;
113 }
114
115 /**
116 * @return the whether the session is destroyed or not.
117 */
118 public boolean isDestroyed() {
119 return fIsDestroyed;
120 }
121
122 /**
123 * Sets the session destroyed state to the given value.
124 * @param destroyed - value to set.
125 */
126 public void setDestroyed(boolean destroyed) {
127 fIsDestroyed = destroyed;
128 }
129
130 /**
131 * @return the session state state (active or inactive).
132 */
133 public TraceSessionState getSessionState() {
134 return fSessionInfo.getSessionState();
135 }
136
137 /**
138 * Sets the session state to the given value.
139 * @param state - state to set.
140 */
141 public void setSessionState(TraceSessionState state) {
142 fSessionInfo.setSessionState(state);
143 }
144
145 /**
146 * Sets the event state to the value specified by the given name.
147 * @param stateName - state to set.
148 */
149 public void setSessionState(String stateName) {
150 fSessionInfo.setSessionState(stateName);
151 }
152
153 /**
154 * @return path string where session is located.
155 */
156 public String getSessionPath() {
157 return fSessionInfo.getSessionPath();
158 }
159
160 /**
161 * Sets the path string (where session is located) to the given value.
162 * @param sessionPath - session path to set.
163 */
164 public void setSessionPath(String sessionPath) {
165 fSessionInfo.setSessionPath(sessionPath);
166 }
167
168 /*
169 * (non-Javadoc)
170 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
171 */
172 @Override
173 public Object getAdapter(Class adapter) {
174 if (adapter == IPropertySource.class) {
175 return new TraceSessionPropertySource(this);
176 }
177 return null;
178 }
179
180 /**
181 * @return all available domains of this session.
182 */
183 public TraceDomainComponent[] getDomains() {
184 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
185 return sessions.toArray(new TraceDomainComponent[sessions.size()]);
186 }
187
188 /**
189 * @return the parent target node
190 */
191 public TargetNodeComponent getTargetNode() {
192 return ((TraceSessionGroup)getParent()).getTargetNode();
193 }
194
195 /**
196 * Returns whether the kernel provider is available or not
197 * @return <code>true</code> if kernel provide is available or <code>false</code>
198 */
199 public boolean hasKernelProvider() {
200 List<ITraceControlComponent> providerGroups = getTargetNode().getChildren(TraceProviderGroup.class);
201 return (!providerGroups.isEmpty() ? ((TraceProviderGroup) providerGroups.get(0)).hasKernelProvider() : false);
202 }
203
204 // ------------------------------------------------------------------------
205 // Operations
206 // ------------------------------------------------------------------------
207
208 /**
209 * Retrieves the session configuration from the node.
210 *
211 * @throws ExecutionException
212 * If the command fails
213 */
214 public void getConfigurationFromNode() throws ExecutionException {
215 getConfigurationFromNode(new NullProgressMonitor());
216 }
217
218 /**
219 * Retrieves the session configuration from the node.
220 *
221 * @param monitor
222 * - a progress monitor
223 * @throws ExecutionException
224 * If the command fails
225 */
226 public void getConfigurationFromNode(IProgressMonitor monitor)
227 throws ExecutionException {
228 removeAllChildren();
229 fSessionInfo = getControlService().getSession(getName(), monitor);
230 IDomainInfo[] domains = fSessionInfo.getDomains();
231 for (int i = 0; i < domains.length; i++) {
232 TraceDomainComponent domainComponent = new TraceDomainComponent(
233 domains[i].getName(), this);
234 addChild(domainComponent);
235 domainComponent.setDomainInfo(domains[i]);
236 }
237 }
238
239 /**
240 * Starts the session.
241 *
242 * @throws ExecutionException
243 * If the command fails
244 */
245 public void startSession() throws ExecutionException {
246 startSession(new NullProgressMonitor());
247 }
248
249 /**
250 * Starts the session.
251 *
252 * @param monitor
253 * - a progress monitor
254 * @throws ExecutionException
255 * If the command fails
256 */
257 public void startSession(IProgressMonitor monitor)
258 throws ExecutionException {
259 getControlService().startSession(getName(), monitor);
260 }
261
262 /**
263 * Starts the session.
264 *
265 * @throws ExecutionException
266 * If the command fails
267 */
268 public void stopSession() throws ExecutionException {
269 startSession(new NullProgressMonitor());
270 }
271
272 /**
273 * Starts the session.
274 *
275 * @param monitor
276 * - a progress monitor
277 * @throws ExecutionException
278 * If the command fails
279 */
280 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
281 getControlService().stopSession(getName(), monitor);
282 }
283
284 /**
285 * Enables channels with given names which are part of this domain. If a
286 * given channel doesn't exists it creates a new channel with the given
287 * parameters (or default values if given parameter is null).
288 *
289 * @param channelNames
290 * - a list of channel names to enable on this domain
291 * @param info
292 * - channel information to set for the channel (use null for
293 * default)
294 * @param isKernel
295 * - a flag for indicating kernel or UST.
296 * @throws ExecutionException
297 * If the command fails
298 */
299 public void enableChannels(List<String> channelNames, IChannelInfo info,
300 boolean isKernel) throws ExecutionException {
301 enableChannels(channelNames, info, isKernel, new NullProgressMonitor());
302 }
303
304 /**
305 * Enables channels with given names which are part of this domain. If a
306 * given channel doesn't exists it creates a new channel with the given
307 * parameters (or default values if given parameter is null).
308 *
309 * @param channelNames
310 * - a list of channel names to enable on this domain
311 * @param info
312 * - channel information to set for the channel (use null for
313 * default)
314 * @param isKernel
315 * - a flag for indicating kernel or UST.
316 * @param monitor
317 * - a progress monitor
318 * @throws ExecutionException
319 * If the command fails
320 */
321 public void enableChannels(List<String> channelNames, IChannelInfo info,
322 boolean isKernel, IProgressMonitor monitor)
323 throws ExecutionException {
324 getControlService().enableChannels(getName(), channelNames, isKernel,
325 info, monitor);
326 }
327
328 /**
329 * Enables a list of events with no additional parameters.
330 *
331 * @param eventNames
332 * - a list of event names to enabled.
333 * @param isKernel
334 * - a flag for indicating kernel or UST.
335 * @throws ExecutionException
336 * If the command fails
337 */
338 public void enableEvent(List<String> eventNames, boolean isKernel)
339 throws ExecutionException {
340 enableEvents(eventNames, isKernel, new NullProgressMonitor());
341 }
342
343 /**
344 * Enables a list of events with no additional parameters.
345 *
346 * @param eventNames
347 * - a list of event names to enabled.
348 * @param isKernel
349 * - a flag for indicating kernel or UST.
350 * @param monitor
351 * - a progress monitor
352 * @throws ExecutionException
353 * If the command fails
354 */
355 public void enableEvents(List<String> eventNames, boolean isKernel,
356 IProgressMonitor monitor) throws ExecutionException {
357 getControlService().enableEvents(getName(), null, eventNames, isKernel,
358 monitor);
359 }
360
361 /**
362 * Enables all syscalls (for kernel domain)
363 *
364 * @throws ExecutionException
365 * If the command fails
366 */
367 public void enableSyscalls() throws ExecutionException {
368 enableSyscalls(new NullProgressMonitor());
369 }
370
371 /**
372 * Enables all syscalls (for kernel domain)
373 *
374 * @param monitor
375 * - a progress monitor
376 * @throws ExecutionException
377 * If the command fails
378 */
379 public void enableSyscalls(IProgressMonitor monitor)
380 throws ExecutionException {
381 getControlService().enableSyscalls(getName(), null, monitor);
382 }
383
384 /**
385 * Enables a dynamic probe (for kernel domain)
386 *
387 * @param eventName
388 * - event name for probe
389 * @param isFunction
390 * - true for dynamic function entry/return probe else false
391 * @param probe
392 * - the actual probe
393 * @throws ExecutionException
394 * If the command fails
395 */
396 public void enableProbe(String eventName, boolean isFunction, String probe)
397 throws ExecutionException {
398 enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
399 }
400
401 /**
402 * Enables a dynamic probe (for kernel domain)
403 *
404 * @param eventName
405 * - event name for probe
406 * @param isFunction
407 * - true for dynamic function entry/return probe else false
408 * @param probe
409 * - the actual probe
410 * @param monitor
411 * - a progress monitor
412 * @throws ExecutionException
413 * If the command fails
414 */
415 public void enableProbe(String eventName, boolean isFunction, String probe,
416 IProgressMonitor monitor) throws ExecutionException {
417 getControlService().enableProbe(getName(), null, eventName, isFunction,
418 probe, monitor);
419 }
420
421 /**
422 * Enables events using log level.
423 *
424 * @param eventName
425 * - a event name
426 * @param logLevelType
427 * - a log level type
428 * @param level
429 * - a log level
430 * @throws ExecutionException
431 * If the command fails
432 */
433 public void enableLogLevel(String eventName, LogLevelType logLevelType,
434 TraceLogLevel level) throws ExecutionException {
435 enableLogLevel(eventName, logLevelType, level,
436 new NullProgressMonitor());
437 }
438
439 /**
440 * Enables events using log level.
441 *
442 * @param eventName
443 * - a event name
444 * @param logLevelType
445 * - a log level type
446 * @param level
447 * - a log level
448 * @param monitor
449 * - a progress monitor
450 * @throws ExecutionException
451 * If the command fails
452 */
453 public void enableLogLevel(String eventName, LogLevelType logLevelType,
454 TraceLogLevel level, IProgressMonitor monitor)
455 throws ExecutionException {
456 getControlService().enableLogLevel(getName(), null, eventName,
457 logLevelType, level, monitor);
458 }
459
460 /**
461 * Gets all available contexts to be added to channels/events.
462 *
463 * @return the list of available contexts
464 * @throws ExecutionException
465 * If the command fails
466 */
467 public List<String> getContextList() throws ExecutionException {
468 return getContextList(new NullProgressMonitor());
469 }
470
471 /**
472 * Gets all available contexts to be added to channels/events.
473 *
474 * @param monitor
475 * The monitor that will indicate the progress
476 * @return the list of available contexts
477 * @throws ExecutionException
478 * If the command fails
479 */
480 public List<String> getContextList(IProgressMonitor monitor)
481 throws ExecutionException {
482 return getControlService().getContextList(monitor);
483 }
484 }
This page took 0.041136 seconds and 5 git commands to generate.