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