Update file headers in LTTng Control feature
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / model / impl / TraceSessionComponent.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
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;
14
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.NullProgressMonitor;
20 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
21 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
22 import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
23 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
24 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
25 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
26 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo;
27 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
28 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
29 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
30 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceSessionPropertySource;
31 import org.eclipse.swt.graphics.Image;
32 import org.eclipse.ui.views.properties.IPropertySource;
33
34 /**
35 * <p>
36 * Implementation of the trace session component.
37 * </p>
38 *
39 * @author Bernd Hufmann
40 */
41 public class TraceSessionComponent extends TraceControlComponent {
42
43 // ------------------------------------------------------------------------
44 // Constants
45 // ------------------------------------------------------------------------
46 /**
47 * Path to icon file for this component (inactive state).
48 */
49 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
50 /**
51 * Path to icon file for this component (active state).
52 */
53 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
54 /**
55 * Path to icon file for this component (destroyed state).
56 */
57 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
58
59 // ------------------------------------------------------------------------
60 // Attributes
61 // ------------------------------------------------------------------------
62 /**
63 * The session information.
64 */
65 private ISessionInfo fSessionInfo = null;
66 /**
67 * A flag to indicate if session has been destroyed.
68 */
69 private boolean fIsDestroyed = false;
70 /**
71 * The image to be displayed in state active.
72 */
73 private Image fActiveImage = null;
74 /**
75 * The image to be displayed in state destroyed
76 */
77 private Image fDestroyedImage = null;
78
79 // ------------------------------------------------------------------------
80 // Constructors
81 // ------------------------------------------------------------------------
82 /**
83 * Constructor
84 * @param name - the name of the component.
85 * @param parent - the parent of this component.
86 */
87 public TraceSessionComponent(String name, ITraceControlComponent parent) {
88 super(name, parent);
89 setImage(TRACE_SESSION_ICON_FILE_INACTIVE);
90 setToolTip(Messages.TraceControl_SessionDisplayName);
91 fSessionInfo = new SessionInfo(name);
92 fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
93 fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
94 }
95
96 // ------------------------------------------------------------------------
97 // Accessors
98 // ------------------------------------------------------------------------
99 /*
100 * (non-Javadoc)
101 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
102 */
103 @Override
104 public Image getImage() {
105 if (fIsDestroyed) {
106 return fDestroyedImage;
107 }
108
109 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
110 return super.getImage();
111 }
112
113 return fActiveImage;
114 }
115
116 /**
117 * @return the whether the session is destroyed or not.
118 */
119 public boolean isDestroyed() {
120 return fIsDestroyed;
121 }
122
123 /**
124 * Sets the session destroyed state to the given value.
125 * @param destroyed - value to set.
126 */
127 public void setDestroyed(boolean destroyed) {
128 fIsDestroyed = destroyed;
129 }
130
131 /**
132 * @return the session state state (active or inactive).
133 */
134 public TraceSessionState getSessionState() {
135 return fSessionInfo.getSessionState();
136 }
137
138 /**
139 * Sets the session state to the given value.
140 * @param state - state to set.
141 */
142 public void setSessionState(TraceSessionState state) {
143 fSessionInfo.setSessionState(state);
144 }
145
146 /**
147 * Sets the event state to the value specified by the given name.
148 * @param stateName - state to set.
149 */
150 public void setSessionState(String stateName) {
151 fSessionInfo.setSessionState(stateName);
152 }
153
154 /**
155 * @return path string where session is located.
156 */
157 public String getSessionPath() {
158 return fSessionInfo.getSessionPath();
159 }
160
161 /**
162 * Sets the path string (where session is located) to the given value.
163 * @param sessionPath - session path to set.
164 */
165 public void setSessionPath(String sessionPath) {
166 fSessionInfo.setSessionPath(sessionPath);
167 }
168
169 /**
170 * Returns if session is streamed over network
171 * @return <code>true</code> if streamed over network else <code>false</code>
172 */
173 public boolean isStreamedTrace() {
174 return fSessionInfo.isStreamedTrace();
175 }
176
177 /**
178 * Sets whether the trace is streamed or not
179 * @param isStreamedTrace <code>true</code> if streamed over network else <code>false</code>
180 */
181 public void setIsStreamedTrace(boolean isStreamedTrace) {
182 fSessionInfo.setStreamedTrace(isStreamedTrace);
183 }
184
185 /*
186 * (non-Javadoc)
187 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
188 */
189 @Override
190 public Object getAdapter(Class adapter) {
191 if (adapter == IPropertySource.class) {
192 return new TraceSessionPropertySource(this);
193 }
194 return null;
195 }
196
197 /**
198 * @return all available domains of this session.
199 */
200 public TraceDomainComponent[] getDomains() {
201 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
202 return sessions.toArray(new TraceDomainComponent[sessions.size()]);
203 }
204
205 /**
206 * @return the parent target node
207 */
208 public TargetNodeComponent getTargetNode() {
209 return ((TraceSessionGroup)getParent()).getTargetNode();
210 }
211
212 /**
213 * Returns whether the kernel provider is available or not
214 * @return <code>true</code> if kernel provide is available or <code>false</code>
215 */
216 public boolean hasKernelProvider() {
217 List<ITraceControlComponent> providerGroups = getTargetNode().getChildren(TraceProviderGroup.class);
218 return (!providerGroups.isEmpty() ? ((TraceProviderGroup) providerGroups.get(0)).hasKernelProvider() : false);
219 }
220
221 /**
222 * Returns if node supports filtering of events
223 * @return <code>true</code> if node supports filtering else <code>false</code>
224 */
225 public boolean isEventFilteringSupported() {
226 return ((TargetNodeComponent)getParent().getParent()).isEventFilteringSupported();
227 }
228
229 // ------------------------------------------------------------------------
230 // Operations
231 // ------------------------------------------------------------------------
232
233 /**
234 * Retrieves the session configuration from the node.
235 *
236 * @throws ExecutionException
237 * If the command fails
238 */
239 public void getConfigurationFromNode() throws ExecutionException {
240 getConfigurationFromNode(new NullProgressMonitor());
241 }
242
243 /**
244 * Retrieves the session configuration from the node.
245 *
246 * @param monitor
247 * - a progress monitor
248 * @throws ExecutionException
249 * If the command fails
250 */
251 public void getConfigurationFromNode(IProgressMonitor monitor)
252 throws ExecutionException {
253 removeAllChildren();
254 fSessionInfo = getControlService().getSession(getName(), monitor);
255 IDomainInfo[] domains = fSessionInfo.getDomains();
256 for (int i = 0; i < domains.length; i++) {
257 TraceDomainComponent domainComponent = new TraceDomainComponent(
258 domains[i].getName(), this);
259 addChild(domainComponent);
260 domainComponent.setDomainInfo(domains[i]);
261 }
262 }
263
264 /**
265 * Starts the session.
266 *
267 * @throws ExecutionException
268 * If the command fails
269 */
270 public void startSession() throws ExecutionException {
271 startSession(new NullProgressMonitor());
272 }
273
274 /**
275 * Starts the session.
276 *
277 * @param monitor
278 * - a progress monitor
279 * @throws ExecutionException
280 * If the command fails
281 */
282 public void startSession(IProgressMonitor monitor)
283 throws ExecutionException {
284 getControlService().startSession(getName(), monitor);
285 }
286
287 /**
288 * Starts the session.
289 *
290 * @throws ExecutionException
291 * If the command fails
292 */
293 public void stopSession() throws ExecutionException {
294 startSession(new NullProgressMonitor());
295 }
296
297 /**
298 * Starts the session.
299 *
300 * @param monitor
301 * - a progress monitor
302 * @throws ExecutionException
303 * If the command fails
304 */
305 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
306 getControlService().stopSession(getName(), monitor);
307 }
308
309 /**
310 * Enables channels with given names which are part of this domain. If a
311 * given channel doesn't exists it creates a new channel with the given
312 * parameters (or default values if given parameter is null).
313 *
314 * @param channelNames
315 * - a list of channel names to enable on this domain
316 * @param info
317 * - channel information to set for the channel (use null for
318 * default)
319 * @param isKernel
320 * - a flag for indicating kernel or UST.
321 * @throws ExecutionException
322 * If the command fails
323 */
324 public void enableChannels(List<String> channelNames, IChannelInfo info,
325 boolean isKernel) throws ExecutionException {
326 enableChannels(channelNames, info, isKernel, new NullProgressMonitor());
327 }
328
329 /**
330 * Enables channels with given names which are part of this domain. If a
331 * given channel doesn't exists it creates a new channel with the given
332 * parameters (or default values if given parameter is null).
333 *
334 * @param channelNames
335 * - a list of channel names to enable on this domain
336 * @param info
337 * - channel information to set for the channel (use null for
338 * default)
339 * @param isKernel
340 * - a flag for indicating kernel or UST.
341 * @param monitor
342 * - a progress monitor
343 * @throws ExecutionException
344 * If the command fails
345 */
346 public void enableChannels(List<String> channelNames, IChannelInfo info,
347 boolean isKernel, IProgressMonitor monitor)
348 throws ExecutionException {
349 getControlService().enableChannels(getName(), channelNames, isKernel,
350 info, monitor);
351 }
352
353 /**
354 * Enables a list of events with no additional parameters.
355 *
356 * @param eventNames
357 * - a list of event names to enabled.
358 * @param isKernel
359 * - a flag for indicating kernel or UST.
360 * @param filterExpression
361 * - a filter expression
362 * @throws ExecutionException
363 * If the command fails
364 */
365 public void enableEvent(List<String> eventNames, boolean isKernel, String filterExpression)
366 throws ExecutionException {
367 enableEvents(eventNames, isKernel, filterExpression, new NullProgressMonitor());
368 }
369
370 /**
371 * Enables a list of events with no additional parameters.
372 *
373 * @param eventNames
374 * - a list of event names to enabled.
375 * @param isKernel
376 * - a flag for indicating kernel or UST.
377 * @param filterExpression
378 * - a filter expression
379 * @param monitor
380 * - a progress monitor
381 * @throws ExecutionException
382 * If the command fails
383 */
384 public void enableEvents(List<String> eventNames, boolean isKernel,
385 String filterExpression, IProgressMonitor monitor) throws ExecutionException {
386 getControlService().enableEvents(getName(), null, eventNames, isKernel,
387 filterExpression, monitor);
388 }
389
390 /**
391 * Enables all syscalls (for kernel domain)
392 *
393 * @throws ExecutionException
394 * If the command fails
395 */
396 public void enableSyscalls() throws ExecutionException {
397 enableSyscalls(new NullProgressMonitor());
398 }
399
400 /**
401 * Enables all syscalls (for kernel domain)
402 *
403 * @param monitor
404 * - a progress monitor
405 * @throws ExecutionException
406 * If the command fails
407 */
408 public void enableSyscalls(IProgressMonitor monitor)
409 throws ExecutionException {
410 getControlService().enableSyscalls(getName(), null, monitor);
411 }
412
413 /**
414 * Enables a dynamic probe (for kernel domain)
415 *
416 * @param eventName
417 * - event name for probe
418 * @param isFunction
419 * - true for dynamic function entry/return probe else false
420 * @param probe
421 * - the actual probe
422 * @throws ExecutionException
423 * If the command fails
424 */
425 public void enableProbe(String eventName, boolean isFunction, String probe)
426 throws ExecutionException {
427 enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
428 }
429
430 /**
431 * Enables a dynamic probe (for kernel domain)
432 *
433 * @param eventName
434 * - event name for probe
435 * @param isFunction
436 * - true for dynamic function entry/return probe else false
437 * @param probe
438 * - the actual probe
439 * @param monitor
440 * - a progress monitor
441 * @throws ExecutionException
442 * If the command fails
443 */
444 public void enableProbe(String eventName, boolean isFunction, String probe,
445 IProgressMonitor monitor) throws ExecutionException {
446 getControlService().enableProbe(getName(), null, eventName, isFunction,
447 probe, monitor);
448 }
449
450 /**
451 * Enables events using log level.
452 *
453 * @param eventName
454 * - a event name
455 * @param logLevelType
456 * - a log level type
457 * @param level
458 * - a log level
459 * @param filterExpression
460 * - a filter expression
461 * @throws ExecutionException
462 * If the command fails
463 */
464 public void enableLogLevel(String eventName, LogLevelType logLevelType,
465 TraceLogLevel level, String filterExpression) throws ExecutionException {
466 enableLogLevel(eventName, logLevelType, level, filterExpression,
467 new NullProgressMonitor());
468 }
469
470 /**
471 * Enables events using log level.
472 *
473 * @param eventName
474 * - a event name
475 * @param logLevelType
476 * - a log level type
477 * @param level
478 * - a log level
479 * @param filterExpression
480 * - a filter expression
481 * @param monitor
482 * - a progress monitor
483 * @throws ExecutionException
484 * If the command fails
485 */
486 public void enableLogLevel(String eventName, LogLevelType logLevelType,
487 TraceLogLevel level, String filterExpression, IProgressMonitor monitor)
488 throws ExecutionException {
489 getControlService().enableLogLevel(getName(), null, eventName,
490 logLevelType, level, null, monitor);
491 }
492
493 /**
494 * Gets all available contexts to be added to channels/events.
495 *
496 * @return the list of available contexts
497 * @throws ExecutionException
498 * If the command fails
499 */
500 public List<String> getContextList() throws ExecutionException {
501 return getContextList(new NullProgressMonitor());
502 }
503
504 /**
505 * Gets all available contexts to be added to channels/events.
506 *
507 * @param monitor
508 * The monitor that will indicate the progress
509 * @return the list of available contexts
510 * @throws ExecutionException
511 * If the command fails
512 */
513 public List<String> getContextList(IProgressMonitor monitor)
514 throws ExecutionException {
515 return getControlService().getContextList(monitor);
516 }
517 }
This page took 0.048255 seconds and 5 git commands to generate.