1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
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
.ui
.views
.control
.model
.impl
;
15 import java
.util
.List
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
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
;
35 * Implementation of the trace session component.
38 * @author Bernd Hufmann
40 public class TraceSessionComponent
extends TraceControlComponent
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 * Path to icon file for this component (inactive state).
48 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
50 * Path to icon file for this component (active state).
52 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
54 * Path to icon file for this component (destroyed state).
56 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 * The session information.
64 private ISessionInfo fSessionInfo
= null;
66 * A flag to indicate if session has been destroyed.
68 private boolean fIsDestroyed
= false;
70 * The image to be displayed in state active.
72 private Image fActiveImage
= null;
74 * The image to be displayed in state destroyed
76 private Image fDestroyedImage
= null;
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 * @param name - the name of the component.
84 * @param parent - the parent of this component.
86 public TraceSessionComponent(String name
, ITraceControlComponent 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
);
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 public Image
getImage() {
102 return fDestroyedImage
;
105 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
106 return super.getImage();
113 * @return the whether the session is destroyed or not.
115 public boolean isDestroyed() {
120 * Sets the session destroyed state to the given value.
121 * @param destroyed - value to set.
123 public void setDestroyed(boolean destroyed
) {
124 fIsDestroyed
= destroyed
;
128 * @return the session state state (active or inactive).
130 public TraceSessionState
getSessionState() {
131 return fSessionInfo
.getSessionState();
135 * Sets the session state to the given value.
136 * @param state - state to set.
138 public void setSessionState(TraceSessionState state
) {
139 fSessionInfo
.setSessionState(state
);
143 * Sets the event state to the value specified by the given name.
144 * @param stateName - state to set.
146 public void setSessionState(String stateName
) {
147 fSessionInfo
.setSessionState(stateName
);
151 * @return path string where session is located.
153 public String
getSessionPath() {
154 return fSessionInfo
.getSessionPath();
158 * Sets the path string (where session is located) to the given value.
159 * @param sessionPath - session path to set.
161 public void setSessionPath(String sessionPath
) {
162 fSessionInfo
.setSessionPath(sessionPath
);
166 * Returns if session is streamed over network
167 * @return <code>true</code> if streamed over network else <code>false</code>
169 public boolean isStreamedTrace() {
170 return fSessionInfo
.isStreamedTrace();
174 * Sets whether the trace is streamed or not
175 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
177 public void setIsStreamedTrace(boolean isStreamedTrace
) {
178 fSessionInfo
.setStreamedTrace(isStreamedTrace
);
182 public Object
getAdapter(Class adapter
) {
183 if (adapter
== IPropertySource
.class) {
184 return new TraceSessionPropertySource(this);
190 * @return all available domains of this session.
192 public TraceDomainComponent
[] getDomains() {
193 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
194 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
198 * @return the parent target node
200 public TargetNodeComponent
getTargetNode() {
201 return ((TraceSessionGroup
)getParent()).getTargetNode();
205 * Returns whether the kernel provider is available or not
206 * @return <code>true</code> if kernel provide is available or <code>false</code>
208 public boolean hasKernelProvider() {
209 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
210 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
214 * Returns if node supports filtering of events
215 * @return <code>true</code> if node supports filtering else <code>false</code>
217 public boolean isEventFilteringSupported() {
218 return ((TargetNodeComponent
)getParent().getParent()).isEventFilteringSupported();
221 // ------------------------------------------------------------------------
223 // ------------------------------------------------------------------------
226 * Retrieves the session configuration from the node.
229 * - a progress monitor
230 * @throws ExecutionException
231 * If the command fails
233 public void getConfigurationFromNode(IProgressMonitor monitor
)
234 throws ExecutionException
{
236 fSessionInfo
= getControlService().getSession(getName(), monitor
);
237 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
238 for (int i
= 0; i
< domains
.length
; i
++) {
239 TraceDomainComponent domainComponent
= new TraceDomainComponent(
240 domains
[i
].getName(), this);
241 addChild(domainComponent
);
242 domainComponent
.setDomainInfo(domains
[i
]);
247 * Starts the session.
250 * - a progress monitor
251 * @throws ExecutionException
252 * If the command fails
254 public void startSession(IProgressMonitor monitor
)
255 throws ExecutionException
{
256 getControlService().startSession(getName(), monitor
);
260 * Starts the session.
263 * - a progress monitor
264 * @throws ExecutionException
265 * If the command fails
267 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
268 getControlService().stopSession(getName(), monitor
);
272 * Enables channels with given names which are part of this domain. If a
273 * given channel doesn't exists it creates a new channel with the given
274 * parameters (or default values if given parameter is null).
276 * @param channelNames
277 * - a list of channel names to enable on this domain
279 * - channel information to set for the channel (use null for
282 * - a flag for indicating kernel or UST.
284 * - a progress monitor
285 * @throws ExecutionException
286 * If the command fails
288 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
289 boolean isKernel
, IProgressMonitor monitor
)
290 throws ExecutionException
{
291 getControlService().enableChannels(getName(), channelNames
, isKernel
,
296 * Enables a list of events with no additional parameters.
299 * - a list of event names to enabled.
301 * - a flag for indicating kernel or UST.
302 * @param filterExpression
303 * - a filter expression
305 * - a progress monitor
306 * @throws ExecutionException
307 * If the command fails
309 public void enableEvents(List
<String
> eventNames
, boolean isKernel
,
310 String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
311 getControlService().enableEvents(getName(), null, eventNames
, isKernel
,
312 filterExpression
, monitor
);
316 * Enables all syscalls (for kernel domain)
319 * - a progress monitor
320 * @throws ExecutionException
321 * If the command fails
323 public void enableSyscalls(IProgressMonitor monitor
)
324 throws ExecutionException
{
325 getControlService().enableSyscalls(getName(), null, monitor
);
329 * Enables a dynamic probe (for kernel domain)
332 * - event name for probe
334 * - true for dynamic function entry/return probe else false
338 * - a progress monitor
339 * @throws ExecutionException
340 * If the command fails
342 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
343 IProgressMonitor monitor
) throws ExecutionException
{
344 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
349 * Enables events using log level.
353 * @param logLevelType
357 * @param filterExpression
358 * - a filter expression
360 * - a progress monitor
361 * @throws ExecutionException
362 * If the command fails
364 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
365 TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
)
366 throws ExecutionException
{
367 getControlService().enableLogLevel(getName(), null, eventName
,
368 logLevelType
, level
, null, monitor
);
372 * Gets all available contexts to be added to channels/events.
375 * The monitor that will indicate the progress
376 * @return the list of available contexts
377 * @throws ExecutionException
378 * If the command fails
380 public List
<String
> getContextList(IProgressMonitor monitor
)
381 throws ExecutionException
{
382 return getControlService().getContextList(monitor
);