Improve package tangle index for LTTng 2.0 control design
[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 * <b><u>TraceSessionComponent</u></b>
35 * <p>
36 * Implementation of the trace session component.
37 * </p>
38 */
39 public class TraceSessionComponent extends TraceControlComponent {
40
41 // ------------------------------------------------------------------------
42 // Constants
43 // ------------------------------------------------------------------------
44 /**
45 * Path to icon file for this component (inactive state).
46 */
47 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
48 /**
49 * Path to icon file for this component (active state).
50 */
51 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
52 /**
53 * Path to icon file for this component (destroyed state).
54 */
55 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
56
57 // ------------------------------------------------------------------------
58 // Attributes
59 // ------------------------------------------------------------------------
60 /**
61 * The session information.
62 */
63 private ISessionInfo fSessionInfo = null;
64 /**
65 * A flag to indicate if session has been destroyed.
66 */
67 private boolean fIsDestroyed = false;
68 /**
69 * The image to be displayed in state active.
70 */
71 private Image fActiveImage = null;
72 /**
73 * The image to be displayed in state destroyed
74 */
75 private Image fDestroyedImage = null;
76
77 // ------------------------------------------------------------------------
78 // Constructors
79 // ------------------------------------------------------------------------
80 /**
81 * Constructor
82 * @param name - the name of the component.
83 * @param parent - the parent of this component.
84 */
85 public TraceSessionComponent(String name, ITraceControlComponent parent) {
86 super(name, parent);
87 setImage(TRACE_SESSION_ICON_FILE_INACTIVE);
88 setToolTip(Messages.TraceControl_SessionDisplayName);
89 fSessionInfo = new SessionInfo(name);
90 fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
91 fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
92 }
93
94 // ------------------------------------------------------------------------
95 // Accessors
96 // ------------------------------------------------------------------------
97 /*
98 * (non-Javadoc)
99 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
100 */
101 @Override
102 public Image getImage() {
103 if (fIsDestroyed) {
104 return fDestroyedImage;
105 }
106
107 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
108 return super.getImage();
109 }
110
111 return fActiveImage;
112 }
113
114 /**
115 * @return the whether the session is destroyed or not.
116 */
117 public boolean isDestroyed() {
118 return fIsDestroyed;
119 }
120
121 /**
122 * Sets the session destroyed state to the given value.
123 * @param destroyed - value to set.
124 */
125 public void setDestroyed(boolean destroyed) {
126 fIsDestroyed = destroyed;
127 }
128
129 /**
130 * @return the session state state (active or inactive).
131 */
132 public TraceSessionState getSessionState() {
133 return fSessionInfo.getSessionState();
134 }
135
136 /**
137 * Sets the session state to the given value.
138 * @param state - state to set.
139 */
140 public void setSessionState(TraceSessionState state) {
141 fSessionInfo.setSessionState(state);
142 }
143
144 /**
145 * Sets the event state to the value specified by the given name.
146 * @param stateName - state to set.
147 */
148 public void setSessionState(String stateName) {
149 fSessionInfo.setSessionState(stateName);
150 }
151
152 /**
153 * @return path string where session is located.
154 */
155 public String getSessionPath() {
156 return fSessionInfo.getSessionPath();
157 }
158
159 /**
160 * Sets the path string (where session is located) to the given value.
161 * @param path - session path to set.
162 */
163 public void setSessionPath(String sessionPath) {
164 fSessionInfo.setSessionPath(sessionPath);
165 }
166
167 /*
168 * (non-Javadoc)
169 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
170 */
171 @SuppressWarnings("rawtypes")
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 (TraceDomainComponent[])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 // Operations
197 // ------------------------------------------------------------------------
198 /**
199 * Retrieves the session configuration from the node.
200 * @throws ExecutionException
201 */
202 public void getConfigurationFromNode() throws ExecutionException {
203 getConfigurationFromNode(new NullProgressMonitor());
204 }
205
206 /**
207 * Retrieves the session configuration from the node.
208 * @param monitor - a progress monitor
209 * @throws ExecutionException
210 */
211 public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException {
212 removeAllChildren();
213 fSessionInfo = getControlService().getSession(getName(), monitor);
214 IDomainInfo[] domains = fSessionInfo.getDomains();
215 for (int i = 0; i < domains.length; i++) {
216 TraceDomainComponent domainComponent = new TraceDomainComponent(domains[i].getName(), this);
217 addChild(domainComponent);
218 domainComponent.setDomainInfo(domains[i]);
219 }
220 }
221
222 /**
223 * Starts the session.
224 * throws ExecutionExecption
225 */
226 public void startSession() throws ExecutionException {
227 startSession(new NullProgressMonitor());
228 }
229
230 /**
231 * Starts the session.
232 * @param monitor - a progress monitor
233 * throws ExecutionExecption
234 */
235 public void startSession(IProgressMonitor monitor) throws ExecutionException {
236 getControlService().startSession(getName(), monitor);
237 }
238
239 /**
240 * Starts the session.
241 * throws ExecutionExecption
242 */
243 public void stopSession() throws ExecutionException {
244 startSession(new NullProgressMonitor());
245 }
246
247 /**
248 * Starts the session.
249 * @param monitor - a progress monitor
250 * throws ExecutionExecption
251 */
252 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
253 getControlService().stopSession(getName(), monitor);
254 }
255
256 /**
257 * Enables channels with given names which are part of this domain. If a given channel
258 * doesn't exists it creates a new channel with the given parameters (or default values
259 * if given parameter is null).
260 * @param channelNames - a list of channel names to enable on this domain
261 * @param info - channel information to set for the channel (use null for default)
262 * @param isKernel - a flag for indicating kernel or UST.
263 * @throws ExecutionException
264 */
265 public void enableChannels(List<String> channelNames, IChannelInfo info, boolean isKernel) throws ExecutionException {
266 enableChannels(channelNames, info, isKernel, new NullProgressMonitor());
267 }
268
269 /**
270 * Enables channels with given names which are part of this domain. If a given channel
271 * doesn't exists it creates a new channel with the given parameters (or default values
272 * if given parameter is null).
273 * @param channelNames - a list of channel names to enable on this domain
274 * @param info - channel information to set for the channel (use null for default)
275 * @param isKernel - a flag for indicating kernel or UST.
276 * @param monitor - a progress monitor
277 * @throws ExecutionException
278 */
279 public void enableChannels(List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
280 getControlService().enableChannels(getName(), channelNames, isKernel, info, monitor);
281 }
282
283 /**
284 * Enables a list of events with no additional parameters.
285 * @param eventNames - a list of event names to enabled.
286 * @param isKernel - a flag for indicating kernel or UST.
287 * @throws ExecutionException
288 */
289 public void enableEvent(List<String> eventNames, boolean isKernel) throws ExecutionException {
290 enableEvents(eventNames, isKernel, new NullProgressMonitor());
291 }
292
293 /**
294 * Enables a list of events with no additional parameters.
295 * @param eventNames - a list of event names to enabled.
296 * @param isKernel - a flag for indicating kernel or UST.
297 * @param monitor - a progress monitor
298 * @throws ExecutionException
299 */
300 public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
301 getControlService().enableEvents(getName(), null, eventNames, isKernel, monitor);
302 }
303
304 /**
305 * Enables all syscalls (for kernel domain)
306 * @throws ExecutionException
307 */
308 public void enableSyscalls() throws ExecutionException {
309 enableSyscalls(new NullProgressMonitor());
310 }
311
312 /**
313 * Enables all syscalls (for kernel domain)
314 * @param monitor - a progress monitor
315 * @throws ExecutionException
316 */
317 public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
318 getControlService().enableSyscalls(getName(), null, monitor);
319 }
320
321 /**
322 * Enables a dynamic probe (for kernel domain)
323 * @param eventName - event name for probe
324 * @param isFunction - true for dynamic function entry/return probe else false
325 * @param probe - the actual probe
326 * @throws ExecutionException
327 */
328 public void enableProbe(String eventName, boolean isFunction, String probe) throws ExecutionException {
329 enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
330 }
331
332 /**
333 * Enables a dynamic probe (for kernel domain)
334 * @param eventName - event name for probe
335 * @param isFunction - true for dynamic function entry/return probe else false
336 * @param probe - the actual probe
337 * @param monitor - a progress monitor
338 * @throws ExecutionException
339 */
340 public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
341 getControlService().enableProbe(getName(), null, eventName, isFunction, probe, monitor);
342 }
343
344 /**
345 * Enables events using log level.
346 * @param eventName - a event name
347 * @param logLevelType - a log level type
348 * @param level - a log level
349 * @throws ExecutionException
350 */
351 public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level) throws ExecutionException {
352 enableLogLevel(eventName, logLevelType, level, new NullProgressMonitor());
353 }
354
355 /**
356 * Enables events using log level.
357 * @param eventName - a event name
358 * @param logLevelType - a log level type
359 * @param level - a log level
360 * @param monitor - a progress monitor
361 * @throws ExecutionException
362 */
363 public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
364 getControlService().enableLogLevel(getName(), null, eventName, logLevelType, level, monitor);
365 }
366
367 /**
368 * Gets all available contexts to be added to channels/events.
369 * @return the list of available contexts
370 */
371 public List<String> getContextList() throws ExecutionException {
372 return getContextList(new NullProgressMonitor());
373 }
374
375 /**
376 * Gets all available contexts to be added to channels/events.
377 * @param monitor
378 * @return the list of available contexts
379 */
380 public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
381 return getControlService().getContextList(monitor);
382 }
383 }
This page took 0.040071 seconds and 6 git commands to generate.