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