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
CommitLineData
eb1bab5b
BH
1/**********************************************************************
2 * Copyright (c) 2012 Ericsson
cfdb727a 3 *
eb1bab5b
BH
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
cfdb727a
AM
8 *
9 * Contributors:
eb1bab5b
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl;
eb1bab5b 13
6503ae0f
BH
14import java.util.List;
15
eb1bab5b
BH
16import org.eclipse.core.commands.ExecutionException;
17import org.eclipse.core.runtime.IProgressMonitor;
18import org.eclipse.core.runtime.NullProgressMonitor;
9315aeee
BH
19import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
20import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
21import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
22import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
23import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
24import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
25import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo;
115b4a01 26import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
9315aeee 27import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
115b4a01 28import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
115b4a01 29import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceSessionPropertySource;
eb1bab5b 30import org.eclipse.swt.graphics.Image;
06b9339e 31import org.eclipse.ui.views.properties.IPropertySource;
eb1bab5b
BH
32
33/**
eb1bab5b
BH
34 * <p>
35 * Implementation of the trace session component.
36 * </p>
cfdb727a 37 *
dbd4432d 38 * @author Bernd Hufmann
eb1bab5b
BH
39 */
40public 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 /**
cfdb727a 82 * Constructor
eb1bab5b
BH
83 * @param name - the name of the component.
84 * @param parent - the parent of this component.
cfdb727a 85 */
eb1bab5b
BH
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);
31a6a4e4
BH
91 fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
92 fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
eb1bab5b
BH
93 }
94
95 // ------------------------------------------------------------------------
96 // Accessors
97 // ------------------------------------------------------------------------
98 /*
99 * (non-Javadoc)
115b4a01 100 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
eb1bab5b
BH
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 }
cfdb727a 111
eb1bab5b
BH
112 return fActiveImage;
113 }
114
eb1bab5b
BH
115 /**
116 * @return the whether the session is destroyed or not.
117 */
118 public boolean isDestroyed() {
119 return fIsDestroyed;
120 }
bbb3538a 121
eb1bab5b
BH
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 }
bbb3538a 129
eb1bab5b
BH
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 }
bbb3538a 144
eb1bab5b
BH
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.
cfdb727a 162 * @param sessionPath - session path to set.
eb1bab5b
BH
163 */
164 public void setSessionPath(String sessionPath) {
165 fSessionInfo.setSessionPath(sessionPath);
166 }
167
06b9339e
BH
168 /*
169 * (non-Javadoc)
115b4a01 170 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
06b9339e 171 */
06b9339e
BH
172 @Override
173 public Object getAdapter(Class adapter) {
174 if (adapter == IPropertySource.class) {
175 return new TraceSessionPropertySource(this);
176 }
177 return null;
cfdb727a 178 }
bbb3538a 179
6503ae0f
BH
180 /**
181 * @return all available domains of this session.
182 */
183 public TraceDomainComponent[] getDomains() {
184 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
cfdb727a 185 return sessions.toArray(new TraceDomainComponent[sessions.size()]);
6503ae0f 186 }
cfdb727a 187
498704b3
BH
188 /**
189 * @return the parent target node
190 */
191 public TargetNodeComponent getTargetNode() {
192 return ((TraceSessionGroup)getParent()).getTargetNode();
193 }
cfdb727a 194
a07c7629
BH
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
eb1bab5b
BH
204 // ------------------------------------------------------------------------
205 // Operations
206 // ------------------------------------------------------------------------
cfdb727a 207
eb1bab5b 208 /**
cfdb727a
AM
209 * Retrieves the session configuration from the node.
210 *
eb1bab5b 211 * @throws ExecutionException
cfdb727a 212 * If the command fails
eb1bab5b
BH
213 */
214 public void getConfigurationFromNode() throws ExecutionException {
215 getConfigurationFromNode(new NullProgressMonitor());
216 }
217
218 /**
cfdb727a
AM
219 * Retrieves the session configuration from the node.
220 *
221 * @param monitor
222 * - a progress monitor
eb1bab5b 223 * @throws ExecutionException
cfdb727a 224 * If the command fails
eb1bab5b 225 */
cfdb727a
AM
226 public void getConfigurationFromNode(IProgressMonitor monitor)
227 throws ExecutionException {
bbb3538a 228 removeAllChildren();
eb1bab5b
BH
229 fSessionInfo = getControlService().getSession(getName(), monitor);
230 IDomainInfo[] domains = fSessionInfo.getDomains();
231 for (int i = 0; i < domains.length; i++) {
cfdb727a
AM
232 TraceDomainComponent domainComponent = new TraceDomainComponent(
233 domains[i].getName(), this);
bbb3538a
BH
234 addChild(domainComponent);
235 domainComponent.setDomainInfo(domains[i]);
eb1bab5b
BH
236 }
237 }
cfdb727a 238
bbb3538a 239 /**
cfdb727a
AM
240 * Starts the session.
241 *
242 * @throws ExecutionException
243 * If the command fails
bbb3538a
BH
244 */
245 public void startSession() throws ExecutionException {
246 startSession(new NullProgressMonitor());
247 }
cfdb727a 248
bbb3538a
BH
249 /**
250 * Starts the session.
cfdb727a
AM
251 *
252 * @param monitor
253 * - a progress monitor
254 * @throws ExecutionException
255 * If the command fails
bbb3538a 256 */
cfdb727a
AM
257 public void startSession(IProgressMonitor monitor)
258 throws ExecutionException {
bbb3538a
BH
259 getControlService().startSession(getName(), monitor);
260 }
cfdb727a 261
bbb3538a 262 /**
cfdb727a
AM
263 * Starts the session.
264 *
265 * @throws ExecutionException
266 * If the command fails
bbb3538a
BH
267 */
268 public void stopSession() throws ExecutionException {
269 startSession(new NullProgressMonitor());
270 }
cfdb727a 271
bbb3538a
BH
272 /**
273 * Starts the session.
cfdb727a
AM
274 *
275 * @param monitor
276 * - a progress monitor
277 * @throws ExecutionException
278 * If the command fails
bbb3538a
BH
279 */
280 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
281 getControlService().stopSession(getName(), monitor);
282 }
283
c56972bb 284 /**
cfdb727a
AM
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.
c56972bb 296 * @throws ExecutionException
cfdb727a 297 * If the command fails
c56972bb 298 */
cfdb727a
AM
299 public void enableChannels(List<String> channelNames, IChannelInfo info,
300 boolean isKernel) throws ExecutionException {
c56972bb
BH
301 enableChannels(channelNames, info, isKernel, new NullProgressMonitor());
302 }
303
304 /**
cfdb727a
AM
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
c56972bb 318 * @throws ExecutionException
cfdb727a 319 * If the command fails
c56972bb 320 */
cfdb727a
AM
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);
c56972bb 326 }
cfdb727a 327
6503ae0f
BH
328 /**
329 * Enables a list of events with no additional parameters.
cfdb727a
AM
330 *
331 * @param eventNames
332 * - a list of event names to enabled.
333 * @param isKernel
334 * - a flag for indicating kernel or UST.
6503ae0f 335 * @throws ExecutionException
cfdb727a 336 * If the command fails
6503ae0f 337 */
cfdb727a
AM
338 public void enableEvent(List<String> eventNames, boolean isKernel)
339 throws ExecutionException {
498704b3 340 enableEvents(eventNames, isKernel, new NullProgressMonitor());
6503ae0f
BH
341 }
342
343 /**
344 * Enables a list of events with no additional parameters.
cfdb727a
AM
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
6503ae0f 352 * @throws ExecutionException
cfdb727a 353 * If the command fails
6503ae0f 354 */
cfdb727a
AM
355 public void enableEvents(List<String> eventNames, boolean isKernel,
356 IProgressMonitor monitor) throws ExecutionException {
357 getControlService().enableEvents(getName(), null, eventNames, isKernel,
358 monitor);
498704b3
BH
359 }
360
361 /**
362 * Enables all syscalls (for kernel domain)
cfdb727a 363 *
498704b3 364 * @throws ExecutionException
cfdb727a 365 * If the command fails
498704b3
BH
366 */
367 public void enableSyscalls() throws ExecutionException {
368 enableSyscalls(new NullProgressMonitor());
369 }
370
371 /**
372 * Enables all syscalls (for kernel domain)
cfdb727a
AM
373 *
374 * @param monitor
375 * - a progress monitor
498704b3 376 * @throws ExecutionException
cfdb727a 377 * If the command fails
498704b3 378 */
cfdb727a
AM
379 public void enableSyscalls(IProgressMonitor monitor)
380 throws ExecutionException {
498704b3
BH
381 getControlService().enableSyscalls(getName(), null, monitor);
382 }
383
384 /**
385 * Enables a dynamic probe (for kernel domain)
cfdb727a
AM
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
498704b3 393 * @throws ExecutionException
cfdb727a 394 * If the command fails
498704b3 395 */
cfdb727a
AM
396 public void enableProbe(String eventName, boolean isFunction, String probe)
397 throws ExecutionException {
d132bcc7 398 enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
498704b3 399 }
cfdb727a 400
498704b3
BH
401 /**
402 * Enables a dynamic probe (for kernel domain)
cfdb727a
AM
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
498704b3 412 * @throws ExecutionException
cfdb727a 413 * If the command fails
498704b3 414 */
cfdb727a
AM
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);
6503ae0f 419 }
cfdb727a 420
ccc66d01
BH
421 /**
422 * Enables events using log level.
cfdb727a
AM
423 *
424 * @param eventName
425 * - a event name
426 * @param logLevelType
427 * - a log level type
428 * @param level
429 * - a log level
ccc66d01 430 * @throws ExecutionException
cfdb727a 431 * If the command fails
ccc66d01 432 */
cfdb727a
AM
433 public void enableLogLevel(String eventName, LogLevelType logLevelType,
434 TraceLogLevel level) throws ExecutionException {
435 enableLogLevel(eventName, logLevelType, level,
436 new NullProgressMonitor());
ccc66d01
BH
437 }
438
439 /**
440 * Enables events using log level.
cfdb727a
AM
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
ccc66d01 450 * @throws ExecutionException
cfdb727a 451 * If the command fails
ccc66d01 452 */
cfdb727a
AM
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);
ccc66d01 458 }
cfdb727a 459
b793fbe1
BH
460 /**
461 * Gets all available contexts to be added to channels/events.
cfdb727a 462 *
b793fbe1 463 * @return the list of available contexts
cfdb727a
AM
464 * @throws ExecutionException
465 * If the command fails
b793fbe1
BH
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.
cfdb727a 473 *
b793fbe1 474 * @param monitor
cfdb727a 475 * The monitor that will indicate the progress
b793fbe1 476 * @return the list of available contexts
cfdb727a
AM
477 * @throws ExecutionException
478 * If the command fails
b793fbe1 479 */
cfdb727a
AM
480 public List<String> getContextList(IProgressMonitor monitor)
481 throws ExecutionException {
b793fbe1
BH
482 return getControlService().getContextList(monitor);
483 }
eb1bab5b 484}
This page took 0.054859 seconds and 5 git commands to generate.