1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
;
14 import java
.util
.List
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
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 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
103 public Image
getImage() {
105 return fDestroyedImage
;
108 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
109 return super.getImage();
116 * @return the whether the session is destroyed or not.
118 public boolean isDestroyed() {
123 * Sets the session destroyed state to the given value.
124 * @param destroyed - value to set.
126 public void setDestroyed(boolean destroyed
) {
127 fIsDestroyed
= destroyed
;
131 * @return the session state state (active or inactive).
133 public TraceSessionState
getSessionState() {
134 return fSessionInfo
.getSessionState();
138 * Sets the session state to the given value.
139 * @param state - state to set.
141 public void setSessionState(TraceSessionState state
) {
142 fSessionInfo
.setSessionState(state
);
146 * Sets the event state to the value specified by the given name.
147 * @param stateName - state to set.
149 public void setSessionState(String stateName
) {
150 fSessionInfo
.setSessionState(stateName
);
154 * @return path string where session is located.
156 public String
getSessionPath() {
157 return fSessionInfo
.getSessionPath();
161 * Sets the path string (where session is located) to the given value.
162 * @param sessionPath - session path to set.
164 public void setSessionPath(String sessionPath
) {
165 fSessionInfo
.setSessionPath(sessionPath
);
169 * Returns if session is streamed over network
170 * @return <code>true</code> if streamed over network else <code>false</code>
172 public boolean isStreamedTrace() {
173 return fSessionInfo
.isStreamedTrace();
177 * Sets whether the trace is streamed or not
178 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
180 public void setIsStreamedTrace(boolean isStreamedTrace
) {
181 fSessionInfo
.setStreamedTrace(isStreamedTrace
);
186 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
189 public Object
getAdapter(Class adapter
) {
190 if (adapter
== IPropertySource
.class) {
191 return new TraceSessionPropertySource(this);
197 * @return all available domains of this session.
199 public TraceDomainComponent
[] getDomains() {
200 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
201 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
205 * @return the parent target node
207 public TargetNodeComponent
getTargetNode() {
208 return ((TraceSessionGroup
)getParent()).getTargetNode();
212 * Returns whether the kernel provider is available or not
213 * @return <code>true</code> if kernel provide is available or <code>false</code>
215 public boolean hasKernelProvider() {
216 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
217 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
221 * Returns if node supports filtering of events
222 * @return <code>true</code> if node supports filtering else <code>false</code>
224 public boolean isEventFilteringSupported() {
225 return ((TargetNodeComponent
)getParent().getParent()).isEventFilteringSupported();
228 // ------------------------------------------------------------------------
230 // ------------------------------------------------------------------------
233 * Retrieves the session configuration from the node.
235 * @throws ExecutionException
236 * If the command fails
238 public void getConfigurationFromNode() throws ExecutionException
{
239 getConfigurationFromNode(new NullProgressMonitor());
243 * Retrieves the session configuration from the node.
246 * - a progress monitor
247 * @throws ExecutionException
248 * If the command fails
250 public void getConfigurationFromNode(IProgressMonitor monitor
)
251 throws ExecutionException
{
253 fSessionInfo
= getControlService().getSession(getName(), monitor
);
254 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
255 for (int i
= 0; i
< domains
.length
; i
++) {
256 TraceDomainComponent domainComponent
= new TraceDomainComponent(
257 domains
[i
].getName(), this);
258 addChild(domainComponent
);
259 domainComponent
.setDomainInfo(domains
[i
]);
264 * Starts the session.
266 * @throws ExecutionException
267 * If the command fails
269 public void startSession() throws ExecutionException
{
270 startSession(new NullProgressMonitor());
274 * Starts the session.
277 * - a progress monitor
278 * @throws ExecutionException
279 * If the command fails
281 public void startSession(IProgressMonitor monitor
)
282 throws ExecutionException
{
283 getControlService().startSession(getName(), monitor
);
287 * Starts the session.
289 * @throws ExecutionException
290 * If the command fails
292 public void stopSession() throws ExecutionException
{
293 startSession(new NullProgressMonitor());
297 * Starts the session.
300 * - a progress monitor
301 * @throws ExecutionException
302 * If the command fails
304 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
305 getControlService().stopSession(getName(), monitor
);
309 * Enables channels with given names which are part of this domain. If a
310 * given channel doesn't exists it creates a new channel with the given
311 * parameters (or default values if given parameter is null).
313 * @param channelNames
314 * - a list of channel names to enable on this domain
316 * - channel information to set for the channel (use null for
319 * - a flag for indicating kernel or UST.
320 * @throws ExecutionException
321 * If the command fails
323 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
324 boolean isKernel
) throws ExecutionException
{
325 enableChannels(channelNames
, info
, isKernel
, new NullProgressMonitor());
329 * Enables channels with given names which are part of this domain. If a
330 * given channel doesn't exists it creates a new channel with the given
331 * parameters (or default values if given parameter is null).
333 * @param channelNames
334 * - a list of channel names to enable on this domain
336 * - channel information to set for the channel (use null for
339 * - a flag for indicating kernel or UST.
341 * - a progress monitor
342 * @throws ExecutionException
343 * If the command fails
345 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
346 boolean isKernel
, IProgressMonitor monitor
)
347 throws ExecutionException
{
348 getControlService().enableChannels(getName(), channelNames
, isKernel
,
353 * Enables a list of events with no additional parameters.
356 * - a list of event names to enabled.
358 * - a flag for indicating kernel or UST.
359 * @param filterExpression
360 * - a filter expression
361 * @throws ExecutionException
362 * If the command fails
364 public void enableEvent(List
<String
> eventNames
, boolean isKernel
, String filterExpression
)
365 throws ExecutionException
{
366 enableEvents(eventNames
, isKernel
, filterExpression
, new NullProgressMonitor());
370 * Enables a list of events with no additional parameters.
373 * - a list of event names to enabled.
375 * - a flag for indicating kernel or UST.
376 * @param filterExpression
377 * - a filter expression
379 * - a progress monitor
380 * @throws ExecutionException
381 * If the command fails
383 public void enableEvents(List
<String
> eventNames
, boolean isKernel
,
384 String filterExpression
, IProgressMonitor monitor
) throws ExecutionException
{
385 getControlService().enableEvents(getName(), null, eventNames
, isKernel
,
386 filterExpression
, monitor
);
390 * Enables all syscalls (for kernel domain)
392 * @throws ExecutionException
393 * If the command fails
395 public void enableSyscalls() throws ExecutionException
{
396 enableSyscalls(new NullProgressMonitor());
400 * Enables all syscalls (for kernel domain)
403 * - a progress monitor
404 * @throws ExecutionException
405 * If the command fails
407 public void enableSyscalls(IProgressMonitor monitor
)
408 throws ExecutionException
{
409 getControlService().enableSyscalls(getName(), null, monitor
);
413 * Enables a dynamic probe (for kernel domain)
416 * - event name for probe
418 * - true for dynamic function entry/return probe else false
421 * @throws ExecutionException
422 * If the command fails
424 public void enableProbe(String eventName
, boolean isFunction
, String probe
)
425 throws ExecutionException
{
426 enableProbe(eventName
, isFunction
, probe
, new NullProgressMonitor());
430 * Enables a dynamic probe (for kernel domain)
433 * - event name for probe
435 * - true for dynamic function entry/return probe else false
439 * - a progress monitor
440 * @throws ExecutionException
441 * If the command fails
443 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
444 IProgressMonitor monitor
) throws ExecutionException
{
445 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
450 * Enables events using log level.
454 * @param logLevelType
458 * @param filterExpression
459 * - a filter expression
460 * @throws ExecutionException
461 * If the command fails
463 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
464 TraceLogLevel level
, String filterExpression
) throws ExecutionException
{
465 enableLogLevel(eventName
, logLevelType
, level
, filterExpression
,
466 new NullProgressMonitor());
470 * Enables events using log level.
474 * @param logLevelType
478 * @param filterExpression
479 * - a filter expression
481 * - a progress monitor
482 * @throws ExecutionException
483 * If the command fails
485 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
486 TraceLogLevel level
, String filterExpression
, IProgressMonitor monitor
)
487 throws ExecutionException
{
488 getControlService().enableLogLevel(getName(), null, eventName
,
489 logLevelType
, level
, null, monitor
);
493 * Gets all available contexts to be added to channels/events.
495 * @return the list of available contexts
496 * @throws ExecutionException
497 * If the command fails
499 public List
<String
> getContextList() throws ExecutionException
{
500 return getContextList(new NullProgressMonitor());
504 * Gets all available contexts to be added to channels/events.
507 * The monitor that will indicate the progress
508 * @return the list of available contexts
509 * @throws ExecutionException
510 * If the command fails
512 public List
<String
> getContextList(IProgressMonitor monitor
)
513 throws ExecutionException
{
514 return getControlService().getContextList(monitor
);