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