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