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
);
170 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
173 public Object
getAdapter(Class adapter
) {
174 if (adapter
== IPropertySource
.class) {
175 return new TraceSessionPropertySource(this);
181 * @return all available domains of this session.
183 public TraceDomainComponent
[] getDomains() {
184 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
185 return sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
189 * @return the parent target node
191 public TargetNodeComponent
getTargetNode() {
192 return ((TraceSessionGroup
)getParent()).getTargetNode();
196 * Returns whether the kernel provider is available or not
197 * @return <code>true</code> if kernel provide is available or <code>false</code>
199 public boolean hasKernelProvider() {
200 List
<ITraceControlComponent
> providerGroups
= getTargetNode().getChildren(TraceProviderGroup
.class);
201 return (!providerGroups
.isEmpty() ?
((TraceProviderGroup
) providerGroups
.get(0)).hasKernelProvider() : false);
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
209 * Retrieves the session configuration from the node.
211 * @throws ExecutionException
212 * If the command fails
214 public void getConfigurationFromNode() throws ExecutionException
{
215 getConfigurationFromNode(new NullProgressMonitor());
219 * Retrieves the session configuration from the node.
222 * - a progress monitor
223 * @throws ExecutionException
224 * If the command fails
226 public void getConfigurationFromNode(IProgressMonitor monitor
)
227 throws ExecutionException
{
229 fSessionInfo
= getControlService().getSession(getName(), monitor
);
230 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
231 for (int i
= 0; i
< domains
.length
; i
++) {
232 TraceDomainComponent domainComponent
= new TraceDomainComponent(
233 domains
[i
].getName(), this);
234 addChild(domainComponent
);
235 domainComponent
.setDomainInfo(domains
[i
]);
240 * Starts the session.
242 * @throws ExecutionException
243 * If the command fails
245 public void startSession() throws ExecutionException
{
246 startSession(new NullProgressMonitor());
250 * Starts the session.
253 * - a progress monitor
254 * @throws ExecutionException
255 * If the command fails
257 public void startSession(IProgressMonitor monitor
)
258 throws ExecutionException
{
259 getControlService().startSession(getName(), monitor
);
263 * Starts the session.
265 * @throws ExecutionException
266 * If the command fails
268 public void stopSession() throws ExecutionException
{
269 startSession(new NullProgressMonitor());
273 * Starts the session.
276 * - a progress monitor
277 * @throws ExecutionException
278 * If the command fails
280 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
281 getControlService().stopSession(getName(), monitor
);
285 * Enables channels with given names which are part of this domain. If a
286 * given channel doesn't exists it creates a new channel with the given
287 * parameters (or default values if given parameter is null).
289 * @param channelNames
290 * - a list of channel names to enable on this domain
292 * - channel information to set for the channel (use null for
295 * - a flag for indicating kernel or UST.
296 * @throws ExecutionException
297 * If the command fails
299 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
300 boolean isKernel
) throws ExecutionException
{
301 enableChannels(channelNames
, info
, isKernel
, new NullProgressMonitor());
305 * Enables channels with given names which are part of this domain. If a
306 * given channel doesn't exists it creates a new channel with the given
307 * parameters (or default values if given parameter is null).
309 * @param channelNames
310 * - a list of channel names to enable on this domain
312 * - channel information to set for the channel (use null for
315 * - a flag for indicating kernel or UST.
317 * - a progress monitor
318 * @throws ExecutionException
319 * If the command fails
321 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
,
322 boolean isKernel
, IProgressMonitor monitor
)
323 throws ExecutionException
{
324 getControlService().enableChannels(getName(), channelNames
, isKernel
,
329 * Enables a list of events with no additional parameters.
332 * - a list of event names to enabled.
334 * - a flag for indicating kernel or UST.
335 * @throws ExecutionException
336 * If the command fails
338 public void enableEvent(List
<String
> eventNames
, boolean isKernel
)
339 throws ExecutionException
{
340 enableEvents(eventNames
, isKernel
, new NullProgressMonitor());
344 * Enables a list of events with no additional parameters.
347 * - a list of event names to enabled.
349 * - a flag for indicating kernel or UST.
351 * - a progress monitor
352 * @throws ExecutionException
353 * If the command fails
355 public void enableEvents(List
<String
> eventNames
, boolean isKernel
,
356 IProgressMonitor monitor
) throws ExecutionException
{
357 getControlService().enableEvents(getName(), null, eventNames
, isKernel
,
362 * Enables all syscalls (for kernel domain)
364 * @throws ExecutionException
365 * If the command fails
367 public void enableSyscalls() throws ExecutionException
{
368 enableSyscalls(new NullProgressMonitor());
372 * Enables all syscalls (for kernel domain)
375 * - a progress monitor
376 * @throws ExecutionException
377 * If the command fails
379 public void enableSyscalls(IProgressMonitor monitor
)
380 throws ExecutionException
{
381 getControlService().enableSyscalls(getName(), null, monitor
);
385 * Enables a dynamic probe (for kernel domain)
388 * - event name for probe
390 * - true for dynamic function entry/return probe else false
393 * @throws ExecutionException
394 * If the command fails
396 public void enableProbe(String eventName
, boolean isFunction
, String probe
)
397 throws ExecutionException
{
398 enableProbe(eventName
, isFunction
, probe
, new NullProgressMonitor());
402 * Enables a dynamic probe (for kernel domain)
405 * - event name for probe
407 * - true for dynamic function entry/return probe else false
411 * - a progress monitor
412 * @throws ExecutionException
413 * If the command fails
415 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
416 IProgressMonitor monitor
) throws ExecutionException
{
417 getControlService().enableProbe(getName(), null, eventName
, isFunction
,
422 * Enables events using log level.
426 * @param logLevelType
430 * @throws ExecutionException
431 * If the command fails
433 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
434 TraceLogLevel level
) throws ExecutionException
{
435 enableLogLevel(eventName
, logLevelType
, level
,
436 new NullProgressMonitor());
440 * Enables events using log level.
444 * @param logLevelType
449 * - a progress monitor
450 * @throws ExecutionException
451 * If the command fails
453 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
454 TraceLogLevel level
, IProgressMonitor monitor
)
455 throws ExecutionException
{
456 getControlService().enableLogLevel(getName(), null, eventName
,
457 logLevelType
, level
, monitor
);
461 * Gets all available contexts to be added to channels/events.
463 * @return the list of available contexts
464 * @throws ExecutionException
465 * If the command fails
467 public List
<String
> getContextList() throws ExecutionException
{
468 return getContextList(new NullProgressMonitor());
472 * Gets all available contexts to be added to channels/events.
475 * The monitor that will indicate the progress
476 * @return the list of available contexts
477 * @throws ExecutionException
478 * If the command fails
480 public List
<String
> getContextList(IProgressMonitor monitor
)
481 throws ExecutionException
{
482 return getControlService().getContextList(monitor
);