Add support for filter feature of LTTng Tools 2.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 * (non-Javadoc)
170 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
171 */
172 @Override
173 public Object getAdapter(Class adapter) {
174 if (adapter == IPropertySource.class) {
175 return new TraceSessionPropertySource(this);
176 }
177 return null;
178 }
179
180 /**
181 * @return all available domains of this session.
182 */
183 public TraceDomainComponent[] getDomains() {
184 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
185 return sessions.toArray(new TraceDomainComponent[sessions.size()]);
186 }
187
188 /**
189 * @return the parent target node
190 */
191 public TargetNodeComponent getTargetNode() {
192 return ((TraceSessionGroup)getParent()).getTargetNode();
193 }
194
195 /**
196 * Returns whether the kernel provider is available or not
197 * @return <code>true</code> if kernel provide is available or <code>false</code>
198 */
199 public boolean hasKernelProvider() {
200 List<ITraceControlComponent> providerGroups = getTargetNode().getChildren(TraceProviderGroup.class);
201 return (!providerGroups.isEmpty() ? ((TraceProviderGroup) providerGroups.get(0)).hasKernelProvider() : false);
202 }
203
204 /**
205 * Returns if node supports filtering of events
206 * @return <code>true</code> if node supports filtering else <code>false</code>
207 */
208 public boolean isEventFilteringSupported() {
209 return ((TargetNodeComponent)getParent().getParent()).isEventFilteringSupported();
210 }
211
212 // ------------------------------------------------------------------------
213 // Operations
214 // ------------------------------------------------------------------------
215
216 /**
217 * Retrieves the session configuration from the node.
218 *
219 * @throws ExecutionException
220 * If the command fails
221 */
222 public void getConfigurationFromNode() throws ExecutionException {
223 getConfigurationFromNode(new NullProgressMonitor());
224 }
225
226 /**
227 * Retrieves the session configuration from the node.
228 *
229 * @param monitor
230 * - a progress monitor
231 * @throws ExecutionException
232 * If the command fails
233 */
234 public void getConfigurationFromNode(IProgressMonitor monitor)
235 throws ExecutionException {
236 removeAllChildren();
237 fSessionInfo = getControlService().getSession(getName(), monitor);
238 IDomainInfo[] domains = fSessionInfo.getDomains();
239 for (int i = 0; i < domains.length; i++) {
240 TraceDomainComponent domainComponent = new TraceDomainComponent(
241 domains[i].getName(), this);
242 addChild(domainComponent);
243 domainComponent.setDomainInfo(domains[i]);
244 }
245 }
246
247 /**
248 * Starts the session.
249 *
250 * @throws ExecutionException
251 * If the command fails
252 */
253 public void startSession() throws ExecutionException {
254 startSession(new NullProgressMonitor());
255 }
256
257 /**
258 * Starts the session.
259 *
260 * @param monitor
261 * - a progress monitor
262 * @throws ExecutionException
263 * If the command fails
264 */
265 public void startSession(IProgressMonitor monitor)
266 throws ExecutionException {
267 getControlService().startSession(getName(), monitor);
268 }
269
270 /**
271 * Starts the session.
272 *
273 * @throws ExecutionException
274 * If the command fails
275 */
276 public void stopSession() throws ExecutionException {
277 startSession(new NullProgressMonitor());
278 }
279
280 /**
281 * Starts the session.
282 *
283 * @param monitor
284 * - a progress monitor
285 * @throws ExecutionException
286 * If the command fails
287 */
288 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
289 getControlService().stopSession(getName(), monitor);
290 }
291
292 /**
293 * Enables channels with given names which are part of this domain. If a
294 * given channel doesn't exists it creates a new channel with the given
295 * parameters (or default values if given parameter is null).
296 *
297 * @param channelNames
298 * - a list of channel names to enable on this domain
299 * @param info
300 * - channel information to set for the channel (use null for
301 * default)
302 * @param isKernel
303 * - a flag for indicating kernel or UST.
304 * @throws ExecutionException
305 * If the command fails
306 */
307 public void enableChannels(List<String> channelNames, IChannelInfo info,
308 boolean isKernel) throws ExecutionException {
309 enableChannels(channelNames, info, isKernel, new NullProgressMonitor());
310 }
311
312 /**
313 * Enables channels with given names which are part of this domain. If a
314 * given channel doesn't exists it creates a new channel with the given
315 * parameters (or default values if given parameter is null).
316 *
317 * @param channelNames
318 * - a list of channel names to enable on this domain
319 * @param info
320 * - channel information to set for the channel (use null for
321 * default)
322 * @param isKernel
323 * - a flag for indicating kernel or UST.
324 * @param monitor
325 * - a progress monitor
326 * @throws ExecutionException
327 * If the command fails
328 */
329 public void enableChannels(List<String> channelNames, IChannelInfo info,
330 boolean isKernel, IProgressMonitor monitor)
331 throws ExecutionException {
332 getControlService().enableChannels(getName(), channelNames, isKernel,
333 info, monitor);
334 }
335
336 /**
337 * Enables a list of events with no additional parameters.
338 *
339 * @param eventNames
340 * - a list of event names to enabled.
341 * @param isKernel
342 * - a flag for indicating kernel or UST.
343 * @param filterExpression
344 * - a filter expression
345 * @throws ExecutionException
346 * If the command fails
347 */
348 public void enableEvent(List<String> eventNames, boolean isKernel, String filterExpression)
349 throws ExecutionException {
350 enableEvents(eventNames, isKernel, filterExpression, new NullProgressMonitor());
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 * @param monitor
363 * - a progress monitor
364 * @throws ExecutionException
365 * If the command fails
366 */
367 public void enableEvents(List<String> eventNames, boolean isKernel,
368 String filterExpression, IProgressMonitor monitor) throws ExecutionException {
369 getControlService().enableEvents(getName(), null, eventNames, isKernel,
370 filterExpression, monitor);
371 }
372
373 /**
374 * Enables all syscalls (for kernel domain)
375 *
376 * @throws ExecutionException
377 * If the command fails
378 */
379 public void enableSyscalls() throws ExecutionException {
380 enableSyscalls(new NullProgressMonitor());
381 }
382
383 /**
384 * Enables all syscalls (for kernel domain)
385 *
386 * @param monitor
387 * - a progress monitor
388 * @throws ExecutionException
389 * If the command fails
390 */
391 public void enableSyscalls(IProgressMonitor monitor)
392 throws ExecutionException {
393 getControlService().enableSyscalls(getName(), null, monitor);
394 }
395
396 /**
397 * Enables a dynamic probe (for kernel domain)
398 *
399 * @param eventName
400 * - event name for probe
401 * @param isFunction
402 * - true for dynamic function entry/return probe else false
403 * @param probe
404 * - the actual probe
405 * @throws ExecutionException
406 * If the command fails
407 */
408 public void enableProbe(String eventName, boolean isFunction, String probe)
409 throws ExecutionException {
410 enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
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 * @param monitor
423 * - a progress monitor
424 * @throws ExecutionException
425 * If the command fails
426 */
427 public void enableProbe(String eventName, boolean isFunction, String probe,
428 IProgressMonitor monitor) throws ExecutionException {
429 getControlService().enableProbe(getName(), null, eventName, isFunction,
430 probe, monitor);
431 }
432
433 /**
434 * Enables events using log level.
435 *
436 * @param eventName
437 * - a event name
438 * @param logLevelType
439 * - a log level type
440 * @param level
441 * - a log level
442 * @param filterExpression
443 * - a filter expression
444 * @throws ExecutionException
445 * If the command fails
446 */
447 public void enableLogLevel(String eventName, LogLevelType logLevelType,
448 TraceLogLevel level, String filterExpression) throws ExecutionException {
449 enableLogLevel(eventName, logLevelType, level, filterExpression,
450 new NullProgressMonitor());
451 }
452
453 /**
454 * Enables events using log level.
455 *
456 * @param eventName
457 * - a event name
458 * @param logLevelType
459 * - a log level type
460 * @param level
461 * - a log level
462 * @param filterExpression
463 * - a filter expression
464 * @param monitor
465 * - a progress monitor
466 * @throws ExecutionException
467 * If the command fails
468 */
469 public void enableLogLevel(String eventName, LogLevelType logLevelType,
470 TraceLogLevel level, String filterExpression, IProgressMonitor monitor)
471 throws ExecutionException {
472 getControlService().enableLogLevel(getName(), null, eventName,
473 logLevelType, level, null, monitor);
474 }
475
476 /**
477 * Gets all available contexts to be added to channels/events.
478 *
479 * @return the list of available contexts
480 * @throws ExecutionException
481 * If the command fails
482 */
483 public List<String> getContextList() throws ExecutionException {
484 return getContextList(new NullProgressMonitor());
485 }
486
487 /**
488 * Gets all available contexts to be added to channels/events.
489 *
490 * @param monitor
491 * The monitor that will indicate the progress
492 * @return the list of available contexts
493 * @throws ExecutionException
494 * If the command fails
495 */
496 public List<String> getContextList(IProgressMonitor monitor)
497 throws ExecutionException {
498 return getControlService().getContextList(monitor);
499 }
500 }
This page took 0.043162 seconds and 5 git commands to generate.