Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / model / impl / TraceSessionComponent.java
CommitLineData
eb1bab5b
BH
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 **********************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.control.model.impl;
13
6503ae0f
BH
14import java.util.List;
15
eb1bab5b
BH
16import org.eclipse.core.commands.ExecutionException;
17import org.eclipse.core.runtime.IProgressMonitor;
18import org.eclipse.core.runtime.NullProgressMonitor;
19import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
20import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
21import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo;
22import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo;
23import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent;
24import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
06b9339e 25import org.eclipse.linuxtools.lttng.ui.views.control.property.TraceSessionPropertySource;
eb1bab5b 26import org.eclipse.swt.graphics.Image;
06b9339e 27import org.eclipse.ui.views.properties.IPropertySource;
eb1bab5b
BH
28
29/**
30 * <b><u>TraceSessionComponent</u></b>
31 * <p>
32 * Implementation of the trace session component.
33 * </p>
34 */
35public class TraceSessionComponent extends TraceControlComponent {
36
37 // ------------------------------------------------------------------------
38 // Constants
39 // ------------------------------------------------------------------------
40 /**
41 * Path to icon file for this component (inactive state).
42 */
43 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
44 /**
45 * Path to icon file for this component (active state).
46 */
47 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
48 /**
49 * Path to icon file for this component (destroyed state).
50 */
51 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
52
53 // ------------------------------------------------------------------------
54 // Attributes
55 // ------------------------------------------------------------------------
56 /**
57 * The session information.
58 */
59 private ISessionInfo fSessionInfo = null;
60 /**
61 * A flag to indicate if session has been destroyed.
62 */
63 private boolean fIsDestroyed = false;
64 /**
65 * The image to be displayed in state active.
66 */
67 private Image fActiveImage = null;
68 /**
69 * The image to be displayed in state destroyed
70 */
71 private Image fDestroyedImage = null;
72
73 // ------------------------------------------------------------------------
74 // Constructors
75 // ------------------------------------------------------------------------
76 /**
77 * Constructor
78 * @param name - the name of the component.
79 * @param parent - the parent of this component.
80 */
81 public TraceSessionComponent(String name, ITraceControlComponent parent) {
82 super(name, parent);
83 setImage(TRACE_SESSION_ICON_FILE_INACTIVE);
84 setToolTip(Messages.TraceControl_SessionDisplayName);
85 fSessionInfo = new SessionInfo(name);
86 fActiveImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
87 fDestroyedImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
88 }
89
90 // ------------------------------------------------------------------------
91 // Accessors
92 // ------------------------------------------------------------------------
93 /*
94 * (non-Javadoc)
95 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
96 */
97 @Override
98 public Image getImage() {
99 if (fIsDestroyed) {
100 return fDestroyedImage;
101 }
102
103 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
104 return super.getImage();
105 }
106
107 return fActiveImage;
108 }
109
eb1bab5b
BH
110 /**
111 * @return the whether the session is destroyed or not.
112 */
113 public boolean isDestroyed() {
114 return fIsDestroyed;
115 }
bbb3538a 116
eb1bab5b
BH
117 /**
118 * Sets the session destroyed state to the given value.
119 * @param destroyed - value to set.
120 */
121 public void setDestroyed(boolean destroyed) {
122 fIsDestroyed = destroyed;
123 }
bbb3538a 124
eb1bab5b
BH
125 /**
126 * @return the session state state (active or inactive).
127 */
128 public TraceSessionState getSessionState() {
129 return fSessionInfo.getSessionState();
130 }
131
132 /**
133 * Sets the session state to the given value.
134 * @param state - state to set.
135 */
136 public void setSessionState(TraceSessionState state) {
137 fSessionInfo.setSessionState(state);
138 }
bbb3538a 139
eb1bab5b
BH
140 /**
141 * Sets the event state to the value specified by the given name.
142 * @param stateName - state to set.
143 */
144 public void setSessionState(String stateName) {
145 fSessionInfo.setSessionState(stateName);
146 }
147
148 /**
149 * @return path string where session is located.
150 */
151 public String getSessionPath() {
152 return fSessionInfo.getSessionPath();
153 }
154
155 /**
156 * Sets the path string (where session is located) to the given value.
157 * @param path - session path to set.
158 */
159 public void setSessionPath(String sessionPath) {
160 fSessionInfo.setSessionPath(sessionPath);
161 }
162
06b9339e
BH
163 /*
164 * (non-Javadoc)
165 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
166 */
167 @SuppressWarnings("rawtypes")
168 @Override
169 public Object getAdapter(Class adapter) {
170 if (adapter == IPropertySource.class) {
171 return new TraceSessionPropertySource(this);
172 }
173 return null;
174 }
bbb3538a 175
6503ae0f
BH
176 /**
177 * @return all available domains of this session.
178 */
179 public TraceDomainComponent[] getDomains() {
180 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
181 return (TraceDomainComponent[])sessions.toArray(new TraceDomainComponent[sessions.size()]);
182 }
183
498704b3
BH
184 /**
185 * @return the parent target node
186 */
187 public TargetNodeComponent getTargetNode() {
188 return ((TraceSessionGroup)getParent()).getTargetNode();
189 }
190
eb1bab5b
BH
191 // ------------------------------------------------------------------------
192 // Operations
193 // ------------------------------------------------------------------------
194 /**
195 * Retrieves the session configuration from the node.
196 * @throws ExecutionException
197 */
198 public void getConfigurationFromNode() throws ExecutionException {
199 getConfigurationFromNode(new NullProgressMonitor());
200 }
201
202 /**
203 * Retrieves the session configuration from the node.
204 * @param monitor - a progress monitor
205 * @throws ExecutionException
206 */
207 public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException {
bbb3538a 208 removeAllChildren();
eb1bab5b
BH
209 fSessionInfo = getControlService().getSession(getName(), monitor);
210 IDomainInfo[] domains = fSessionInfo.getDomains();
211 for (int i = 0; i < domains.length; i++) {
bbb3538a
BH
212 TraceDomainComponent domainComponent = new TraceDomainComponent(domains[i].getName(), this);
213 addChild(domainComponent);
214 domainComponent.setDomainInfo(domains[i]);
eb1bab5b
BH
215 }
216 }
bbb3538a
BH
217
218 /**
219 * Starts the session.
220 * throws ExecutionExecption
221 */
222 public void startSession() throws ExecutionException {
223 startSession(new NullProgressMonitor());
224 }
225
226 /**
227 * Starts the session.
228 * @param monitor - a progress monitor
229 * throws ExecutionExecption
230 */
231 public void startSession(IProgressMonitor monitor) throws ExecutionException {
232 getControlService().startSession(getName(), monitor);
233 }
234
235 /**
236 * Starts the session.
237 * throws ExecutionExecption
238 */
239 public void stopSession() throws ExecutionException {
240 startSession(new NullProgressMonitor());
241 }
242
243 /**
244 * Starts the session.
245 * @param monitor - a progress monitor
246 * throws ExecutionExecption
247 */
248 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
249 getControlService().stopSession(getName(), monitor);
250 }
251
6503ae0f
BH
252 /**
253 * Enables a list of events with no additional parameters.
254 * @param eventNames - a list of event names to enabled.
255 * @param isKernel - a flag for indicating kernel or UST.
256 * @throws ExecutionException
257 */
258 public void enableEvent(List<String> eventNames, boolean isKernel) throws ExecutionException {
498704b3 259 enableEvents(eventNames, isKernel, new NullProgressMonitor());
6503ae0f
BH
260 }
261
262 /**
263 * Enables a list of events with no additional parameters.
264 * @param eventNames - a list of event names to enabled.
265 * @param isKernel - a flag for indicating kernel or UST.
266 * @param monitor - a progress monitor
267 * @throws ExecutionException
268 */
498704b3
BH
269 public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
270 getControlService().enableEvents(getName(), null, eventNames, isKernel, monitor);
271 }
272
273 /**
274 * Enables all syscalls (for kernel domain)
275 * @throws ExecutionException
276 */
277 public void enableSyscalls() throws ExecutionException {
278 enableSyscalls(new NullProgressMonitor());
279 }
280
281 /**
282 * Enables all syscalls (for kernel domain)
283 * @param monitor - a progress monitor
284 * @throws ExecutionException
285 */
286 public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
287 getControlService().enableSyscalls(getName(), null, monitor);
288 }
289
290 /**
291 * Enables a dynamic probe (for kernel domain)
292 * @param eventName - event name for probe
293 * @param probe - the actual probe
294 * @throws ExecutionException
295 */
296 public void enableProbe(String eventName, String probe) throws ExecutionException {
297 enableProbe(eventName, probe, new NullProgressMonitor());
298 }
299
300 /**
301 * Enables a dynamic probe (for kernel domain)
302 * @param eventName - event name for probe
303 * @param probe - the actual probe
304 * @param monitor - a progress monitor
305 * @throws ExecutionException
306 */
307 public void enableProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException {
308 getControlService().enableProbe(getName(), null, eventName, probe, monitor);
309 }
310
311 /**
312 * Enables a dynamic function entry/return probe (for kernel domain)
313 * @param eventName - event name for probe
314 * @param probe - the actual probe
315 * @throws ExecutionException
316 */
317 public void enableFunctionProbe(String eventName, String probe) throws ExecutionException {
318 enableFunctionProbe(eventName, probe, new NullProgressMonitor());
319 }
320
321 /**
322 * Enables a dynamic function entry/return probe (for kernel domain)
323 * @param eventName - event name for probe
324 * @param probe - the actual probe
325 * @param monitor - a progress monitor
326 * @throws ExecutionException
327 */
328 public void enableFunctionProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException {
329 getControlService().enableFunctionProbe(getName(), null, eventName, probe, monitor);
6503ae0f 330 }
eb1bab5b 331}
This page took 0.037956 seconds and 5 git commands to generate.