lttng: Rename lttng2 feature/plugins to lttng2.control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / model / impl / TraceSessionComponent.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl;
14
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo;
20 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo;
21 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
22 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo;
23 import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType;
24 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
25 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
26 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo;
27 import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
28 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
29 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
30 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.property.TraceSessionPropertySource;
31 import org.eclipse.swt.graphics.Image;
32 import org.eclipse.ui.views.properties.IPropertySource;
33
34 /**
35 * <p>
36 * Implementation of the trace session component.
37 * </p>
38 *
39 * @author Bernd Hufmann
40 */
41 public 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 /**
83 * Constructor
84 * @param name - the name of the component.
85 * @param parent - the parent of this component.
86 */
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);
92 fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
93 fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
94 }
95
96 // ------------------------------------------------------------------------
97 // Accessors
98 // ------------------------------------------------------------------------
99
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 }
109
110 return fActiveImage;
111 }
112
113 /**
114 * @return the whether the session is destroyed or not.
115 */
116 public boolean isDestroyed() {
117 return fIsDestroyed;
118 }
119
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 }
127
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 }
142
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.
160 * @param sessionPath - session path to set.
161 */
162 public void setSessionPath(String sessionPath) {
163 fSessionInfo.setSessionPath(sessionPath);
164 }
165
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
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
198 @Override
199 public Object getAdapter(Class adapter) {
200 if (adapter == IPropertySource.class) {
201 return new TraceSessionPropertySource(this);
202 }
203 return null;
204 }
205
206 /**
207 * @return all available domains of this session.
208 */
209 public TraceDomainComponent[] getDomains() {
210 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
211 return sessions.toArray(new TraceDomainComponent[sessions.size()]);
212 }
213
214 /**
215 * @return the parent target node
216 */
217 public TargetNodeComponent getTargetNode() {
218 return ((TraceSessionGroup)getParent()).getTargetNode();
219 }
220
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
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
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
247 // ------------------------------------------------------------------------
248 // Operations
249 // ------------------------------------------------------------------------
250
251 /**
252 * Retrieves the session configuration from the node.
253 *
254 * @param monitor
255 * - a progress monitor
256 * @throws ExecutionException
257 * If the command fails
258 */
259 public void getConfigurationFromNode(IProgressMonitor monitor)
260 throws ExecutionException {
261 removeAllChildren();
262 fSessionInfo = getControlService().getSession(getName(), monitor);
263
264 IDomainInfo[] domains = fSessionInfo.getDomains();
265 for (int i = 0; i < domains.length; i++) {
266 TraceDomainComponent domainComponent = new TraceDomainComponent(
267 domains[i].getName(), this);
268 addChild(domainComponent);
269 domainComponent.setDomainInfo(domains[i]);
270 }
271 }
272
273 /**
274 * Starts the session.
275 *
276 * @param monitor
277 * - a progress monitor
278 * @throws ExecutionException
279 * If the command fails
280 */
281 public void startSession(IProgressMonitor monitor)
282 throws ExecutionException {
283 getControlService().startSession(getName(), monitor);
284 }
285
286 /**
287 * Starts the session.
288 *
289 * @param monitor
290 * - a progress monitor
291 * @throws ExecutionException
292 * If the command fails
293 */
294 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
295 getControlService().stopSession(getName(), monitor);
296 }
297
298 /**
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
312 * @throws ExecutionException
313 * If the command fails
314 */
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);
320 }
321
322 /**
323 * Enables a list of events with no additional parameters.
324 *
325 * @param eventNames
326 * - a list of event names to enabled.
327 * @param isKernel
328 * - a flag for indicating kernel or UST.
329 * @param filterExpression
330 * - a filter expression
331 * @param monitor
332 * - a progress monitor
333 * @throws ExecutionException
334 * If the command fails
335 */
336 public void enableEvents(List<String> eventNames, boolean isKernel,
337 String filterExpression, IProgressMonitor monitor) throws ExecutionException {
338 getControlService().enableEvents(getName(), null, eventNames, isKernel,
339 filterExpression, monitor);
340 }
341
342 /**
343 * Enables all syscalls (for kernel domain)
344 *
345 * @param monitor
346 * - a progress monitor
347 * @throws ExecutionException
348 * If the command fails
349 */
350 public void enableSyscalls(IProgressMonitor monitor)
351 throws ExecutionException {
352 getControlService().enableSyscalls(getName(), null, monitor);
353 }
354
355 /**
356 * Enables a dynamic probe (for kernel domain)
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
366 * @throws ExecutionException
367 * If the command fails
368 */
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);
373 }
374
375 /**
376 * Enables events using log level.
377 *
378 * @param eventName
379 * - a event name
380 * @param logLevelType
381 * - a log level type
382 * @param level
383 * - a log level
384 * @param filterExpression
385 * - a filter expression
386 * @param monitor
387 * - a progress monitor
388 * @throws ExecutionException
389 * If the command fails
390 */
391 public void enableLogLevel(String eventName, LogLevelType logLevelType,
392 TraceLogLevel level, String filterExpression, IProgressMonitor monitor)
393 throws ExecutionException {
394 getControlService().enableLogLevel(getName(), null, eventName,
395 logLevelType, level, null, monitor);
396 }
397
398 /**
399 * Gets all available contexts to be added to channels/events.
400 *
401 * @param monitor
402 * The monitor that will indicate the progress
403 * @return the list of available contexts
404 * @throws ExecutionException
405 * If the command fails
406 */
407 public List<String> getContextList(IProgressMonitor monitor)
408 throws ExecutionException {
409 return getControlService().getContextList(monitor);
410 }
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 }
423 }
This page took 0.042898 seconds and 5 git commands to generate.