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
.ui
.Activator
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IChannelInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IDomainInfo
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ISessionInfo
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.LogLevelType
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceSessionState
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.property
.TraceSessionPropertySource
;
29 import org
.eclipse
.swt
.graphics
.Image
;
30 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
33 * <b><u>TraceSessionComponent</u></b>
35 * Implementation of the trace session component.
38 public class TraceSessionComponent
extends TraceControlComponent
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 * Path to icon file for this component (inactive state).
46 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
48 * Path to icon file for this component (active state).
50 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
52 * Path to icon file for this component (destroyed state).
54 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 * The session information.
62 private ISessionInfo fSessionInfo
= null;
64 * A flag to indicate if session has been destroyed.
66 private boolean fIsDestroyed
= false;
68 * The image to be displayed in state active.
70 private Image fActiveImage
= null;
72 * The image to be displayed in state destroyed
74 private Image fDestroyedImage
= null;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * @param name - the name of the component.
82 * @param parent - the parent of this component.
84 public TraceSessionComponent(String name
, ITraceControlComponent parent
) {
86 setImage(TRACE_SESSION_ICON_FILE_INACTIVE
);
87 setToolTip(Messages
.TraceControl_SessionDisplayName
);
88 fSessionInfo
= new SessionInfo(name
);
89 fActiveImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE
);
90 fDestroyedImage
= Activator
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED
);
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
101 public Image
getImage() {
103 return fDestroyedImage
;
106 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
107 return super.getImage();
114 * @return the whether the session is destroyed or not.
116 public boolean isDestroyed() {
121 * Sets the session destroyed state to the given value.
122 * @param destroyed - value to set.
124 public void setDestroyed(boolean destroyed
) {
125 fIsDestroyed
= destroyed
;
129 * @return the session state state (active or inactive).
131 public TraceSessionState
getSessionState() {
132 return fSessionInfo
.getSessionState();
136 * Sets the session state to the given value.
137 * @param state - state to set.
139 public void setSessionState(TraceSessionState state
) {
140 fSessionInfo
.setSessionState(state
);
144 * Sets the event state to the value specified by the given name.
145 * @param stateName - state to set.
147 public void setSessionState(String stateName
) {
148 fSessionInfo
.setSessionState(stateName
);
152 * @return path string where session is located.
154 public String
getSessionPath() {
155 return fSessionInfo
.getSessionPath();
159 * Sets the path string (where session is located) to the given value.
160 * @param path - session path to set.
162 public void setSessionPath(String sessionPath
) {
163 fSessionInfo
.setSessionPath(sessionPath
);
168 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
170 @SuppressWarnings("rawtypes")
172 public Object
getAdapter(Class adapter
) {
173 if (adapter
== IPropertySource
.class) {
174 return new TraceSessionPropertySource(this);
180 * @return all available domains of this session.
182 public TraceDomainComponent
[] getDomains() {
183 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
184 return (TraceDomainComponent
[])sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
188 * @return the parent target node
190 public TargetNodeComponent
getTargetNode() {
191 return ((TraceSessionGroup
)getParent()).getTargetNode();
194 // ------------------------------------------------------------------------
196 // ------------------------------------------------------------------------
198 * Retrieves the session configuration from the node.
199 * @throws ExecutionException
201 public void getConfigurationFromNode() throws ExecutionException
{
202 getConfigurationFromNode(new NullProgressMonitor());
206 * Retrieves the session configuration from the node.
207 * @param monitor - a progress monitor
208 * @throws ExecutionException
210 public void getConfigurationFromNode(IProgressMonitor monitor
) throws ExecutionException
{
212 fSessionInfo
= getControlService().getSession(getName(), monitor
);
213 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
214 for (int i
= 0; i
< domains
.length
; i
++) {
215 TraceDomainComponent domainComponent
= new TraceDomainComponent(domains
[i
].getName(), this);
216 addChild(domainComponent
);
217 domainComponent
.setDomainInfo(domains
[i
]);
222 * Starts the session.
223 * throws ExecutionExecption
225 public void startSession() throws ExecutionException
{
226 startSession(new NullProgressMonitor());
230 * Starts the session.
231 * @param monitor - a progress monitor
232 * throws ExecutionExecption
234 public void startSession(IProgressMonitor monitor
) throws ExecutionException
{
235 getControlService().startSession(getName(), monitor
);
239 * Starts the session.
240 * throws ExecutionExecption
242 public void stopSession() throws ExecutionException
{
243 startSession(new NullProgressMonitor());
247 * Starts the session.
248 * @param monitor - a progress monitor
249 * throws ExecutionExecption
251 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
252 getControlService().stopSession(getName(), monitor
);
256 * Enables channels with given names which are part of this domain. If a given channel
257 * doesn't exists it creates a new channel with the given parameters (or default values
258 * if given parameter is null).
259 * @param channelNames - a list of channel names to enable on this domain
260 * @param info - channel information to set for the channel (use null for default)
261 * @param isKernel - a flag for indicating kernel or UST.
262 * @throws ExecutionException
264 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
, boolean isKernel
) throws ExecutionException
{
265 enableChannels(channelNames
, info
, isKernel
, new NullProgressMonitor());
269 * Enables channels with given names which are part of this domain. If a given channel
270 * doesn't exists it creates a new channel with the given parameters (or default values
271 * if given parameter is null).
272 * @param channelNames - a list of channel names to enable on this domain
273 * @param info - channel information to set for the channel (use null for default)
274 * @param isKernel - a flag for indicating kernel or UST.
275 * @param monitor - a progress monitor
276 * @throws ExecutionException
278 public void enableChannels(List
<String
> channelNames
, IChannelInfo info
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
279 getControlService().enableChannels(getName(), channelNames
, isKernel
, info
, monitor
);
283 * Enables a list of events with no additional parameters.
284 * @param eventNames - a list of event names to enabled.
285 * @param isKernel - a flag for indicating kernel or UST.
286 * @throws ExecutionException
288 public void enableEvent(List
<String
> eventNames
, boolean isKernel
) throws ExecutionException
{
289 enableEvents(eventNames
, isKernel
, new NullProgressMonitor());
293 * Enables a list of events with no additional parameters.
294 * @param eventNames - a list of event names to enabled.
295 * @param isKernel - a flag for indicating kernel or UST.
296 * @param monitor - a progress monitor
297 * @throws ExecutionException
299 public void enableEvents(List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
300 getControlService().enableEvents(getName(), null, eventNames
, isKernel
, monitor
);
304 * Enables all syscalls (for kernel domain)
305 * @throws ExecutionException
307 public void enableSyscalls() throws ExecutionException
{
308 enableSyscalls(new NullProgressMonitor());
312 * Enables all syscalls (for kernel domain)
313 * @param monitor - a progress monitor
314 * @throws ExecutionException
316 public void enableSyscalls(IProgressMonitor monitor
) throws ExecutionException
{
317 getControlService().enableSyscalls(getName(), null, monitor
);
321 * Enables a dynamic probe (for kernel domain)
322 * @param eventName - event name for probe
323 * @param isFunction - true for dynamic function entry/return probe else false
324 * @param probe - the actual probe
325 * @throws ExecutionException
327 public void enableProbe(String eventName
, boolean isFunction
, String probe
) throws ExecutionException
{
328 enableProbe(eventName
, isFunction
, probe
, new NullProgressMonitor());
332 * Enables a dynamic probe (for kernel domain)
333 * @param eventName - event name for probe
334 * @param isFunction - true for dynamic function entry/return probe else false
335 * @param probe - the actual probe
336 * @param monitor - a progress monitor
337 * @throws ExecutionException
339 public void enableProbe(String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
340 getControlService().enableProbe(getName(), null, eventName
, isFunction
, probe
, monitor
);
344 * Enables events using log level.
345 * @param eventName - a event name
346 * @param logLevelType - a log level type
347 * @param level - a log level
348 * @throws ExecutionException
350 public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
) throws ExecutionException
{
351 enableLogLevel(eventName
, logLevelType
, level
, new NullProgressMonitor());
355 * Enables events using log level.
356 * @param eventName - a event name
357 * @param logLevelType - a log level type
358 * @param level - a log level
359 * @param monitor - a progress monitor
360 * @throws ExecutionException
362 public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
363 getControlService().enableLogLevel(getName(), null, eventName
, logLevelType
, level
, monitor
);
367 * Gets all available contexts to be added to channels/events.
368 * @return the list of available contexts
370 public List
<String
> getContextList() throws ExecutionException
{
371 return getContextList(new NullProgressMonitor());
375 * Gets all available contexts to be added to channels/events.
377 * @return the list of available contexts
379 public List
<String
> getContextList(IProgressMonitor monitor
) throws ExecutionException
{
380 return getControlService().getContextList(monitor
);