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
;
34 * <b><u>TraceSessionComponent</u></b>
36 * Implementation of the trace session component.
39 public class TraceSessionComponent
extends TraceControlComponent
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 * Path to icon file for this component (inactive state).
47 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
49 * Path to icon file for this component (active state).
51 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
53 * Path to icon file for this component (destroyed state).
55 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 * The session information.
63 private ISessionInfo fSessionInfo
= null;
65 * A flag to indicate if session has been destroyed.
67 private boolean fIsDestroyed
= false;
69 * The image to be displayed in state active.
71 private Image fActiveImage
= null;
73 * The image to be displayed in state destroyed
75 private Image fDestroyedImage
= null;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 * @param name - the name of the component.
83 * @param parent - the parent of this component.
85 public TraceSessionComponent(String name
, ITraceControlComponent parent
) {
87 setImage(TRACE_SESSION_ICON_FILE_INACTIVE
);
88 setToolTip(Messages
.TraceControl_SessionDisplayName
);
89 fSessionInfo
= new SessionInfo(name
);
90 fActiveImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE
);
91 fDestroyedImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED
);
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
102 public Image
getImage() {
104 return fDestroyedImage
;
107 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
108 return super.getImage();
115 * @return the whether the session is destroyed or not.
117 public boolean isDestroyed() {
122 * Sets the session destroyed state to the given value.
123 * @param destroyed - value to set.
125 public void setDestroyed(boolean destroyed
) {
126 fIsDestroyed
= destroyed
;
130 * @return the session state state (active or inactive).
132 public TraceSessionState
getSessionState() {
133 return fSessionInfo
.getSessionState();
137 * Sets the session state to the given value.
138 * @param state - state to set.
140 public void setSessionState(TraceSessionState state
) {
141 fSessionInfo
.setSessionState(state
);
145 * Sets the event state to the value specified by the given name.
146 * @param stateName - state to set.
148 public void setSessionState(String stateName
) {
149 fSessionInfo
.setSessionState(stateName
);
153 * @return path string where session is located.
155 public String
getSessionPath() {
156 return fSessionInfo
.getSessionPath();
160 * Sets the path string (where session is located) to the given value.
161 * @param path - session path to set.
163 public void setSessionPath(String sessionPath
) {
164 fSessionInfo
.setSessionPath(sessionPath
);
169 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
171 @SuppressWarnings("rawtypes")
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 (TraceDomainComponent
[])sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
189 * @return the parent target node
191 public TargetNodeComponent
getTargetNode() {
192 return ((TraceSessionGroup
)getParent()).getTargetNode();
195 // ------------------------------------------------------------------------
197 // ------------------------------------------------------------------------
199 * Retrieves the session configuration from the node.
200 * @throws ExecutionException
202 public void getConfigurationFromNode() throws ExecutionException
{
203 getConfigurationFromNode(new NullProgressMonitor());
207 * Retrieves the session configuration from the node.
208 * @param monitor - a progress monitor
209 * @throws ExecutionException
211 public void getConfigurationFromNode(IProgressMonitor monitor
) throws ExecutionException
{
213 fSessionInfo
= getControlService().getSession(getName(), monitor
);
214 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
215 for (int i
= 0; i
< domains
.length
; i
++) {
216 TraceDomainComponent domainComponent
= new TraceDomainComponent(domains
[i
].getName(), this);
217 addChild(domainComponent
);
218 domainComponent
.setDomainInfo(domains
[i
]);
223 * Starts the session.
224 * throws ExecutionExecption
226 public void startSession() throws ExecutionException
{
227 startSession(new NullProgressMonitor());
231 * Starts the session.
232 * @param monitor - a progress monitor
233 * throws ExecutionExecption
235 public void startSession(IProgressMonitor monitor
) throws ExecutionException
{
236 getControlService().startSession(getName(), monitor
);
240 * Starts the session.
241 * throws ExecutionExecption
243 public void stopSession() throws ExecutionException
{
244 startSession(new NullProgressMonitor());
248 * Starts the session.
249 * @param monitor - a progress monitor
250 * throws ExecutionExecption
252 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
253 getControlService().stopSession(getName(), monitor
);
257 * Enables channels with given names which are part of this domain. If a given channel
258 * doesn't exists it creates a new channel with the given parameters (or default values
259 * if given parameter is null).
260 * @param channelNames - a list of channel names to enable on this domain
261 * @param info - channel information to set for the channel (use null for default)
262 * @param isKernel - a flag for indicating kernel or UST.
263 * @throws ExecutionException
265 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
, boolean isKernel
) throws ExecutionException
{
266 enableChannels(channelNames
, info
, isKernel
, new NullProgressMonitor());
270 * Enables channels with given names which are part of this domain. If a given channel
271 * doesn't exists it creates a new channel with the given parameters (or default values
272 * if given parameter is null).
273 * @param channelNames - a list of channel names to enable on this domain
274 * @param info - channel information to set for the channel (use null for default)
275 * @param isKernel - a flag for indicating kernel or UST.
276 * @param monitor - a progress monitor
277 * @throws ExecutionException
279 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
280 getControlService().enableChannels(getName(), channelNames
, isKernel
, info
, monitor
);
284 * Enables a list of events with no additional parameters.
285 * @param eventNames - a list of event names to enabled.
286 * @param isKernel - a flag for indicating kernel or UST.
287 * @throws ExecutionException
289 public void enableEvent(List
<String
> eventNames
, boolean isKernel
) throws ExecutionException
{
290 enableEvents(eventNames
, isKernel
, new NullProgressMonitor());
294 * Enables a list of events with no additional parameters.
295 * @param eventNames - a list of event names to enabled.
296 * @param isKernel - a flag for indicating kernel or UST.
297 * @param monitor - a progress monitor
298 * @throws ExecutionException
300 public void enableEvents(List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
301 getControlService().enableEvents(getName(), null, eventNames
, isKernel
, monitor
);
305 * Enables all syscalls (for kernel domain)
306 * @throws ExecutionException
308 public void enableSyscalls() throws ExecutionException
{
309 enableSyscalls(new NullProgressMonitor());
313 * Enables all syscalls (for kernel domain)
314 * @param monitor - a progress monitor
315 * @throws ExecutionException
317 public void enableSyscalls(IProgressMonitor monitor
) throws ExecutionException
{
318 getControlService().enableSyscalls(getName(), null, monitor
);
322 * Enables a dynamic probe (for kernel domain)
323 * @param eventName - event name for probe
324 * @param isFunction - true for dynamic function entry/return probe else false
325 * @param probe - the actual probe
326 * @throws ExecutionException
328 public void enableProbe(String eventName
, boolean isFunction
, String probe
) throws ExecutionException
{
329 enableProbe(eventName
, isFunction
, probe
, new NullProgressMonitor());
333 * Enables a dynamic probe (for kernel domain)
334 * @param eventName - event name for probe
335 * @param isFunction - true for dynamic function entry/return probe else false
336 * @param probe - the actual probe
337 * @param monitor - a progress monitor
338 * @throws ExecutionException
340 public void enableProbe(String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
341 getControlService().enableProbe(getName(), null, eventName
, isFunction
, probe
, monitor
);
345 * Enables events using log level.
346 * @param eventName - a event name
347 * @param logLevelType - a log level type
348 * @param level - a log level
349 * @throws ExecutionException
351 public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
) throws ExecutionException
{
352 enableLogLevel(eventName
, logLevelType
, level
, new NullProgressMonitor());
356 * Enables events using log level.
357 * @param eventName - a event name
358 * @param logLevelType - a log level type
359 * @param level - a log level
360 * @param monitor - a progress monitor
361 * @throws ExecutionException
363 public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
364 getControlService().enableLogLevel(getName(), null, eventName
, logLevelType
, level
, monitor
);
368 * Gets all available contexts to be added to channels/events.
369 * @return the list of available contexts
371 public List
<String
> getContextList() throws ExecutionException
{
372 return getContextList(new NullProgressMonitor());
376 * Gets all available contexts to be added to channels/events.
378 * @return the list of available contexts
380 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
381 return getControlService().getContextList(monitor
);